﻿/*** 
    DIV Slideshow
    Written by Jon Sinclair 2/19/09 using:
    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 :)
***/
var a = 1500;   // fade speed
var b = 6000;  // slide "up" time
var playSlideshow = setInterval( "slideSwitch()", b );
var state = "playing";

// randomize the starting slide if active is not set
function initSlide() {
    var $test = $('#slideshow').children('.active');
    if ($test.length <= 0)
    {
        var $kids  = $('#slideshow').children('.slide');
        var rndNum = Math.floor(Math.random() * $kids.length );
        $( $kids[ rndNum ] ).addClass('active');
    }
}

function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next('div.slide').length ? $active.next('div.slide')
        : $('#slideshow DIV:first');

    $active.fadeOut(a,function(){
        $active.removeClass('active');
        $next.addClass('active').hide().fadeIn(a);
    });
}

function playpause() {
    if (state == "playing")
    {
        clearInterval(playSlideshow);
        state = "paused";
        $('img#imgPlayPause').attr("src","/Images/default-slideshow-play.gif");
        $('img#imgPlayPause').attr("alt","Click to play");
    } else
    {
        playSlideshow = setInterval( "slideSwitch()", b );
        state = "playing";
        $('img#imgPlayPause').attr("src","/Images/default-slideshow-pause.gif");
        $('img#imgPlayPause').attr("alt","Click to pause");
        slideSwitch();
    }
}

$(function() {
    $('#slideshow DIV.active').fadeIn(a);
});

// Custom sliding navigation: Jon Sinclair, December 27, 2008
// Feel free to use this as needed, please leave the credit 
// if don't change the code, or just change the variables.
$(document).ready(function(){
    //for slideshow
    initSlide();
    //for top tier of nav
    $("#nav").find("ul li").hoverIntent(
		function(){
			if (this._timerID)
				clearTimeout(this._timerID)
			$("ul.tier1",this).fadeIn("fast");
			$("ul.tier1 li ul",this).hide();
		}, 
		function(){
			var self = this;
			var fadespeed = 200;
			this._timerID = window.setTimeout(function(){
				// jQuery fade out the UL of the calling li
				$("ul.tier1", self).fadeOut("fast");
			},fadespeed);
		}
	);
	$("#nav").find("ul li ul li").hover(
	    function(){
	        $("ul.tier2",this).fadeIn("fast");
	    },
	    function(){
	        $("ul.tier2",this).fadeOut("fast");
	    }
	);
});