// JavaScript Document

var height = 0;

$(document).ready(function(){
	// Common functions
	clearClick();
	setBrowserClass();
	cssTweaks();
	hideFooter();
	adjustFooter();
	
	// Show non-flash content
	if(!hasFlash){
		$('.no_flash').show();
		$('.has_flash').remove();
		$('#sidebar').css('marginTop','-37px');
	}else{
		$('.no_flash').remove();
	}
	
	// PNG support for IE6
	if(isIE(6)){
		//$(document).pngFix();
	}
	
	$('#footer_expand-btn a').click(function() {
		footerExpand();
		return false;
	});
	
});

$(window).resize(function() {
	adjustFooter();	
});

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

function hideFooter() {
	height = $('#footer').height();
	
	// hide everything
	
	$('#footer_nav').hide();
	$('#footer_events').hide();	
	$('#footer_copyright').hide();
	$('#footer .spacer').hide();
	
	//remove .open class
	
	$('#footer_expand-btn a').removeClass('open');	
}

function adjustFooter() {
	if($('#footer_wrapper').hasClass('home_footer')) {
		if(hasFlash) {
			$('#footer_wrapper').animate({ 'top': 834 },1);
		}
		else {
			$('#footer_wrapper').removeClass('home_footer');
			adjustFooter();	
		}
	}
	else {
		var screen_size = getScreenSize();
		var screen_height = screen_size[1];
		var doc_height = $(document).height();
		$('#docheight').val(doc_height);
		$('#screenheight').val(screen_height);
			if(screen_height >= doc_height) {
				var foffset = $('#footer').offset();
				var top = foffset.top;
				var fheight = $('#footer').height()+24+46;
				var move = screen_height - fheight;
				$('#footer_wrapper').animate({ 'top': move },1);
		}
	}
}

function footerExpand () {
	if($('#footer_copyright').is(':visible')) {
		$('#footer_nav').fadeOut('fast');
		$('#footer_address').fadeOut('fast');
		$('#footer_events').fadeOut('fast');
		$('#footer_copyright').fadeOut('fast');
		$('#footer .spacer').fadeOut('fast');
		$('#footer_expand-btn a').removeClass('open');	
		$('#footer').animate({'height': ''}, 500, function() {$('#footer_address').fadeIn('fast');});
	}
	else {
		$('#footer').animate({'height': height}, 1, function() {
			$('#footer_nav').fadeIn('fast');
			$('#footer_events').fadeIn('fast');
			$('#footer_copyright').fadeIn('fast');
			$('#footer .spacer').fadeIn('fast');
			$('#footer_expand-btn a').addClass('open');		
			$.scrollTo('#footer', {duration:1000});
		});
	}
}
