﻿var index = 0, index1 = 0;
var MyTime1, MyTime2;
$(document).ready(function () {
    lunhuan("idNum", "idSlider", "idTransformView","X");	
    lunhuan("idNum1", "idSlider1", "idTransformView1","Y");	 
    $("#brs").jCarouselLite({
        auto: true,
        vertical: true,
        visible: 2,
        speed: 3000,
        scroll: 1
    });
    /*控制新品显示*/
    MyTime1 = setInterval(function () {
        $("#" + 'news_sp a').each(function () {
            if ($(this).index() == index) {
                GetNewProductByType('/home/GetNewProductByCategory', 'new_p', this);
            }
        });
        index++;
        if (index == 6) {
            index = 0;
        }
    }, 10000);
    /*控制特价显示*/
    MyTime2 = setInterval(function () {
        $("#" + 'tj_sp a').each(function () {
            if ($(this).index() == index1) {
                GetNewProductByType('/home/GetTjProductByCategory', 'tj_p', this);
            }
        });
        index1++;
        if (index1 == 6) {
            index1 = 0;
        }
    }, 12000);

    AjaxGetLeft();
});
function lunhuan(idNum, idSlider, idTransformView,obj) {
    /*焦点图代码开始*/
    var lengthFocus = $("#" + idNum + " > li").length;
    var indexNum = 0;
    var num = 0;
    $("#" + idNum + " li").mouseover(function () {
        indexNum = $("#" + idNum + " li").index(this);
        showFocusImg(idSlider, idNum, indexNum)
    });
    //滑入停止动画，滑出开始动画.
    $('#' + idTransformView).hover(function () {
        if (MyTime) {
            clearInterval(MyTime);
        }
    }, function () {
        MyTime = setInterval(function () {
            showFocusImg(idSlider, idNum, num)
            num++;
            if (num == lengthFocus) { num = 0; }
        }, 4000);
    });
    //自动开始
    var MyTime = setInterval(function () {
        showFocusImg(idSlider1, idNum1, num)
        num++;
        if (num == lengthFocus) { num = 0; }
    }, 4000);

    //关键函数：通过控制stop ，来显示不同的幻灯片
    function showFocusImg(slider, num, i) {
        if (obj == "X")
            $("#" + slider).stop(true, false).animate({ left: -779 * i }, 800);
        if (obj == "Y")
            $("#" + slider).stop(true, false).animate({ top: -103 * i }, 800);
        $("#" + num + " li").eq(i).addClass("on").siblings().removeClass("on");
    }
    /*焦点图片代码结束*/
}
//新品停止动画    鼠标滑入
function newsStop(sth) {
    clearInterval(MyTime1);
    GetNewProductByType('/home/GetNewProductByCategory', 'new_p', sth);
}
//新品开始动画    鼠标滑出
function newsStart() {
    MyTime1 = setInterval(function () {
        $("#" + 'news_sp a').each(function () {
            if ($(this).index() == index) {
                GetNewProductByType('/home/GetNewProductByCategory', 'new_p', this);
            }
        });
        index++;
        if (index == 6) {
            index = 0;
        }
    }, 10000);
}
//特价停止动画   鼠标滑入
function tjStop(sth) {
    clearInterval(MyTime2);
    GetNewProductByType('/home/GetTjProductByCategory', 'tj_p', sth);
}

//特价开始动画   鼠标滑出
function tjStart() {
    MyTime2 = setInterval(function () {
        $("#" + 'tj_sp a').each(function () {
            if ($(this).index() == index1) {
                GetNewProductByType('/home/GetTjProductByCategory', 'tj_p', this);
            }
        });
        index1++;
        if (index1 == 6) {
            index1 = 0;
        }
    }, 12000);
}
//类型菜单
function MenuPopUp(obj) {
    $(obj).addClass("mainlevel_over");
    $(obj).bind("mouseout", function () {
        $(obj).removeClass("mainlevel_over");
        $(obj).children("ul").hide();
    });
    $(obj).children("ul").show();
}
function AjaxGet(url) {
}



//动态查询特价商品和新品
function GetNewProductByType(url, id, me) {

    var str = "<div style=\"padding-top:210px;padding-left:420px;\"><img alt=\"正在加载\"  src=\"../../Images/onLoad.gif\" />正在加载中...</div>";
    $("#" + id).html(str);
    if (id == 'new_p')
        RemoveCs('news_sp');
    if (id == 'tj_p')
        RemoveCs('tj_sp');
    $(me).addClass("onmouse");
    $.ajax({
        url: url,
        type: "POST",
        cache:false,
        data: { CateType: $(me).attr('id') },
        success: function (data) {
            $("#" + id + "").html(data);
        }
    });
}
//删除a标签选中的样式
function RemoveCs(name) {
    $("#" + name + " a").each(function () {
        $(this).removeClass("onmouse");
    });
}
//调用生成的左边列表
function AjaxGetLeft() {
    var x
    if ($("#_YH_SORTLIST1") != null)
        x = $("#_YH_SORTLIST1").remove().html();
    if ($("#_YH_ALLSORT1") != null)
        $("#_YH_ALLSORT1").html(x).attr("load", "1");
    $(".allsort1 .item").hoverForIE6To({ delay: 0 });
}
