﻿var _counter = 1;
var _rotateItemsInterval;
var _rotateItemsPause;
var _rotatePeriod = 10000;

$(document).ready(function () {
    StartItemRotator();
    

});

function StartItemRotator() {
// Run our swapImages() function every 4secs
    _rotateItemsInterval = setInterval('RotateItems()', _rotatePeriod);
}

function ShowItem(itemID) {

    _counter = itemID;

    if ($("#Heading > img").size() > 1) {
        ResetAllHeadings();
        $('#Heading' + itemID).delay(500).fadeIn(400);
    }

    ResetAllSubHeadings();
    $('#SubHeading' + itemID).delay(500).fadeIn(400);

    if ($("#MainText > div").size() > 1) {
        ResetAllMainText();
        $('#MainText' + itemID).delay(500).fadeIn(400);
    }

    ResetAllButtons();
    $("#Button" + itemID).addClass("activeItemYello");

    ResetAllBottomMenus();
    $("#BottomMenu" + itemID).addClass("activeItemWhite");

    if ($("#BottomRightImage > img").size() > 1) {
        ResetAllBottomRightImages();
        $('#BottomRightImage' + itemID).delay(500).fadeIn(400);
    }

}

function ResetAllHeadings() {
    $("#Heading").children().fadeOut(400);
}

function ResetAllSubHeadings() {
    $("#Subheading").children().fadeOut(400);
}

function ResetAllMainText() {
    $("#MainText").children().fadeOut(400);
}

function ResetAllButtons() {
    $("#Buttons").children().removeClass("activeItemYello");
    $("#Buttons").children().addClass("whiteLink ");
}

function ResetAllBottomMenus() {
    $("#BottomMenu").children().removeClass("activeItemWhite");
    $("#BottomMenu").children().addClass("blackLink");
}

function ResetAllBottomRightImages() {
    $("#BottomRightImage").children().fadeOut(400);

}



function RotateItems() {
    _counter++;
    if (_counter > numberOfItems) {
        _counter = 1;
    }

    ShowItem(_counter);

};


function ShowItemAndPause(itemID) {
//pause the item rotator and pause
    clearInterval(_rotateItemsInterval);
    clearTimeout(_rotateItemsPause);

    //show item
    ShowItem(itemID);

    //wait 15 sec and start rotator again
   _rotateItemsPause = setTimeout(StartItemRotator, 30000);

}
