﻿$.ajaxSetup({
    async: false
});
//滚动图片
var _c = _h = 0;
$(function () {
    $('#slidenum > a').click(function () {
        _c = $(this).text() - 1;
        clearInterval(_h);
        changeimg(_c);
        startslide();
    })
    $("#slideimg img").hover(function () { clearInterval(_h) }, function () { startslide() });
    autoslide();
    startslide();
})
function startslide() {
    _h = setInterval("autoslide()", 3000);
}
function changeimg(i) {
    //$('#slidenum > a').css('background-color', '#ffffff').eq(i).css('background-color', '#1a4963').blur();
    $('#slidenum > a').attr("class", "scolla");
    $($('#slidenum > a')[i]).attr("class", "scolla_over");
    //$("#scollTitle").html($("#slideimg").find("a").eq(i).attr("alt"));
    //$("#scollContent").html($("#slideimg").find("img").eq(i).attr("alt"));
    //$("#scollURL").attr("href",$("#slideimg").find("a").eq(i).attr("href"));
    
    //$('#slidenum > a').css('color', '#1a4963').eq(i).css('color', '#ffffff').blur();
    $("#slideimg img").hide().eq(i).fadeIn('slow');
    $("#slideimg img").eq(i).css("display", "block");
}
function autoslide() {
    _c++;
    if (_c >= $("#slideimg img").size()) _c = 0;
    changeimg(_c);
}
//tab商品切换
$(function () {
    var tab_current = undefined;
    var menu_current = undefined;
    var u_current = undefined;
    var c_current = undefined;
    var sub_current = undefined;
    $(".tab_item").hover(
    function () {
        if (tab_current != undefined) {
            tab_current.attr("className", "tab_item");
            $("#div_" + tab_current.attr("id")).css("display", "none");
        }
        tab_current = $(this);
        tab_current.attr("className", "tab_item_current");
        $("#div_" + tab_current.attr("id")).css("display", "block");
    });
    //$($(".tab_item")[0]).mouseover();
    //菜单
    $(".menu_item").hover(
    function () {
        menu_current = $(".current");
        //        for (var i = 0; i < $(".menu_item").length; i++) {
        //            if ($(this).attr("id") == $(".menu_item").eq(i).attr("id")) {
        //                $("#sub_menudiv").css("paddingLeft", 300 + i * 120);
        //                $("#sub_menudiv").css("width", 980 - (300 + i * 120));
        //                $("#sub_menudiv").css("textAlign", "cneter");
        //            }
        //        }

        $(this).find("a").attr("className", "current");
        $("#sub_menudiv").html($("#sub" + $(this).attr("id")).html());


    },
    function () {
        if (menu_current.parents().attr("id") != $(this).attr("id"))
            $(this).find("a").attr("className", "");
    });

    $(".submenu_item").hover(
    function () {
        $("#sub_menudiv").html($(this).html());
    },
    function () {
        $(this).css("display", "none");
    });

    $("#div_utitle").append($("#div_ucontent").find(".u_span"));
    $("#div_ucontent").find(".u_span").remove(); ;

    $(".u_span").click(
    function () {
        if (u_current != undefined) {
            u_current.css("display", "none");
            sub_current.css("display", "none");
        }
        u_current = $("#divu_" + $(this).attr("id"));
        sub_current = $("#sub_" + $(this).attr("id"));
        if (sub_current.html().replace(/(^\s*)|(\s*$)/g, "") == "") {
            sub_current.html("");
            sub_current.append(u_current.find(".c_span"));
            u_current.find(".c_span").remove();
        }
        u_current.css("display", "block");
        sub_current.css("display", "block");
        $(".u_span_over").attr("className", "u_span")
        $(this).attr("className", "u_span_over");
        sub_current.find(".c_span").eq(0).click();
    });

    $(".c_span").click(
    function () {
        if (c_current != undefined)
            c_current.css("display", "none");
        c_current = $("#divc_" + $(this).attr("id"));
        c_current.css("display", "block");
        $(".c_span_over").attr("className", "c_span")
        $(this).attr("className", "c_span_over")
    });
    if ($(".u_span").length != 0) {
        $(".u_span").eq(0).click()
        //$(".c_span")[0].click();
    }
});
function setMenu(index) {
    $(".menu_item").find("a").eq(index).attr("className", "current");
}
function productSearch() {
    if ($("#txtSearch").val().replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入关键字！");
        return;
    }
    window.location.href = "Product.aspx?keyword=" + $("#txtSearch").val() + "&Type=" + $("#ddlProductType").val();
}
function selectScore(ownerID) {
    if ($("#txtNumber").val().replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("请输入会员卡号！");
        return;
    } else {
        $.post("/ashx/UpdateInfo.ashx", { state: "SelectScore", OwnerID: ownerID, Number: $("#txtNumber").val().replace(/(^\s*)|(\s*$)/g, "") }, function (data) {
            if (data == "false")
              alert("输入的卡号不存在！");
            else
              $("#scoreDiv").html("您的积分是："+data);
      });
    }
}
//向左滚动
function ScrollImgLeft(scroll_id_out, scroll_id_in, imgclass) {
    var _img;
    var scrollwidth = 2;
    var speed = 20;
    var imgframewidth = $("#" + scroll_id_out).css("width"); //图片外div的宽度
    imgframewidth = parseInt(imgframewidth.substr(0, imgframewidth.length - 2));

    var imgwidth = $($("." + imgclass)[0]).css("width"); //一张图片的宽度
    imgwidth = imgwidth.substr(0, imgwidth.length - 2);
    var scrollimg_margin_left = $($("." + imgclass)[0]).css("margin-left");
    if (scrollimg_margin_left != "auto")
        scrollimg_margin_left = scrollimg_margin_left.substr(0, scrollimg_margin_left.length - 2);
    else
        scrollimg_margin_left = 0;

    var scrollimg_margin_right = $($("." + imgclass)[0]).css("margin-right");
    if (scrollimg_margin_right != "auto")
        scrollimg_margin_right = scrollimg_margin_right.substr(0, scrollimg_margin_right.length - 2);
    else
        scrollimg_margin_right = 0;
    imgwidth = parseInt(imgwidth) + parseInt(scrollimg_margin_left) + parseInt(scrollimg_margin_right);

    var imgcount = $("." + imgclass).length;
    var scroll_div = document.getElementById(scroll_id_out);
    $("#" + scroll_id_in).css("width", imgcount * imgwidth * 2);
    scroll_div.scrollLeft = 0;
    var scollstate = 1;
    if (imgwidth * imgcount >= imgframewidth) {
        $("#" + scroll_id_in).append($("#" + scroll_id_in).html());
        Marquee1();
        //_img=setInterval("Marquee1()", speed);
    }
    function Marquee1() {
        if (scroll_div.scrollLeft >= (imgwidth * imgcount)) {
            scroll_div.scrollLeft = scrollwidth;
        }
        else {
            if (scollstate == 1)
                scroll_div.scrollLeft = scroll_div.scrollLeft + scrollwidth;
        }
        setTimeout(Marquee1, speed)
    }
    scroll_div.onmouseover = function () { scollstate = 0; }
    scroll_div.onmouseout = function () { scollstate = 1; }
}
