
var sizetitle = ""; //尺码或净含量

$(document).ready(function() {
    sizetitle = $.trim($("#selectedSize").text().split('：')[0]);
    $("#bigView").decorateIframe();
    var productcode = $("#productcode").text().split("：")[1];
    $("#addToShoppingCar").click(function() {
        var closeCode = getCloseCode();
        if (closeCode == null) {
            alert('请选择尺码');
            return false;
        }
        var url = [];
        url.push(WebSiteHttps);
        url.push("/Shopping/Shopping_IncartConfirm.ashx");
        url.push("?ProductID=");
        url.push(closeCode);
        url.push("&num=");
        url.push($("#selectedAmount").val());
        if ($(this).attr("href").length > 1) {
            url.push($(this).attr("href").replace("#", "&"));
        }

        $.fn.popwindow({
            href: "/styles/Static.mvc?Position=MyShoppingCar&t=" + Math.random(),
            width: '400px', height: "130px", title: "操作提示", noOverlayClose: true
        });

        $(".close").one("click", function() { window.location = window.location.href });

        $.getJSON(url.join("") + "&callback=?", function(data) {
            if (!data.error || data.error == "") {
                try {
                    $("#LoadedContent").contents().find("#price").text(data.price);
                    $("#LoadedContent").contents().find("#count").text(data.amount);

                    $("#LoadedContent").contents().find("#loading").fadeOut();
                } catch (err) {
                    $("#LoadedContent").attr("src", $("#LoadedContent").attr("src") + "&p=" + data.price + "&c=" + data.amount);
                }
            } else {

                $("#LoadedContent").attr("src", "/styles/Static.mvc?Position=ShoppingCarError&msg=" + escape(data.error));
            }
        });
        return false;

    });

    $("img[original]").lazyload({
        placeholder: "images/list/color3.gif",
        event: "scroll"
    });

    var producttype = $("#pricearea").attr("name");
    var styleid = $("#styleinfo").attr("name");
    //切换花色
    $(".selColorArea .selColor li[name]").click(function() {

        if ($(this).attr("id") != "onlickColor") {
            if ($("#onlickColor").length == 0) {
                var params = $(this).attr("name").split('&');
                url = "/StyleDetail_0_" + params[0].split('=')[1] + "_0/pinyin.html"
                window.location = url;
                return false;
            }
            var $this = $(this);
            back2view();
            $(".selSize li").removeAttr("onclick");
            $("#loading")
            .css({
                "top": $(".bigImg").position().top,
                "height": $(".bigImg").height()
            }).show();
            if ($(this).find(".colorBlock").attr("name") == "True") {
                $("#comeon").show();
            } else {
                $("#comeon").hide();
            }
            $.get("/styles/AjaxChangeProduct.mvc?" + $(this).attr("name"), function(data) {

                //ajax
                $("#midimg").attr("src", $("#midimg", data).attr("src"));
                changeViewImg();
                $("#imageMenu").html($("#imageMenu", data).html());
                $("#loading").fadeOut("slow").hide(0);

                $("#pricearea").html($("#price", data).html());
                $(".selSizeArea").html($("#size", data).html());
                $("#SimilarPurchase").html($("#SimilarPurchase", data).html());

                var $color = $.trim($this.text());
                productcode = $("#productcode").text().split("：")[1];
                $(".selColorArea .selColor li").removeAttr("id");
                $this.attr("id", "onlickColor");
                $(".selColorArea .clothingColor strong").text($color);
                $("#selectedColor").text("颜色：" + $color);


                if ($("#onlickSelSize").length == 1) {
                    $("#selectedSize").text(sizetitle + "：" + $.trim($(".selSize #onlickSelSize").text()));
                    $(".selSizeArea h3 strong").text($.trim($(".selSize #onlickSelSize").text()));

                } else {
                    $(".selSizeArea h3 strong").text("未选择");
                    $("#selectedSize").text(sizetitle + "：未选择");
                }
                $("#selectedAmount").attr("value", '1');
                $(".goodsPrice p em").text($(".cuxiaoPrice span").text());
                $("#imageMenu").scrollTop(0).scrollLeft(0);
                checkMenuStatus();

                //放大查看
                $(".fangda a").attr("href", WebSite + "/Product/Pic.aspx?ProductCode=" + productcode + "&ProductName=" + encodeURI($.trim($("#pricearea h2").text())));

                //收藏
                //$(".dp_scbtn").attr("href", WebSite + "/Usercenter/UserFavorite.aspx?AddCart=" + productcode);

                //我要评论
                $("#pinglun").attr("href", $("#pinglun").attr("href").replace(/\d{7,8}/, productcode));
                var url = location.href.replace(/\d{7,8}/, productcode);
                setCookie("ShoppingBackUrl", url, 30);

                //库存信息
                var closeCode = getCloseCode();
                if (closeCode == null) {
                    $("#stockinfo").text("请先选择" + sizetitle);
                } else {
                    checkStocking();
                }
            });

        }
    });

    //点击到中图
    var midChangeHandler = null;
    $("#imageMenu li img").live("click", function() {
        if ($(this).attr("id") != "onlickImg") {
            midChange($(this).attr("src").replace("small", "mid"));
            $("#imageMenu li").removeAttr("id");
            $(this).parent().attr("id", "onlickImg");
        }
    }).live("mouseover", function() {
        if ($(this).attr("id") != "onlickImg") {
            window.clearTimeout(midChangeHandler);
            midChange($(this).attr("src").replace("small", "mid"));
            $(this).css({ "background": "none repeat scroll 0 0 #336699", "border": "1px solid #336699" });
        }
    }).live("mouseout", function() {
        if ($(this).attr("id") != "onlickImg") {
            $(this).removeAttr("style");

        }
    });

    function midChange(src) {
        $("#midimg").attr("src", src).load(function() { changeViewImg(); });
    }

    //滑动左边小图
    $("#imageMenu").scrollTop(0).scrollLeft(0);

    var data = [];
    data["smallImgDown"] = {
        direction: 1,
        target: "last-child",
        visible: function() {
            return $("#imageMenu").scrollTop() + $("#imageMenu").height() == $("#imageMenu").attr("scrollHeight");

        },
        span: function($dom) {
            return $dom.position().top;
        },
        scrollSpan: function($dom) {
            return $dom.scrollTop();
        },
        animateParam: function(move) {
            return { scrollTop: move };
        }
    };
    data["smallImgUp"] =
    {
        direction: -1,
        target: "first",
        visible: function() {
            return $("#imageMenu").scrollTop() == 0;
        },
        span: function($dom) {
            return $dom.position().top;
        },
        scrollSpan: function($dom) {
            return $dom.scrollTop();
        },
        animateParam: function(move) {
            return { scrollTop: move };
        }
    };

    data["smallImgRight"] = {
        direction: 1,
        target: "last-child",
        visible: function() {
            return $("#imageMenu").scrollLeft() + $("#imageMenu").width() == $("#imageMenu").attr("scrollWidth");

        },
        span: function($dom) {
            return $dom.position().left;
        },
        scrollSpan: function($dom) {
            return $dom.scrollLeft();
        },
        animateParam: function(move) {
            return { scrollLeft: move };
        }
    };
    data["smallImgLeft"] =
    {
        direction: -1,
        target: "first",
        visible: function() {
            return $("#imageMenu").scrollLeft() == 0;
        },
        span: function($dom) {
            return $dom.position().left;
        },
        scrollSpan: function($dom) {
            return $dom.scrollLeft();
        },
        animateParam: function(move) {
            return { scrollLeft: move };
        }
    };

    //控制上下箭头
    $(".smallImgDown,.smallImgUp,.smallImgRight,.smallImgLeft").click(function() {
        var className = $(this).attr("class");

        if ($("." + className + " img").attr("src").indexOf(className + "02.gif")) {
            var mydata = data[className];
            var num = 0;
            while (mydata.span($("#imageMenu")) > mydata.span($("#imageMenu li").eq(num))) {
                num++;
            }

            num += 5 * mydata.direction;

            var $li = $("#imageMenu li").eq(num);
            if ($li.length == 0 || num < 0) {
                $li = $("#imageMenu li:" + mydata.target);
            }

            var move = mydata.scrollSpan($("#imageMenu")) + mydata.span($li) - mydata.span($("#imageMenu"));
            $("#imageMenu").animate(mydata.animateParam(move), 500, checkMenuStatus);
        }
    });

    function checkMenuStatus() {
        for (key in data) {
            var $img = $("." + key + " img");
            if ($img.length > 0) {
                if (data[key].visible()) {
                    if ($img.attr("src").indexOf(key + "01.gif") > -1) {
                        $img.attr("src", $img.attr("src").replace(key + "01.gif", key + "02.gif"));
                    }
                } else {
                    if ($img.attr("src").indexOf(key + "02.gif") > -1) {
                        $img.attr("src", $img.attr("src").replace(key + "02.gif", key + "01.gif"));
                    }
                }
            }
        }
    }

    //大视窗看图
    function mouseEnter(e) {
        if ($("#winSelector").css("display") == "none") {
            $("#winSelector,#bigView").show();
        }

        $("#winSelector").css(fixedPosition(e));
        e.stopPropagation();
        return false;
    }

    function mouseOut(e) {
        if ($("#winSelector").css("display") != "none") {
            $("#winSelector,#bigView").hide();
        }
        e.stopPropagation();
    }

    if (document.createTouch) {
        $("#midimg,#winSelector").bind("touchmove", mouseEnter).bind("touchend", mouseOut);
    } else {
        $("#midimg").mouseenter(mouseEnter); //中图事件
        $("#midimg,#winSelector").mousemove(mouseEnter).mouseout(mouseOut); //选择器事件
    }


    var $divWidth = $("#winSelector").width(); //选择器宽度
    var $divHeight = $("#winSelector").height(); //选择器高度
    var $imgWidth = $("#midimg").width(); //中图宽度
    var $imgHeight = $("#midimg").height(); //中图高度
    var $viewImgWidth = $viewImgHeight = $height = null; //IE加载后才能得到 大图宽度 大图高度 大图视窗高度



    function changeViewImg() {
    }
    changeViewImg();

    $("#bigView").scrollTop(0);
    function fixedPosition(e) {
        if (e == null) {
            return;
        }
        var pageX = e.clientX + $(document).scrollLeft();
        var pageY = e.clientY + $(document).scrollTop();
        if (document.createTouch) {
            pageX = event.touches[0].pageX;
            pageY = event.touches[0].pageY;
        }

        var $imgLeft = $("#midimg").offset().left; //中图左边距
        var $imgTop = $("#midimg").offset().top; //中图上边距
        X = pageX - $imgLeft - $divWidth / 2; //selector顶点坐标 X
        Y = pageY - $imgTop - $divHeight / 2; //selector顶点坐标 Y

        X = X < 0 ? 0 : X;
        Y = Y < 0 ? 0 : Y;
        X = X + $divWidth > $imgWidth ? $imgWidth - $divWidth : X;
        Y = Y + $divHeight > $imgHeight ? $imgHeight - $divHeight : Y;

        if ($viewImgWidth == null) {
            $viewImgWidth = $("#bigView img").outerWidth();
            $viewImgHeight = $("#bigView img").height();
            if ($viewImgWidth < 200 || $viewImgHeight < 200) {
                $viewImgWidth = $viewImgHeight = 800;
            }
            $height = $divHeight * $viewImgHeight / $imgHeight;
            $("#bigView").width($divWidth * $viewImgWidth / $imgWidth);
            $("#bigView").height($height);
        }

        var scrollX = X * $viewImgWidth / $imgWidth;
        var scrollY = Y * $viewImgHeight / $imgHeight;
        $("#bigView img").css({ "left": scrollX * -1, "top": scrollY * -1 });


        //确定上边距
        //用户视窗高度
        var viewH = document.documentElement.clientHeight == 0 ? document.body.clientHeight : document.documentElement.clientHeight;
        var top = ((viewH - $height) / 2) + $(document).scrollTop();
        top = top < 360 ? 360 : top;
        var left = 530;
        if (isIE6) {
            if ($(window).width() > $(document.body).width()) {
                left = left + (($(window).width() - $(document.body).width()) / 2);
            }
        }

        $("#bigView").css({ "top": top, "left": left });


        return { left: X, top: Y };
    }

    //售罄
    var saleoutWidth = 466;
    var saleoutHeight = 208;
    if (!isLogined) {
        saleoutWidth = 451;
        saleoutHeight = 156;
    }
    $("#saleout").popwindow({ width: saleoutWidth, height: saleoutHeight, title: "售罄",
        href: WebSite + "/Product/ProductSaleOutNotify.aspx?oper=1&productCode=" + productcode + "&r=" + Math.random()
    });

    function selectedAmount_click() {
        var number = parseFloat($("#selectedAmount").val());
        re = /\d/g;
        var text = $(".cuxiaoPrice span").text().replace(/[\d|\.]+/g, function($1) { return (parseFloat($1) * number).toFixed(2) });
        $(".goodsPrice em").text(text);
    }
    $("#selectedAmount").click(selectedAmount_click);
    selectedAmount_click();

    //分享
    $("#share").popwindow({ width: 420, height: 120, title: "将这个产品分享给我的好友" });
    iniVideoTip()
    $("#video").click(function() {
        trackurl("dp-Video-track", this);
        TipClose();
        if ($(this).css("background-image").indexOf("videoBtn.gif") > -1) {
            $(this).removeClass("videoBtn").addClass("videoBtn02");
            $("span:has(#share),#imageMenu,#midimg").hide();
            var vars = "args=" + $(this).attr("name") + "|" + encodeURI($.trim($("#pricearea h2").text())) + "|yes|no|yes|0|75";
            $(this).css("");
            html = [];
            html.push("")
            var css = { "top": $(".selImg").position().top, "left": $(".selImg").position().left + 12 - ($(document).width() - $("body").width()) / 2 };
            if (!document.all) {
                css = { "top": $(".selImg").position().top - 2 };
            }
            $(html.join("")).appendTo("body").css(css);
        } else {
            back2view();
        }
        //videoBtn
        return false;
    });
    function back2view() {
        $("#video")
        .css("background-image", "url()")
        .removeClass("videoBtn02").addClass("videoBtn");
        $("span:has(#share),#imageMenu,#midimg").show();
        $("#videowindow").remove();
    }
    //成为VIP
    $(".question a").hover(function() {
        var divIframe = $("#vipiframe");
        if (divIframe.length == 0) {
            var divIframe = $("<iframe />");
            divIframe.attr("id", "vipiframe").attr("frameborder", "0").appendTo("body");
        }
        divIframe.attr("src", $(this).attr("href"))
            .css({ "width": 340, "height": 67, "top": $(this).position().top + 20, "left": 650 })
            .show();
    }, function() { $("#vipiframe").hide() }).click(function() { return false; });



    $(".question1 a").hover(function() {
        var divIframe = $("#vipiframe");
        if (divIframe.length == 0) {
            var divIframe = $("<iframe />");
            divIframe.attr("id", "vipiframe").attr("frameborder", "0").appendTo("body");
        }
        divIframe.attr("src", $(this).attr("href"))
            .css({ "width": 511, "height": 500, "top": $(this).position().top + 20, "left": 500 })
            .show();
    }, function() { $("#vipiframe").hide() }).click(function() { return false; });



    if ($("#onlickColor .colorBlock").attr("name") == "True") {
        $("#comeon").fadeIn();
    }

    //支付方式
    $(".payRight a").popwindow({ width: 550, height: 280, title: "支付方式" });

    //库存信息
    var closeCode = getCloseCode();
    if (closeCode == null) {
        $(".cityAdd").click(function() {
            alert("请选择尺码");
        });
    } else {
        //默认选择尺码
        $("#selectedSize").text("尺码：" + $.trim($(".selSize #onlickSelSize").text()));
        $(".selSizeArea h3 strong").text($.trim($(".selSize #onlickSelSize").text()));
        checkStocking();
        $(".cityAdd").hover(stockIn, stockOut);
        $(".addressWindows").hover(stockIn, stockOut);
    }
    $(".goodsAddArea").fadeIn("slow");
    if (window.localStorage) {
        var myprovince = window.localStorage["myprovince"];
        if (myprovince == null) {
            myprovince = "北京";
        }
        $("span.goodsAdd").text(myprovince);
    } else if (document.body.style.behavior != "undefined") {
        var o = document.getElementById("bigView");
        o.style.behavior = "url('#default#userData')"
        o.addBehavior("#default#userData");
        o.load("my");
        var myprovince = o.getAttribute("province");

        if (myprovince == null) {
            myprovince = "北京";
        }
        $("span.goodsAdd").text(myprovince);
    }

    $(".addressWindows a").click(function() {
        $("span.goodsAdd").text($(this).text());
        //写入
        if (window.localStorage) {
            window.localStorage["myprovince"] = $(this).text();
        } else if (document.body.style.behavior != "undefined") {
            var o = document.getElementById("bigView");
            o.setAttribute("province", $(this).text());
            o.save("my");
        }
        checkStocking();
        return false;
    });

    //图标
    $(".attricon img[title]").each(function() {
        $(this).attr("ref", $(this).attr("title")).removeAttr("title")
    })
    .hover(function(e) {
        var proudctBox = $(".proudctBox");
        if (proudctBox.length == 0) {
            html = []
            html.push("<div class=\"proudctBox\">");
            html.push("<div class=\"proudctConArea\">");
            html.push("<h2></h2>");
            html.push("<p></p>");
            html.push("<span class=\"blank5\"></span>");
            html.push("</div>");
            html.push("</div>");
            proudctBox = $(html.join(""));
            proudctBox.appendTo("body")
        }
        proudctBox.show()
        .css({ "top": e.pageY, "left": e.pageX - ($(document).width() - $("body").width()) / 2 })
        .find("p").text($(this).attr("ref"));

        proudctBox.find("h2").text($(this).attr("alt") + "功能说明：");
    }, function() {
        $(".proudctBox").hide();
    });
    //我最近看过
    if (window.localStorage && getCookie("VisitedCookies") == "") {
        var history = window.localStorage["VisitedCookies"];
        if (history == null) {
            history = [];
        } else {
            history = history.split('|||');
            //显示
        }

        var item = [productcode,
        $.trim($("#pricearea h2").text()),
        $.trim($(".cuxiaoPrice strong").text()),
        window.location.pathname,
        $("#onlickImg img").attr("src")].join("|");
        if ($.inArray(item, history) == -1) {
            history.reverse();

            history.push(item);
            history.reverse();
            history = $.grep(history, function(n, i) {
                return i < 6;
            });
            window.localStorage["VisitedCookies"] = history.join('|||');
        }
    } else {
        var history = getCookie("VisitedCookies").split(',');
        if ($.inArray(productcode, history) == -1) {
            history.reverse();
            history.push(productcode);
            history.reverse();

            history = $.grep(history, function(n, i) { return i < 6; });
            setCookie("VisitedCookies", history.join(","), 30);
        }

        if (window.localStorage) {
            delCookie("VisitedCookies");
        }
    }

    $(".RsetTabMenu li").click(function() {
        var menu = $(".RsetTabMenu li");
        menu.removeClass("hover").addClass("down");
        $(this).addClass("hover").removeClass("down");
        var index = $(this).prevAll().length;
        var tabs = $(".RsetTabCon");
        tabs.hide();
        if (tabs.eq(index).html() == "") {
            $.get($(this).find("a").attr("href"), function(data) {
                tabs.eq(index).html(data);
            }).success(function() { tabs.eq(index).show(); });
        } else {
            tabs.eq(index).show();
        }

        if (index > 0) {
            $(".RsetTabArea>.liketabfg,.RsetTabArea>.blank20,.RsetTabArea>.blank15").hide();
        } else {
            $(".RsetTabArea>.liketabfg,.RsetTabArea>.blank20,.RsetTabArea>.blank15").show();
            tabs.eq(1).show();
            tabs.eq(2).show();
        }

        return false;
    });

    //Feedback
    (function() {
    var pagesize = 10;
        if (!isLogined) {
            $('#pinglun').click(function() {
                if (confirm('此操作需要登录，您现在要登录吗？')) {
                    location.href = WebSiteHttps + '/login/login.aspx?' + location.href;
                }
                return false;
            });
        } else {
            if ($('#pinglun').attr("name") == "allow") {
                $('#pinglun').popwindow({ width: 821, height: 500, title: "评论" });
            } else {
                $("#pinglun").click(function() {
                    alert('只有购买过此商品的顾客且没有评论才可以打分和评论');
                    return false;
                });
            }
        }
        function loadstyleassesses(pageindex) {
            window.location.hash = "feedback";
            $("#styleAssesseslist").html("<div style='text-align:center'></div>");
            $.get("/styles/AjaxStyleAssesses.mvc?styleId=" + styleid + "&pageindex=" + pageindex, function(data) {
                $("#styleAssesseslist").html(data);
                $("#styleAssessesPager").pager({ pagenumber: pageindex, pagecount: Math.ceil($("#feedbackcount").text() / pagesize), buttonClickCallback: loadstyleassesses });
            });
        }

        $("#styleAssessesPager").pager({ pagenumber: 1, pagecount: Math.ceil($("#feedbackcount").text() / pagesize), buttonClickCallback: loadstyleassesses });
    })();
    //Quiz
    (function() {
        var pagesize = 5;
            $('#tiwen').popwindow(
        {
            href: 'static.asp?prodid=' + prodid,
            width: '821px',
            height: "400px",
            title: "评论"
        });

            $('.myAsk a').live('click', function() {
                $.fn.popwindow({ href: $(this).attr('href'), width: '821px', height: "470px", title: "我要回答" });
                return false;
            });
        $(".area3Con:odd").addClass("area3ConBg");
        $("#stylequestionsPager").pager({ pagenumber: 1, pagecount: Math.ceil($("#quizcount").text() / pagesize), buttonClickCallback: loadstylequestions });

        function loadstylequestions(pageindex) {
            window.location.hash = "a3";
            $("#stylequestionslist").html("<div style='text-align:center'></div>");
            $.get("/styles/AjaxStyleQuestions.mvc?styleId=" + styleid + "&pageindex=" + pageindex + "&orderType=" + $("#questionOrderType").val(), function(data) {
                $("#stylequestionslist").html(data);
                $("#stylequestionsPager").pager({ pagenumber: pageindex, pagecount: Math.ceil($("#quizcount").text() / pagesize), buttonClickCallback: loadstylequestions });
                $(".area3Con:odd").addClass("area3ConBg");
            });
        }
        $("#questionOrderType").change(function() {
            $("#stylequestionslist").html("<div style='text-align:center'></div>");
            $.get("/styles/AjaxStyleQuestions.mvc?styleId=" + styleid + "&pageindex=1&orderType=" + $("#questionOrderType").val(), function(data) {
                $("#stylequestionslist").html(data);
                $("#stylequestionsPager").pager({ pagenumber: 1, pagecount: $("#quizcount").text(), buttonClickCallback: loadstylequestions });
                $(".area3Con:odd").addClass("area3ConBg");
            });
        });

        $(".sizeList table tr:first td").each(function(i) {
            $(this).addClass("col0" + (i + 1));
        });
    })();
    //ajax显示区域
    $(window).one("scroll", function() {
        var productcode = $("#productcode").text().split("：")[1];
        $.get("/styles/ajaxload.mvc?productcode=" + productcode + "&producttype=" + producttype + "&styleid=" + styleid, function(data) {
            $(".danpinRight").append(($("#promotion", data).html()));

            if ($("#history").length == 0) {
                $(".sideBarArea").append(($("#left", data).html()));
            } else {
                $($("#left", data).html()).insertBefore("#history");
            }
        });
        //尺码计算器
        iniColorBox();
    });

    setShoppingUrl();
    //go up
    //var viewW = document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth;
    var viewH = document.documentElement.clientHeight == 0 ? document.body.clientHeight : document.documentElement.clientHeight;
    if (window.screen.width > $(document.body).width() + 100) {
        var goup = $("<div style=\"right:0px;POSITION: absolute;\"><a href=\"#\"><img src=\"images/list/top.gif\" alt=\"top\" /></a></div>").hide();
        if (!isIE6) {
            goup.css({ "position": "fixed", "bottom": 5, "right": $(window).width() / 2 - $(document.body).width() / 2 - 100 });
        } else {
            if ($(window).scrollTop() > 0) {
                goup.css({ "top": $(window).scrollTop() + viewH - 100 }).show();
            }
        }

        $(window).scroll(function() {
            if ($(window).scrollTop() == 0) {
                goup.fadeOut();
            } else {
                goup.fadeIn();
                if (isIE6) {
                    goup.css({ "top": $(window).scrollTop() + viewH - 100 });
                }
            }
        });
        $("body").prepend(goup);
    }

    //搭配翻页
    var pageCount = $("#relatedPager").find("a[name='relatedPagerHref']").length;

    if (pageCount > 0) {
        $("#relatedLeft").hide();
        $("#relatedPager").find("a[name='relatedPagerHref']").click(function() {
            var pagerID = $(this).attr("id");
            setRelatedCurent(pagerID);
            return false;
        });
        $("#relatedRight").click(function() {
            relatedPageStep(1);
            return false;
        });
        $("#relatedLeft").click(function() {
            relatedPageStep(-1);
            return false;
        });
    }

});

