// JavaScript Document
var FadeImageCounter = 2;
function FadeImages (){
	var maxImages = $('#HiddenImages img').size();
	var newBackground;
	
	if (FadeImageCounter >= maxImages){
		FadeImageCounter = 0;
	}
	newBackground = $('#HiddenImages img').eq(FadeImageCounter).attr('src');
	if (FadeImageCounter%2 == 0) {		 
		$('#BraniffRotator > div').eq(0).fadeOut(3000, function() {
			$(this).css('background-image','url("' + newBackground + '")');
		});
		FadeImageCounter++
	}
	else {
		$('#BraniffRotator > div').eq(0).fadeIn(3000, function() {
			$('#BraniffRotator > div').eq(1).css('background-image','url("' + newBackground + '")');
		});
		FadeImageCounter++
	}
	
}

function BraniffRotation() {
	
	
	//$('#BraniffRotator > div').eq(0).fadeOut(3000, FadeImages(2,maxImages));
	setInterval("FadeImages()", 9000);
}

$(function(){
	//Load images into divs
	if ($('#HiddenImages img').size() > 1) {
		$('#BraniffRotator > div').each(function() {
			var newBg = $('#HiddenImages img').eq($('#BraniffRotator div').index(this)).attr('src');
			$(this).css('background-image','url("' + newBg + '")');
		});
		
		//startRotator
		BraniffRotation();
	}
	else if ($('#HiddenImages img').size() == 1) {
		var newBg = $('#HiddenImages img').eq(0).attr('src');
		$('#BraniffRotator > div').css('background-image','url(' + newBg + ')');
	}
	else {
		$('#BraniffRotator > div').css('background-image','url('+ resourcesRoot + 'HomeImage.jpg)');
	}
	
	//The navigation bar is stupid because the guy who designed it didn't make consisent widths
	$('#nav #NavigationCustom > ul > li').css({'width': '117px', 'padding':'0px 2px'});
	$('#nav #NavigationCustom > ul > li:first-child').css({'width': '121px'});
	$('#nav #NavigationCustom > ul > li:last-child').css({'width': '120px'});
	
	$('#nav #NavigationCustom > ul > li a').filter(function () {
		return $(this).height() > 32;
		}).css({lineHeight:'12px', paddingTop:'3px'});
		
	//hurrr cellpadding
	$('table').attr('cellpadding','0');

});
