$(document).ready(function()
{
	$("a[href$='.pdf']").addClass("pdf");
});	
	
	//**************************
// slideSwitch
//**************************
var imageArray=[];
imageArray.push("<img src='graphics/home/hero1.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero10.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero2.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero11.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero3.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero4.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero12.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero5.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero6.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero7.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero8.jpg' width='980' height='186' border='0'>");
imageArray.push("<img src='graphics/home/hero9.jpg' width='980' height='186' border='0'>");

var nCurrentImage = 1;
var bLoop = 0;
var nStopSlideshowID = setInterval( "slideSwitch()", 4000 ); // make this last.
var nImageCount = imageArray.length;

//**************************
// slideSwitch
//**************************
function slideSwitch() {
	
	// dynamically loads the images as they are called for instead of preloading all at once!
	
	// Fetch the current list of images. The 1st time in, there will only be the 1 image. 
	var $images = $('#slideshow IMG');
	
	// Has the currently requested image been loaded yet? If not, load it.
	// Is the img indexed by nCurrentImage in our list of images? (and is the nCurrentImage index still within our array range?)
	if (($images.length < nImageCount) && (nCurrentImage < nImageCount))
	{
		var sHTML = imageArray[nCurrentImage];
		$('#slideshow').append(sHTML);
	}
	
	// this must take place AFTER the above image setting (appending)
	nCurrentImage++;
	
	// fetch the currently displaying image
	var $active = $('#slideshow IMG.active');

	// if we're not yet dipslaying any image, start with the last image
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	// fetch the next image. If there is only 1 image in the list, use that.
    var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');

	// add 'last-active' class to the current image to indicate that it was the one most recently displaying
    $active.addClass('last-active');

	// Set the CSS opacity on the next image to invisible (zero), add the 'active' class to it and then
	// animate it to visibility over 1 second. when complete, remove the 'active and last-active' classes
	// from the image that was displaying.
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1}, 1800, function() {
            $active.removeClass('active last-active');
        });
		
	// if we're not looping, see if this is the last image. If so, stop.
	if (!bLoop)
	{
		if (nCurrentImage >= nImageCount) clearInterval(nStopSlideshowID);
	}
}


