﻿var TIME_TO_SLIDE = 1500; //1.5 secs
var TIME_TO_WAIT = 3000; //3 secs
var TIME_TO_WAIT1 = 5000; //3.5 secs

$(window).load(function () {
    if (tabQty != 0) {
        // set up tabs
        setUpTabsForSliding(tabQty);
        $(document).oneTime(TIME_TO_WAIT, "pageLoad", function () {
            slideTabTo("#hn_banner_" + tabOn % tabQty, $("#hn_banner_" + tabOn % tabQty).width());
            slideTabTo("#hn_banner_" + ++tabOn % tabQty, 0);
            $("#hn_bannerTabs li a").removeClass("active");
            $("#bnrTab" + tabOn % tabQty + " a").attr("class", "active");
            // });
            $(document).everyTime(TIME_TO_WAIT1, "pageLoad", function () {
                slideTabTo("#hn_banner_" + tabOn % tabQty, $("#hn_banner_" + tabOn % tabQty).width());
                slideTabTo("#hn_banner_" + ++tabOn % tabQty, 0);
                $("#hn_bannerTabs li a").removeClass("active");
                $("#bnrTab" + tabOn % tabQty + " a").attr("class", "active");
                if (tabOn != tabOn % tabQty) { // i.e., beyond end of tab list
                    // $(document).stopTime();
                }
            }, 0, true);
        });
        //checkQueryString('mktgHome','','mdsflp_HomepageLandingPage_1');
    }
});

function slideTabTo(tId, xPos) {
    $(tId).animate({
        'top': '0px',
        'left': '-' + xPos + 'px'
    }, TIME_TO_SLIDE, 'swing', function () {
        $(tId).css({
            'top': '0px',
            'left': xPos + 'px'
        })
    });
}

function moveTabTo(tId, xPos) {
    // $(tId).fadeOut().css({'top':'0px','left':xPos+'px'}).fadeIn();
    $(tId).css({
        'top': '0px',
        'left': xPos + 'px'
    });
}

function setUpTabsForSliding(n) {
    for (var i = 1; i < n; i++) // skip zeroth tab
    {
        $("#hn_banner_" + i).css({
            'display': 'block',
            'left': $("#hn_banner_" + i).width() + 'px'
        });
    }
}

function stopIt(cmd, el) {
    $(document).stopTime();
    if (cmd == 'pause') {
        $('.pauseButton').hide();
        $(el).hide();
    } else {
        $('.hnBanner').hide();
        $("#hn_banner_" + cmd).stop();
        moveTabTo("#hn_banner_" + cmd, 0);
        $("#hn_banner_" + cmd).show();
        $(".hn_tab a").removeClass("active");
        $("#bnrTab" + cmd + " a").attr("class", "active");
    }
    return false;
}
