// JavaScript Document

$(document).ready(function(){
	// Common functions
	clearClick();
	setBrowserClass();
	cssTweaks();
	
	resizeBG();
	window.onresize = resizeBG;
	
	// Show non-flash content
	if(!hasFlash){
		$('.no_flash').show();
		initDropdownNavs();
	}else{
		initDropdownNavs(); // remove after testing
	}
	
	// PNG support for IE6
	if(isIE(6)){
		$(document).pngFix();
	}
});


function cssTweaks(){
	$('blockquote').each(function(i,elem){ $(elem).find('p:last').css('margin',0); });
	$('ol li').wrapInner('<span></span>');
}

function resizeBG(){
	var size = getScreenSize();
	$('#scalable_bg_inner').css('width',size[0]+'px');
}

function initDropdownNavs(){
	$('#home_nav>li, #nav>li').hover(
		function(){ $(this).find('ul').fadeIn(); },
		function(){ $(this).find('ul').fadeOut(); }
	);
	$('#home_nav ul a:last').css('border-bottom','none');
	$('#nav ul a:last').css('border-bottom','none');
	$('#nav_categories').hover (
		function(){ $('#catNav').fadeIn(); },
		function(){ $('#catNav').fadeOut(); }
		)
	$('#navVid ul a:last').css('border-bottom','none');
						   
}


/*-----------------------------------------------------*/
/*	Gallery Header Template
/*-----------------------------------------------------*/
function goToSlide(num){
	$('#gallery_main').cycle('pause');
	var html = '';
	var count = 0;
	var stopLoop = false;
	$('#gallery_slider .slide').each(function(i,elem){
		if(!stopLoop){
			var id = $(elem).attr('id').replace('slide','');
			if(id == num){
				stopLoop = true; // stop, we're at the current image
			}else{
				count++;
				var className = $(elem).attr('class');
				html += '<div id="slide'+id+'" class="'+className+'">';
				html += $(elem).html();
				html += '</div>';
				$(elem).addClass('removeMe');
			}
		}
	});
	if(html != ''){
		var newTop = -130 * count;
		$('#gallery_slider').append(html);
		$('#gallery_slider').animate({top:newTop},750,'',
			function(){
				$('#gallery_slider .removeMe').remove();
				$('#gallery_slider').css('top',0);
				skipSlide = true;
				$('#gallery_main').cycle(num);
				$('#gallery_main').cycle('resume');
			}
		);
	}
}

var skipSlide = true;
function slideGallery(next){
	if(!skipSlide && $('#gallery_slider .slide').length > 2){
		var top = $('#gallery_slider .slide:first');
		var id = $(top).attr('id');
		var className = $(top).attr('class');
		var html = '<div id="'+id+'" class="'+className+'">';
		html += $(top).html();
		html += '</div>';
		$('#gallery_slider').append(html);
		$('#gallery_slider').animate({top:-130},750,'',
			function(){
				$(top).remove();
				$('#gallery_slider').css('top',0);
			}
		);
	}
	skipSlide = false;
}


function showDropDown( h ) {
	$('#flash_header').height(h);
}

function hideDropDown( h ) {
	$('#flash_header').height(h);
}






