/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

// Home Page
function slideSwitch1() {
	var $active = $('#slideshow1 IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow1 IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next('IMG').length ? $active.next('IMG')
        : $('#slideshow1 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');

	// 2009-09-20 KR Remove display:none, which we put in during init for IE8 bug fix
	$next.css('display', 'block');

    // 2009-09-20 KR Set interval specific to this image or default if 0
	var $interval = $next.attr('displayTime') ? $next.attr('displayTime') * 1000 : 5000;
	if ($interval < 2000) $interval = 2000;
	slideSwitch1TimeoutID = setTimeout( "slideSwitch1()",  $interval);

	$next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });

	// 2009-09-21 KR fill description - animate down, fill text, then animate back up - used animate vs fadin/out due to bug on 2nd fadein
	var $desc = $('#slideshow1 #description');
	$desc.animate({opacity: 0.0}, 200, function () {
		$desc.html($next.attr('description'));
	    $desc.animate({opacity: 1.0}, 800);
     });
}

var slideSwitch1TimeoutID = 0;
$(document).ready(function(){
	// 2009-09-20 KR Allow image-specific timeout for 1st pic
	var $interval = $('#slideshow1 IMG:first').attr('displayTime') ? $('#slideshow1 IMG:first').attr('displayTime') * 1000 : 5000;
	if ($interval < 2000) $interval = 2000;

	// 2011-06-23 KR Added TimeoutID so we can kill the setTimeout later, if desired
	slideSwitch1TimeoutID = setTimeout( "slideSwitch1()", $interval );  // 2009-09-20 KR was setInterval

	// 2009-08-18 KR - start with all images (except 1st) as 'hide' class, then unhide them when we start.
	$('#slideshow1 IMG').removeClass('hide');

	// 2009-09-21 KR fill description for 1st pic
	$('#slideshow1 #description').animate({opacity: 0.0}, 1);
	$('#slideshow1 #description').html($('#slideshow1 IMG:first').attr('description'));
	$('#slideshow1 #description').animate({opacity: 1.0}, 800);
});

// 2011-06-23 KR Add function to stop slideshow
function stopSlideSwitch1() {
	clearTimeout(slideSwitch1TimeoutID);
}





// Inner Pages
function slideSwitch2() {
	var $active = $('#slideshow2 IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow2 IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next('IMG').length ? $active.next('IMG')
        : $('#slideshow2 IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    // 2009-10-01 KR uncommented:
    var $sibs  = $active.siblings('IMG');
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

	// 2009-09-20 KR Remove display:none, which we put in during init for IE8 bug fix
	$next.css('display', 'block');

    // 2009-09-20 KR Set interval specific to this image or default if 0
	var $interval = $next.attr('displayTime') ? $next.attr('displayTime') * 1000 : 5000;
	if ($interval < 2000) $interval = 2000;
	slideSwitch2TimeoutID = setTimeout( "slideSwitch2()",  $interval);

	$next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });

	// 2009-09-21 KR fill description - animate down, fill text, then animate back up - used animate vs fadin/out due to bug on 2nd fadein
	var $desc = $('#slideshow2 #description');
	$desc.animate({opacity: 0.0}, 200, function () {
		$desc.html($next.attr('description'));
	    $desc.animate({opacity: 1.0}, 800);
     });
}

var slideSwitch2TimeoutID = 0;
$(document).ready(function(){
	// 2009-10-01 KR call slideSwitch2 one time to pull random 1st pic - call with setTimeout (=0), rather than just calling slideSwitch2() by itself so if it errors (as it does on home page with no inner pics), it won't crash rest of document-ready functions

	// 2011-06-23 KR Added TimeoutID so we can kill the setTimeout later, if desired
	slideSwitch2TimeoutID = setTimeout( "slideSwitch2()", 0);
	
	// 2009-10-01 KR 1st pic is now random
	// // 2009-09-20 KR Allow image-specific timeout for 1st pic
	// var $interval = $('#slideshow2 IMG:first').attr('displayTime') ? $('#slideshow2 IMG:first').attr('displayTime') * 1000 : 5000;
    // setTimeout( "slideSwitch2()", $interval );  // 2009-09-20 KR was setInterval

	// 2009-10-01 KR 1st pic is now random
	// // 2009-08-18 KR - start with all images (except 1st) as 'hide' class, then unhide them when we start.
	//	$('#slideshow2 IMG').removeClass('hide');

	// 2009-10-01 KR 1st pic is now random
	// // 2009-09-21 KR fill description for 1st pic
	// $('#slideshow2 #description').animate({opacity: 0.0}, 1);
	// $('#slideshow2 #description').html($('#slideshow2 IMG:first').attr('description'));
	// $('#slideshow2 #description').animate({opacity: 1.0}, 800);
});

// 2011-06-23 KR Add function to stop slideshow
function stopSlideSwitch2() {
	clearTimeout(slideSwitch2TimeoutID);
}





// 2009-10-24 KR Slideshow for text only
// Announements Footer
function slideSwitch3() {
	var $active = $('#slideshow3 P.active');

    if ( $active.length == 0 ) $active = $('#slideshow3 P:last');

    // use this to pull the paragraphs in the order they appear in the markup
    var $next =  $active.next('P').length ? $active.next('P')
        : $('#slideshow3 P:first');

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings('IMG');
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    // 2009-09-20 KR Set interval specific to this image or default if 0
	var $interval = $next.attr('displayTime') ? $next.attr('displayTime') * 1000 : 5000;
	if ($interval < 2000) $interval = 2000;
	slideSwitch3TimeoutID = setTimeout( "slideSwitch3()",  $interval);

	// 2009-09-21 KR fill description - animate down, fill text, then animate back up - used animate vs fadin/out due to bug on 2nd fadein
	$active.animate({opacity: 0.0}, 100, function () {
		// 2009-09-20 KR Remove display:none, which we put in during init for IE8 bug fix
		$next.css('display', 'block');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 200, function() {
				$active.removeClass('active last-active');
			});
     });
}

var slideSwitch3TimeoutID = 0;
$(document).ready(function(){
	// 2009-09-20 KR Allow image-specific timeout for 1st pic
	var $interval = $('#slideshow3 P:first').attr('displayTime') ? $('#slideshow3 P:first').attr('displayTime') * 1000 : 5000;
	if ($interval < 2000) $interval = 2000;
	
	// 2011-06-23 KR Added TimeoutID so we can kill the setTimeout later, if desired
	slideSwitch3TimeoutID = setTimeout( "slideSwitch3()", $interval );  // 2009-09-20 KR was setInterval

	// 2009-09-21 KR fill 1st paragraph
	$('#slideshow3 P:first').animate({opacity: 0.0}, 1, function () {
		$('#slideshow3 P:first').addClass('active').removeClass('hide').css('display', 'block');
	});
	$('#slideshow3 P:first').animate({opacity: 1.0}, 200);
});

// 2011-06-23 KR Add function to stop slideshow
function stopSlideSwitch3() {
	clearTimeout(slideSwitch3TimeoutID);
}

