﻿//Splash Control.
var ITEMTIMEOUTLENGTH; //Global timeout value.
var cycleItemTimer; //Global timer.
var firstItem;
var lastItem;

$(document).ready(function() {         
    if ($('div.splash-item-collection'))
    {        
        //If only one item (or zero items) exist, then no need for animation. 	
        if ($('div.splash-item-collection > div.splash-item').length == 1) return;                     

        //Store first and last items in collection.
        firstItem = $('div.splash-item-collection > div.splash-item:first');
        lastItem = $('div.splash-item-collection > div.splash-item:last');        
        
        //Set our global timeout.          
        ITEMTIMEOUTLENGTH = $('input#transitionInterval').val();              

        $('div.splash-item-collection > div.splash-item').hover(
	        function() {			            
	            clearTimeout(cycleItemTimer);	            	            
	        },
	        function() {	            
	            cycleItemTimer = setTimeout("cycleItems()", ITEMTIMEOUTLENGTH);	            	            
	        }
        );
	    
        //Cycle through ticker items.
        cycleItemTimer = setTimeout("cycleItems()", ITEMTIMEOUTLENGTH);
    }
});

//Function to cycle through items.
function cycleItems()
{   
    clearTimeout(cycleItemTimer);						

    var activeItem = $('div.splash-item-collection > div.splash-item:visible');        
    var nextItem = (activeItem.attr('class') == lastItem.attr('class')) ? firstItem : (activeItem.next());
    
    activeItem.fadeOut("slow");    
    nextItem.fadeIn("slow", function() {
        cycleItemTimer = setTimeout("cycleItems()", ITEMTIMEOUTLENGTH);
    });
}
