var codaSliderTotalTimerCnt = 1;
function InitializeHomePageSlider() {
    $(document).ready(function() {
        $('ul.navigation a:first').click();
        var interavl = 13500;
        var intHandler = window.setInterval(changeCodaSlider, interavl);
        HomePageSliderSlide_Changed(codaSliderTotalTimerCnt);
        var intHandler2 = null;
        var totalSlides = $("#slider div.panel").length;
        var totalSlideShowDurationInSeconds = (totalSlides * interavl) / 1000;
        //alert(totalSlideShowDurationInSeconds);
        InitializeHomePageTimerCountdown(totalSlideShowDurationInSeconds);
        function changeCodaSlider() {
            intHandler = window.clearInterval(intHandler);
            HomePageSliderSlide_Changed(codaSliderTotalTimerCnt + 1);
            codaSliderTotalTimerCnt++;
            $('img.scrollButtons.right').click();
            if (codaSliderTotalTimerCnt == totalSlides) {
                intHandler = window.clearInterval(intHandler);
                intHandler2 = window.setInterval(demoRegistration, interavl);
                //Cookie logic moved to Presentation#2 CompensationPlan
                //setCookie('HomePagePresentationViewed', 'true', null); //Marked the presentation as Viewed
            }
            else {
                intHandler = window.setInterval(changeCodaSlider, interavl);
            }
        }

        function demoRegistration() {
            window.location = 'Register.aspx';
        }

    });
}

var codaSliderTotalTimerCompensationPlanCnt = 1;
function InitializeCompensationPlanSlider() {
    $(document).ready(function() {
        $('ul.navigation a:first').click();

        var interavl = 7000;
        var intHandler = window.setInterval(changeCodaSlider, interavl);
        var intHandler2 = null;
        function changeCodaSlider() {
            intHandler = window.clearInterval(intHandler);
            codaSliderTotalTimerCompensationPlanCnt++;
            $('img.scrollButtons.right').click();
            if (codaSliderTotalTimerCompensationPlanCnt == $("#slider div.panel").length) {
                intHandler = window.clearInterval(intHandler);
                intHandler2 = window.setInterval(sliderComplete, interavl);
                setCookie('HomePagePresentationViewed', 'true', 3650); //Marked the presentation as Viewed and make 10years cookie (2011-12-22)
                playCompensationPlanVideo();
            }
            else {
                intHandler = window.setInterval(changeCodaSlider, interavl);
            }
        }

        function sliderComplete() {
            //window.location = 'Register.aspx';
            intHandler2 = window.clearInterval(intHandler2);
        }

        function playCompensationPlanVideo() {
            if (typeof (playVideo) === "function") {
                flowplayer('player1', 'FlowPlayer/flowplayer-3.2.7.swf');
            }
        }

    });
}

function InitializeHomePageTimerCountdown(cntdown) {
    cntdown = (6 * 60) + 39; //6m39s
    $('#tmrHomePageCountdown').countdown({
        until: cntdown,
        layout: 'Special Announcement in {mn}:{snn}',
        compact: true,
        onExpiry: TimerForHomePageCountdown_Expired
    });

    function TimerForHomePageCountdown_Expired() {
        HideHomePageTimerCountdownContainer();
    }
}

function HomePageSliderSlide_Changed(slideNo) {

    //SlideNo >= 10 are largewall
    switch (slideNo) {
        case 11: case 2:    
            $("#homePageTimerCountdownContainer").addClass("largeWall");
            break;
        default:
            $("#homePageTimerCountdownContainer").removeClass("largeWall");
            break;
    }
    
    switch (slideNo) {
        case 5: case 11:
            ShowHomePageTimerCountdownContainer();
            break;
        default:
            HideHomePageTimerCountdownContainer();
            break;
    }
}

function HideHomePageTimerCountdownContainer() {
    $("#homePageTimerCountdownContainer").css("visibility", "hidden");
}
function ShowHomePageTimerCountdownContainer() {
    $("#homePageTimerCountdownContainer").css("visibility", "visible");
}
