// Javascript to be loaded only for home page
function slideSwitch() {
    var $active = jQuery('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function setSlide(selector){
	var nextImg = jQuery(selector);
	var activeImg = jQuery('#slideshow IMG.active');

    activeImg.addClass('last-active');

    nextImg.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 250, function() {
            activeImg.removeClass('active last-active');
        });
    clearInterval(slideShowInterval);
    slideShowInterval = setInterval( "slideSwitch()", slideWait );
}


function toggleFlash(){
	var objs = document.getElementsByTagName('object');
	for(i in objs){
		if(objs[i].type == "application/x-shockwave-flash"){
			if( objs[i].style.display=='none' ){
				objs[i].style.display='inline';
			}else{
				objs[i].style.display='none';
			}
		}
 	}
}

function toggleReadIt(){
 	toggleFlash();
 	popup('popUpDiv');
 	return false;
}

var slideWait = 7000; //in ms
var slideShowInterval = setInterval( "slideSwitch()", slideWait );
