<!--
// ==============================
// SET VARIABLES
// ==============================


// ==============================
// RUN ALL ONLOAD JQUERY COMMANDS
// ==============================
$(document).ready(function() {
	// ==============================
	// Pulldonw menus for IE
	// ==============================
	if (jQuery.browser.msie && (jQuery.browser.version == '7.0' || jQuery.browser.version == '6.0')) {                     
        // The isIE variable is set in the page.tpl.php file
        $('#nav ul li').mouseover(function() {
            $(this).children('ul').css({left:'auto'});
        });
        
		$('#nav ul li').mouseout(function() {
            $(this).children('ul').css({left:'-999em'});
        });
	}


    // Run nav code if this is IE6
	/*if (jQuery.browser.msie && jQuery.browser.version == '6.0') {              
        // The isIE variable is set in the page.tpl.php file
        $('#nav ul li').mouseover(function() {
            $(this).children('ul').css({left:'auto'});
        });
        
		$('#nav ul li').mouseout(function() {
            $(this).children('ul').css({left:'-999em'});
        });
	}*/
	
	// ==============================
	// SUBNAV TITLE
	// ==============================
	var subNavTitle = $('div#subnav>ul>li.treeOn>a').text();
	$('h2#subNavTitle').text(subNavTitle);
	
	// ==============================
	// FONT SIZE BUTTONS
	// ==============================
	$('#plus').mousedown(function() {
		var currentFontSize = parseInt($('body').css('font-size'));
		var newFontSize = currentFontSize + 1;
		if (newFontSize <= 14) {
			$('body').css('font-size',newFontSize);
		}
	});
	$('#minus').mousedown(function() {
		var currentFontSize = parseInt($('body').css('font-size'));
		var newFontSize = currentFontSize - 1;
		if (newFontSize >= 11) {
			$('body').css('font-size',newFontSize);
		}
	});
	
	
	
	// ==============================
	// COMPONENT BOXES
	// ==============================
	// The following three component boxes have their containers turned off in screen.css
	// They're then turned on here after all their additional processing is complete.
	// This keeps these random load components from briefly showing all their content.
	// TESTIMONIALS
	var totalParasTestimonials = $('div#testimonials p').size();
	var testimonialToDisplay = randomRange(1,totalParasTestimonials) - 1;
	//alert(paraToDisplay);
	$('div#testimonials p').css('display','none');
	$('div#testimonials p:eq(' + testimonialToDisplay + ')').css('display','block').addClass('quote');
	// Turn the container on
	$('div#testimonials .componentContent').css('display','block');
	
	
	
	// STORIES
	var totalParasStories = $('div#stories p').size();
	var storyToDisplay = randomRange(1,totalParasStories) - 1;
	$('div#stories p').css('display','none');
	$('div#stories p:eq(' + storyToDisplay + ')').each(function() {
		$(this).css('display','block');
		$(this).find('img').addClass('moveright padding1FloatRight');
		
		// REDUCE WIDTH IF TOO LARGE.
		// Get the width of the image
		var storyImageWidth = $(this).find('img').width();
		// If it's too large, process it down.
		if (storyImageWidth > 115) {
			// Calculate it's new height
			var storyImageHeight = $(this).prev().height();
			var storyImageHeightNew = (storyImageHeight * 115)/storyImageWidth;
			// Set it's new width and height
			var storyImageWidth = $(this).find('img').attr('width','115');
			var storyImageWidth = $(this).find('img').attr('height',storyImageHeightNew);
		}
	});
	// Turn the container on
	$('div#stories .componentContent').css('display','block');
	
	
	// FAQ, (Did You Know?)
	var totalParasFAQ = $('div#faq p').size();
	var faqToDisplay = randomRange(1,totalParasFAQ) - 1;
	//alert(paraToDisplay);
	$('div#faq p').css('display','none');
	$('div#faq p:eq(' + faqToDisplay + ')').css('display','block');
	// Turn the container on
	$('div#faq .componentContent').css('display','block');
	
	
	
	// SPONSORS
	//$('div.componentContent div.logos img').each(function() {
	//	$(this).css('display','none');
	//});
	$('div.componentContent div.logos').css('display','block');
	// Staight fade
	$('div.componentContent div.logos').cycle({
		fx: 'fade',  
		speed: 1000, 
		pause: 10 
	});
	/* Zoom fade
	$('div.componentContent div.logos').cycle({
		fx: 'custom', 
			cssBefore: {  
			left: 97,  
			top:  55,  
			width: 0,  
			height: 0,  
			opacity: 1, 
			zIndex: 1 
		}, 
		animOut: {  
        	opacity: 0  
		}, 
		animIn: {  
			left: 0,  
			top: 0,  
			width: 194,  
			height: 110  
		}, 
		cssAfter: {  
			zIndex: 0 
		}, 
		delay: -3000 
	});*/
	/*	The block that follows was a scatch slideshow solution.
		It was replaced by the cycle plugin code above.
		If this is re-implemented, you need to include the jquery timer plugin. */
	// Set some variables and turn off all items
	/*var totalSponsorLogos = $('div#sponsors .logos img').size();
	var currentSponsorLogo = 0;
	// Turn off all logos
	$('div#sponsors .logos img').hide();
	// Turn the first logo on
	$('div#sponsors .logos img:eq(0)').show();	
	// Now run the slideshow in a continous loop
	$('div#sponsors .logos').everyTime(4000,function(i) {
		// Last image, prepare to loop back
		if (currentSponsorLogo >= totalSponsorLogos - 1) {
			var nextSponsorLogo = 0;
		} else {
			var nextSponsorLogo = currentSponsorLogo + 1;
		}
		// Perform the exchange of images
		$(this).find('img:eq(' + currentSponsorLogo + ')').fadeOut(400, function() {
			$(this).parent().find('img:eq(' + nextSponsorLogo + ')').fadeIn(400,function() {
				// If we just went to the first image, set the loop counter back to the beginning.
				if (nextSponsorLogo == 0) {
					currentSponsorLogo = 0;
				} else {
					currentSponsorLogo++;
				}
			});
		});
	});*/
	
	
	// ==============================
	// PAGE SPECIFIC EFFECTS
	// ==============================
	// NEWS AND RESOURCES INDEX
	$('#photoGalleryTeasers img').addClass('moveleft padding2');
	
	// HOME PAGE
	// Set the sponsors box to the same height as the homeBottomLeft box.
	// first test both heights.
	var homeBottomLeftHeight = $('#home_left #homeBottomLeft').height();
	var homeSponsorsHeight = $('#home_left #sponsors').height();
	// Now adjust the smaller box to match the larger
	if (homeSponsorsHeight < homeBottomLeftHeight) {
		$('#home_left #sponsors').height(homeBottomLeftHeight);
	} else {
		$('#home_left #homeBottomLeft').height(homeSponsorsHeight + 11); // We add 11 pixels to account for the sifr title, it's processed after this.
	}
	
	// Set the two top left boxes to the same heights.
	// first test both heights.
	var homeTopLeftHeight = $('#home_left #homeTopLeft').height();
	var homeTopRightHeight = $('#home_left #homeTopRight').height();
	// Now adjust the smaller box to match the larger
	if (homeTopLeftHeight < homeTopRightHeight) {
		$('#home_left #homeTopLeft').height(homeTopRightHeight);
	} else {
		$('#home_left #homeTopRight').height(homeTopLeftHeight); // We add 11 pixels to account for the sifr title, it's processed after this.
	}
	
	// LANDING PAGES
	// The repeating region boxes must have <br clear="all" /> after every 2nd box or the layout can break.
	// First calculate the total and then loop through them all
	var totalLandingPageBoxes = $('.landingPage div.component_box6').size();
	for (i=0; i<totalLandingPageBoxes; i++) {
		// if it's an even numbered box, put the break tag after it.
		if (i%2 == 0 && i>0) {
			$('.landingPage div.component_box6:eq(' + (i-1) + ')').after('<br clear="all" />');
		}
	}
});



function randomRange(minNum,maxNum) {
	var randomnumber=Math.floor(Math.random() * (maxNum - 1 + minNum)) + minNum;
	return randomnumber;
}
//-->  

