﻿var secondaryFeatureIndex = 2;
var maxTabs = 3;
var pauseTimer;
var fadeInterval;
var fadeOutTimer;
var fadeInTimer;

if (!fadeInterval) fadeInterval = setInterval("RotateContent()", 6000);

function SecondaryFeature_Click(x) {
    secondaryFeatureIndex = x;
    TransitionSecondaryFeature(x);
}

function TransitionSecondaryFeature ( clickedIndex )
{
    // ensure selected tab isn't currently active
    if ( document.getElementById( "SecondaryFeature" + clickedIndex ).style.display == "block" )
    {
        return false;
    }
    
    // cycle through features and find the one that is currently active
    for ( i = 1; i <= maxTabs; i++ )
    {
        var fadeOutItem = document.getElementById( "SecondaryFeature" + i );
        if ( fadeOutItem.style.display == "block" )
        {
            // setup fadeout for currently active feature
            var YfadeOut = new YAHOO.util.Anim(fadeOutItem, { opacity: { to: 0 } }, .2);
        
            // setup fadein for newly selected feature
            var fadeInItem = document.getElementById( "SecondaryFeature" + clickedIndex );
            var YfadeIn = new YAHOO.util.Anim(fadeInItem, { opacity: { to: .999 } }, .8);

            // update active navigation styles
            document.getElementById( fadeOutItem.id + "Link" ).className = "";
            document.getElementById( fadeInItem.id + "Link" ).className = "Active";
                    
            // attach fadein event to occur after fadeout is complete
            YfadeOut.onComplete.subscribe(
                function() 
                {
                    // hide fadeout item
                    fadeOutItem.style.display = 'none';
                    
                    // show fadein item
                    fadeInItem.style.display = 'block';
                    
                    // begin fadein animation
                    YfadeIn.animate(); 
                }
            );
            
            // start animations
            YfadeOut.animate();
            return false;
        }
   }
}


function RotateContent()
{
    TransitionSecondaryFeature(secondaryFeatureIndex);

    if (secondaryFeatureIndex >= maxTabs)
    {
        secondaryFeatureIndex = 1;
    } else {
        secondaryFeatureIndex++;
    }
}

function PauseRotation(rotatePause)
{
    clearInterval(fadeInterval);
    if(!rotatePause)
    {
        secondaryFeatureIndex++;
        fadeInterval = setInterval("RotateContent()", 6000);
    }
    else
    {
        //If they clicked on a link, wait 2 mins then call this function again, which will restart the rotation 8 secs later
        if (!pauseTimer) pauseTimer = setTimeout("PauseRotation(false)", 120000);
    }
}

//Add an onmouseover events to each feature so that rotation will pause
for(i=1;i<4;i++)
{
    document.getElementById("SecondaryFeature"+i).onmouseover = function(){ PauseRotation(true); } 
}
document.getElementById("ctl00_ContentPlaceHolderFullPage_SecondaryFeature_ctl00_NewsletterSnapshot1_NewsletterEmailAddress").onkeypress = function(){ PauseRotation(true); }
