var maxHomepageDisplay = 8;
var delayHomepageDisplay = 13000;
var StopRotation = false;
function rotateHero() {
    if (StopRotation == false) {
        var list = document.getElementById('HomepageHeroMenu');
        var listItems = list.getElementsByTagName('li');
        maxHomepageDisplay = listItems.length;
        var indexHomepageDisplay = 1;
        var currentStory;
        homepageDisplay = readCookie('HomepageDisplay');
        /*HomepageDisplay2*/

        for (var i = 1; i <= maxHomepageDisplay; i++) {
            if (homepageDisplay == i) {
                indexHomepageDisplay = i + 1;
            }
        }
        if (indexHomepageDisplay >= (maxHomepageDisplay + 1)) {
            indexHomepageDisplay = 1;
        }
        /*if (FadeActive == true) {*/
        MoveBackground(indexHomepageDisplay);
        createCookie("HomepageDisplay", indexHomepageDisplay, 10);
        setTimeout('rotateHero()', delayHomepageDisplay);
        /*} else {
        setTimeout('rotateHero()', delayHomepageDisplay);
        }*/
    }
}


function HaltRotation(movingDiv) {

    MoveBackground(movingDiv);
    StopRotation = true;
    return false;
}


function MoveBackground(movingDiv) {
    var clickevent = SwitchHPFeaturedItem(movingDiv);
    resetBackgrounds(movingDiv);
    $(document).ready(function () {
        $("#HomepageDisplay" + movingDiv).show();

    })
    createCookie("HomepageDisplay", movingDiv, 10);
    return false;
}


function SwitchHPFeaturedItem(hoverIndex) {
    var list = document.getElementById('HomepageHeroMenu');
    var listItems = list.getElementsByTagName('li');
    for (itemIndex = 0; itemIndex < listItems.length; itemIndex++) {
         var anchorItem = listItems[itemIndex].getElementsByTagName('a');
        if (itemIndex == hoverIndex-1) {

            if (hoverIndex != listItems.length) {
                anchorItem[0].className = 'ActiveHPMenu';
            } else {
                anchorItem[0].className = 'ActiveHPMenuLast';
            }
           
        } else {
            if (itemIndex != listItems.length -1) {
                anchorItem[0].className = 'item';
            } else {
                anchorItem[0].className = 'last';
            }
        }
    }
    return false;
}


function MoveBackground2(movingDiv) {
    resetBackgrounds(movingDiv);
    $(document).ready(function () {
        $("#HomepageDisplay" + movingDiv).animate({ "top": "+=300px" }, "fast", MoveContent(movingDiv));

    })
    return false;
}

function MoveContent(movingDiv) {

    $(document).ready(function () {
        $("#HomepageDisplay" + movingDiv + "MainContent").animate({ "right": "+=1340px" }, "slow");

    })
}

function resetBackgrounds(index) {

    for (var counter = 1; counter <= maxHomepageDisplay; counter++) {
        $("#HomepageDisplay" + counter).hide();
    }
    
    
}
function resetBackgrounds2(index) {


    $("#HomepageDisplay1").css("top", "-300px");
    $("#HomepageDisplay1MainContent").css("right", "-1000px");
    $("#HomepageDisplay2").css("top", "-300px");
    $("#HomepageDisplay2MainContent").css("right", "-1000px");
}