function relatedPageStep(step) {
    var curObj = $("#relatedPager").find("strong").parent();
    var ID = curObj.attr("id");
    var arr = ID.split("_");
    var nextNum = Number(arr[1]) + step;
    var nextID = arr[0] + "_" + nextNum;
    setRelatedCurent(nextID);
}

function setRelatedCurent(id) {

    var curObj = $("#relatedPager").find("strong");
    var s = curObj.html();
    curObj.parent().html(s);
    $("#" + id).html("<strong>" + $("#" + id).html() + "</strong>");
    $(".relatedshow").removeClass("relatedshow").addClass("relatedhide");
    var i = 0;
    var c = 5;
    var showPageStart = Number(id.split("_")[1]) * c;
    var total = Number($("#relatedTotal").html());

    if (showPageStart + c >= total)
    {
        c = total - showPageStart;
        $("#relatedRight").hide();
    }
    else
    {
        $("#relatedRight").show();
    }
    if (showPageStart == 0)
    {
        $("#relatedLeft").hide();
    }
    else
    {
        $("#relatedLeft").show();
    }
    //alert(showPageStart)
    while (i < c)
    {
        var t = showPageStart + i;
        // alert(t);
        $("#relatedImage_" + t).removeClass("relatedhide").addClass("relatedshow");
        i++;
    }
    $("html,body").animate({ scrollTop: $("#relatedsplit").offset().top }, 0);
}

