//home rotator script.

$(document).ready(    
    function() 
    {       
        var pageIconOnSrc = $("#hiddenPageIconOn").val();
        var pageIconOffSrc =  $("#hiddenPageIconOff").val();
        var inMarkUp = $("#inMarkUp").val();        
        
        var homeRotator = $(".homeRotator");
        var homeRotatorIcons = $(".homeRotatorIcon");
        var homeRotatorFeatures = $(".homeRotatorFeature");
        var homeRotatorFeature = $(".homeRotatorFeature");
        
        var isPaused = inMarkUp != "true";
        var currentIndex = 0;                
        
        //rotate.
        setInterval(
            function()
            {
                if (!isPaused)
                {                
                    if (currentIndex == homeRotatorIcons.length)
                        currentIndex = 0;                                    
                                                                    
                    moveToFeature(homeRotatorIcons[currentIndex]);                                                                        
                    currentIndex = ++currentIndex;
                }
            },               
            6000
        );
        
        //mouse over event.
        homeRotatorIcons.mouseover(function() { moveToFeature(this); } );   
        
        //pause when mousing over rotator.
        homeRotator.mouseover(function() { isPaused = true; });
        
        //resume when mouse out of rotator.
        homeRotator.mouseout(function() { isPaused = false; });
        
        //move to feature.
        function moveToFeature(pageIcon)
        {                                        
            homeRotatorIcons.attr("src", pageIconOffSrc);                                   
            $(pageIcon).attr("src", pageIconOnSrc);                
            homeRotatorFeatures.removeClass("selected");       
            currentIndex = homeRotatorIcons.index(pageIcon);
            $(homeRotatorFeature[currentIndex]).addClass("selected");   
        }                                        
    }
 );
