// 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();
	}
		
	$('#sideNav .active a:first').css({'color':'#FFFFFF', 'background': '#8f8b8b'});
	
});


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

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

function initDropdownNavs(){
	$('#nav>li').hover(
		function(){ $(this).find('a:first').css('background', '#666666').css('color', '#FFFFFF'); $(this).find('ul').stop(true, true).fadeIn( 150 ); },
		function(){ $(this).find('a:first').css('background', 'none').css('color', '#666666'); $(this).find('ul').stop(true, true).fadeOut( 150 ); Cufon.refresh(); }
	);
					   
}
function campusDropDown(){
	if($('#campusSelectorList').is(':visible')){
		$('#campusSelectorList').fadeOut();
	}
	else {
		$('#campusSelectorList').fadeIn();	
	}
}

//call from flash // mag
function showDivContent(div_id){
	$('#' + div_id).slideToggle();
}
function showDropDown(h) {
	$('#flash_wrapper').height(h);
}

function hideDropDown(h) {
	$('#flash_wrapper').height(h);
}
// ==============================

/*-----------------------------------------------------*/
/*	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;
}