function ChooseThisSize($this, SKU, maxNum) {
    if (maxNum < 10) {
        $("#comeon").fadeIn();
    } else {
        $("#comeon").fadeOut();
    }
    $(".selSize li").removeAttr("id");
    $($this).attr("id", "onlickSelSize");
    maxNum = parseInt(maxNum);
    $("#selectedSize").text("尺码：" + $.trim($($this).text()));
    $(".selSizeArea h3 strong").text($.trim($($this).text()));

    var span = $("#selectedAmount option").length - maxNum;
    if (span > 0) {
        //减少option
        $("#selectedAmount option").eq(maxNum - 1).nextAll().remove();
    } else if (span < 0) {
        //增加option
        span = Math.abs(span);
        var array = new Array(span);
        $.map(array, function(n, i) {
            var val = parseInt($("#selectedAmount option:last-child").val()) + 1;
            $("#selectedAmount").append("<option value=\"" + val + "\">" + val + "</option>");
        });
    }
    checkStocking();
    $(".cityAdd").unbind();
    $(".cityAdd").hover(stockIn, stockOut);
    $(".addressWindows").hover(stockIn, stockOut);
}



function ChooseThisSize1($this, SKU, maxNum) {
    if (maxNum < 10) {
        $("#comeon").fadeIn();
    } else {
        $("#comeon").fadeOut();
    }
    $(".selColor li").removeAttr("id");
    $($this).attr("id", "onlickSelSize");
    maxNum = parseInt(maxNum);
    $("#selectedColor").text("颜色：" + $.trim($($this).text()));

    var span = $("#selectedAmount option").length - maxNum;
    if (span > 0) {
        //减少option
        $("#selectedAmount option").eq(maxNum - 1).nextAll().remove();
    } else if (span < 0) {
        //增加option
        span = Math.abs(span);
        var array = new Array(span);
        $.map(array, function(n, i) {
            var val = parseInt($("#selectedAmount option:last-child").val()) + 1;
            $("#selectedAmount").append("<option value=\"" + val + "\">" + val + "</option>");
        });
    }
    checkStocking();
    $(".cityAdd").unbind();
    $(".cityAdd").hover(stockIn, stockOut);
    $(".addressWindows").hover(stockIn, stockOut);
}


