﻿$(document).ready(PageLoad);

function PageLoad() {
    //触发搜索框输入事件
    $("#top-keywords").focus(
        function() {
            var A = $(this);
            if (A.val() == "搜索...") {
                A.val("");
            }
        }
    );
    $("#top-keywords").blur(
        function() {
            var A = $(this);
            if (A.val() == "") {
                A.val("搜索...");
            }
        }
    );


    //触发页面所有分类推拉事件
    $(".drawer-fur").click(
        function() {
            var A = $(this);
            var B = A.attr("id").substring(A.attr("id").lastIndexOf("-") + 1);
            var C = B.substring(0, B.indexOf("_"));

            //如果该面板是显示的，则关闭该面板，并返回
            if ($("#drawer-content-" + B).css("display") == "block") {
                $("#drawer-content-" + B).slideUp("slow");
                return;
            }

            //隐藏该box下所有显示的面板
            var D = A.parent().attr("id");

            $("#" + D + " > ul:visible").each(
                function() {
                    var E = $(this);
                    E.slideUp("slow");
                }
            );

            //显示应该显示的
            $("#drawer-content-" + B).slideDown("slow");
        }
    );

    //触发页面菜单变换事件
    $(".menu-pri span").mouseover(
        function() {
            var A = $(this);
            var B = A.attr("id").substring(A.attr("id").lastIndexOf("-") + 1);
            var C = B.substring(0, B.indexOf("_"));

            //如果该面板是显示的，则返回
            if ($("#menu-se-" + B).css("display") == "block") {
                return;
            }

            //隐藏该box下所有显示的面板
            var D = $("#menu-se-" + B);
            var E = D.parent().attr("id");

            $("#" + E + " > .menu-second:visible").each(
                function() {
                    var F = $(this);
                    F.css("display", "none");
                }
            );

            //显示应该显示的
            $("#menu-se-" + B).show();

            //定位新的索引
            A.addClass("current1");
        }
    );

    $(".menu-pri span").mouseout(
        function() {
            var A = $(this);
            var B = A.attr("id").substring(A.attr("id").lastIndexOf("-") + 1);

            if (B == CurPrimaryMenuId) {
                return;
            }
            else {
                //隐藏该下拉菜单
                //$("#menu-se-" + B).css("display","none");
                A.removeClass("current1");
                //显示应该显示的
                //$("#menu-se-" + CurPrimaryMenuId).show();
            }
        }
    );


    //触发页面畅销榜切换事件
    $("#cxb .top-seq div").mouseover(
        function() {
            var A = $(this);
            var B = A.attr("class");
            if (B.lastIndexOf("-") != -1) {
                B = B.substring(0, B.lastIndexOf("-"));
            }

            //如果该面板是显示的，则返回
            if ($("#" + B + "-top").css("display") == "block") {
                return;
            }

            //隐藏该box下所有显示的面板
            var D = A.parent().parent().parent().parent().attr("id");

            $("#" + D + " > .box-body > .topbox:visible").each(
                function() {
                    var E = $(this);
                    E.css("display", "none");
                }
            );

            //显示应该显示的
            $("#" + B + "-top").show();
        }
    );

    //触发电视机切换事件
    //触发电视机切换事件
    $(".tv-banner-seq span").mouseover(
        function() {
            var A = $(this);
            var B = A.attr("id").substring(A.attr("id").lastIndexOf("-") + 1);
            var C = B.substring(B.indexOf("_") + 1, B.length);

            changerIndex = parseInt(C);

            //如果该面板是显示的，则返回
            if ($("#changer-body-" + B).css("display") == "block") {
                return;
            }

            //隐藏该box下所有显示的面板
            var D = A.parent().parent().attr("id");

            $("#" + D + " > .changer-body:visible").each(
                function() {
                    var E = $(this);
                    E.css("display", "none");
                }
            );

            $("#" + D + " > .tv-banner-seq > span").each(
                function() {
                    var F = $(this);
                    F.removeClass("current1");
                }
            );

            //显示应该显示的
            $("#changer-body-" + B).fadeIn("fast");

            //定位新的索引
            A.addClass("current1");
        }
    );

    //目录专区弹出框
    $(".special-menu-3 .drop").click(
        function() {
            var A = $(this);
            var B = A.attr("id");

            //显示下拉筐
            $("#" + B + " > .pop-up").each(
                function() {
                    var E = $(this);
                    //alert(E.css("display"));
                    if (E.css("display") == "none") {
                        E.slideDown("fast");
                    }
                    else {
                        E.slideUp("fast");
                    }
                }
            );
        }
    );

    $(".popup").mouseover(
        function() {
            var A = $(this).attr("id");
            var B = $("#" + A + "-content");
            B.css("left", A.offsetLeft);
            B.show();
        }
    );

    var droperTimer;

    $(".popup").mouseout(
        function() {
            var A = $(this).attr("id");

            droperTimer = setTimeout(
            function() {
                var B = $("#" + A + "-content");
                B.hide();
            }
            , 200);
        }
    );

    $(".popup-content").mouseover(
        function() {
            if (droperTimer) clearTimeout(droperTimer);
            $(this).show();
        }
    );

    $(".popup-content").mouseout(
        function() {
            var A = $(this);
            A.hide();
        }
    );
}

