﻿
//热卖推荐/新品上架使用
function changeTab(curr) {
    var tabs = $("#tagtable td[id]");
    var entityID;
    $.each(tabs, function(entityIndex, entity) {
        entityID = $(entity).attr("id");
        $(entity).attr("class", "home_bg_off");
        $("#" + entityID + " > img").attr("src", "/images/icon_gray.gif");
        $("#div_" + entityID).hide();
        entityID = null;
    });
    tabs = null;

    $("#" + curr).attr("class", "home_bg_on");
    $("#" + curr + " > img").attr("src", "/images/icon_red.gif");
    $("#div_" + curr).show();
}

//热卖推荐/新品上架使用
function TabAutoChange() {
    var tabs = $("#tagtable td[id]");
    var ii = 0;
    $.each(tabs, function(entityIndex, entity) {
        if ($(entity).attr("class") == "home_bg_on") {
            ii = entityIndex + 1;
        }
    });

    if (ii >= tabs.length) { ii = 0; }
    changeTab($(tabs[ii]).attr("id"))
    tabs = null;
}

$(document).ready(function() {
    setInterval("TabAutoChange()", 5000);

    //limitCutover("next");
//    var ctvr = setInterval(function() { limitCutover("next") }, 3000);
//    $("#limitdiv").mouseenter(function() { clearInterval(ctvr); });
//    $("#limitdiv").mouseleave(function() { ctvr = setInterval(function() { limitCutover("next") }, 3000); });

//    $("#limitprev").click(function() { limitCutover("prev"); });
//    $("#limitnext").click(function() { limitCutover("next"); });

});

//右侧抢购使用第一屏
function limitCutover(type) {
    var lis = $("#limitproduct > li");
    var icurrent = 0;
    $.each(lis, function(entityIndex, entity) {
        if ($(entity).css("display") == "block") {
            $(entity).css("display", "none");
            if (type == "prev") {
                icurrent = entityIndex - 1;
            }
            else {
                icurrent = entityIndex + 1;
            }
            
            return;
        }
    });
    if (icurrent >= lis.length) { icurrent = 0; }
    if (icurrent <= -1) { icurrent = (lis.length - 1); }
    
    $(lis[icurrent]).css("display", "block");
    lis = null;
}     