var preUrlArr = [WebSite + '/SizeCalculate/PageRedirect.mvc?pageName=HWCompute'];
var sizeCalObj;
var preParam = {};
function iniColorBox() {
    var styleID = $("#styleinfo").attr("name");

    jQuery.get('/SizeCalculate/IniColorBox.mvc?styleID=' + styleID + "&ctrlType=ini&r=" + Math.random(),
            function(r) {
                if (r != "") {

                    //  eval("var k =" + r);
                    sizeCalObj = eval('(' + r + ')');
                    if (sizeCalObj.isHave) {

                        $("#SizeCalculate").css("display", "block");
                        $("#sizeCal_text").css("display", "block");
                        if (!sizeCalObj.tipShow) {
                            $("#sizeCal_tipClose").click(function() {
                                TipClose();
                                return false;
                            })

                            $("#sizeCal_tipBT").click(function() {
                                TipClose();
                            })

                            $("#neverShow").click(function() {
                                TipClose();
                                jQuery.getScript(WebSite + '/SizeCalculate/IniColorBox.mvc?ctrlType=setNeverShow&r=' + Math.random());
                            })
                        }
                        else {
                            TipClose();
                        }

                        if (sizeCalObj.start) {
                            $("#showSizeCalculate").attr("href", WebSite + "/SizeCalculate/PageRedirect.mvc?pageName=" + sizeCalObj.start);
                        }
                        setSizeCalculate();
                    }
                    else {
                        $("#sizeCal_link").removeClass("sizeCal_linkShow").addClass("sizeCal_linkhide");
                    }
                }

            });


}
function iniVideoTip() {
    if ($("#video")) {
        ShowTip();
    }
    else {
        TipClose();
    }
}

