// HOME PAGE CONDITIONS BANNER

var imgTimer;
var imgBottom;
var imgTop;
var imageNumber=0;
var bannerImage=["url(/multimedia/img/nonFlashBanners/1106-conditions/bg-01.jpg)","url(/multimedia/img/nonFlashBanners/1106-conditions/bg-02.jpg)","url(/multimedia/img/nonFlashBanners/1106-conditions/bg-03.jpg)"];
var openSection=0;
var buttonVerticalPosition=[0,"-35px","-70px","-105px","-140px","-175px"];

$(document).ready(function($) {
	fadebg();
	$('#bannerlink1').click(function(){expandLink(1);});
	$('#bannerlink2').click(function(){expandLink(2);});
	$('#bannerlink3').click(function(){expandLink(3);});
	$('#bannerlink4').click(function(){expandLink(4);});
	$('#bannerlink5').click(function(){expandLink(5);});
	$('#bannerlink6').click(function(){expandLink(6);});
});

// CONTINOUSLY FADE THE BACKGROUND BETWEEN 2 IMAGES
	function fadedelay() {
		imgTimer=setTimeout("fadebg()",5000);
	}
	
	function fadebg() {
		// Define which banner is at the top and which at the bottom for this round
		if (imageNumber < bannerImage.length-1) {
			imgTop = bannerImage[imageNumber];
			imgBottom = bannerImage[imageNumber+1];
			imageNumber++;
		} else {
			imgTop = bannerImage[imageNumber];
			imgBottom = bannerImage[0];
			imageNumber = 0;
		}
		// Place the top banner into the container
		$('#banner-top').css('background-image', imgTop);
		// Set the top banner opacity to 100%
		$("#banner-top").css({ opacity: 1 });
		// Place bottom banner into the container
		$('#banner-bottom').css('background-image', imgBottom);
		// Start the fade timer (wait for the bg image to fully load).
		imgTimer=setTimeout("fadeImage()",5000);
	}
	
	function fadeImage() {
		$('#banner-top').fadeTo('slow', 0, function() {
			// onComplete reload fadebg function
			fadebg();
		});
	}

// BANNER LINKS
	function expandLink(theSection) {
		if (openSection == 0) {
			$('#bannerlink'+theSection).css('background-position','-209px ' + buttonVerticalPosition[theSection-1]);
			$('#expand'+theSection).slideToggle('fast');
			openSection = theSection;
		} else if (openSection == theSection) {
			$('#bannerlink'+openSection).css('background-position','0 ' + buttonVerticalPosition[openSection-1]);
			$('#expand'+openSection).slideToggle('fast');
			openSection = 0;
		} else {
			$('#bannerlink'+theSection).css('background-position','-209px ' + buttonVerticalPosition[theSection-1]);
			$('#expand'+theSection).slideToggle('fast');
			$('#bannerlink'+openSection).css('background-position','0 ' + buttonVerticalPosition[openSection-1]);
			$('#expand'+openSection).slideToggle('fast');
			openSection = theSection;
		}
	}