function ShowTip() {
    var neverShow = getCookie("SizeCal_NeverTipShow")
    if (neverShow != "true") {
        $("#video_Tip").css("display", "block");
    }
    $("#sizeCal_tipClose").click(function() {
        TipClose();
        return false;
    });

    $("#sizeCal_tipBT").click(TipClose);

    $("#neverShow").click(function() {
        TipClose();
        jQuery.getScript(WebSite + '/SizeCalculate/IniColorBox.mvc?ctrlType=setNeverShow');
    });
}
function TipClose() {
    $("#sizeCal_Tip").hide();
    $("#SizeCalculate_Tip").removeClass("sizeCal_TipShow").addClass("sizeCal_Tiphide");
    $("#sizeCal_link").removeClass("sizeCal_linkShow").addClass("sizeCal_linkhide");
    $("#video_Tip").hide();
}

function setSizeCalculate() {

    $("#showSizeCalculate").popwindow({
        width: '530px',
        height: '354px',
        noOverlayClose: true
    })
}


function setTab(name, cursel, n) {
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        menu.className = i == cursel ? "hover" : "";
        con.style.display = i == cursel ? "block" : "none";
    }
}

function addFavorite() {
    $.fn.popwindow.close();
    isLogined = true;
    setWelcome();
    var productcode = $("#productcode").text().split("：")[1];
    $.ajax({
        url: "/Shopping/AddFavorite.ashx?productcode=" + productcode,
        error: function(err) { alert(err); },
        success: function(msg) {
            if (msg == "Y") {
                $.fn.popwindow({ href: "/styles/Static.mvc?Position=AddFavoriteSuccess",
                    width: '300px', height: "120px", title: "提示", noOverlayClose: true
                });
            }
            else {
                alert("添加错误");
            }
        }
    });
}