var timeoutShowSearchType;
var timeoutleaveSearchType;
var oneX = 0;
var oneY = 0;

function setZIXUN(id, name, length) {
    setTimeout(zixun(id, name, length), 500);
}

function zixun(id, name, length) {
    $.ajax({
        type: "GET",  //提交方式
        url: "//www.gec123.com/office/api/v1/catalogs",//路径
        data: {
            "stockdir": id
        },
        success: function (data) {//返回数据根据结果进行相应的处理
            if (data[0] != null && data[0].issue_url != null) {
                $("#muencontent" + length).css("width", "70%");
                $("#muencontent" + length).css("float", "left");
                $("#zixun" + length).show();
                $("#btn_zixun" + length).attr("onclick", "_hmt.push(['_trackEvent', 'pa-drainage', 'stockdir'," + data[0].issue_url + "]);");
                $("#btn_zixun" + length).attr("href", data[0].issue_url);
                $("#btn_zixun" + length).attr("target", "_blank");
                $("#btn_zixun_title" + length).text(name);
                $("#btn_zixun" + length).attr("stockDirId", id);
            } else {
                $("#muencontent" + length).css("width", "100%");
                $("#muencontent" + length).css("float", "left");
                $("#zixun" + length).hide();
                $("#btn_zixun" + length).attr("href", "");
            }
        }
    });

}


$(function () {
    var marketid = $("#marsid").val();
    $("#enquiryWeb").show();
    var timedelay = 50;
    $("#topNavigation .nav_wrap_menu .nav_wrap").mouseenter(function (event) {
        // 是否为末级
        var isLastStage = $(this).attr('isLastStage');

        // 是否展示明细
        var isDisplay = $(this).attr('isDisplay');

        // 为空表明需要展示明细
        if (!isDisplay || isDisplay == "") {
            if ((event.clientY > oneY && event.clientX > oneX) || (event.clientY < oneY && event.clientX > oneX)) {
                timedelay = 800;
            } else {
                timedelay = 50;
            }
            if (timeoutleaveSearchType != null) {
                window.clearTimeout(timeoutleaveSearchType);
            }

            var onj = $(this);
            timeoutShowSearchType = setTimeout(function () {
                showSearchTypeT(onj);
            }, timedelay);
        } else {
            if (typeof timeoutShowSearchType !== 'undefined') {
                window.clearTimeout(timeoutShowSearchType);
            }
            if (typeof timeoutShowSearchType !== 'undefined') {
                window.clearTimeout(timeoutleaveSearchType);
            }
            $(".nav_wrap_content .nav_more").hide();
            $(".J_content_Shadow").hide();
            $(".nav_wrap_menu .nav_wrap").removeClass("div_nav_wrap_HOVER_nav_title");
            if (isLastStage == 'true') {
                $(this).addClass("div_nav_wrap_HOVER_nav_title");
            }
        }
    });
    $("#topNavigation .nav_wrap_menu .nav_second").mouseenter(function (event) {
        if (typeof timeoutShowSearchType !== 'undefined') {
            window.clearTimeout(timeoutShowSearchType);
        }
        if (typeof timeoutShowSearchType !== 'undefined') {
            window.clearTimeout(timeoutleaveSearchType);
        }
        $(".nav_wrap_content .nav_more").hide();
        $(".J_content_Shadow").hide();
        $(".nav_wrap_menu .nav_wrap").removeClass("div_nav_wrap_HOVER_nav_title");
    });

    $("#topNavigation .nav_wrap_menu .nav_title").mouseleave(function (e) {
        oneX = e.clientX;
        oneY = e.clientY;
    });
    $("#topNavigation .nav_wrap_menu .nav_wrap").mouseleave(function () {
        window.clearTimeout(timeoutShowSearchType);
    });
    $("#topNavigation .nav_list").mouseleave(function () {
        timeoutleaveSearchType = setTimeout(leavesearchTypeT, 300);
    });

    $("#topNavigation #navigation_wrap").find("li").eq(0).on("click", function () {
        window.open("//xygh.gec123.com/home.jsp", "_self");
    });
    $("#topNavigation #navigation_wrap").find("li").eq(1).on("click", function () {
        window.open("//xygh.gec123.com/trade/enquiryWeb!loadInit.action", "_self");
    });
    $("#topNavigation #navigation_wrap").find("li").eq(2).on("click", function () {
        window.open("//xygh.gec123.com/providerList.action", '_self');
    });
    $("#topNavigation #navigation_wrap").find("#propertymanserver").on("click", function () {
        window.open("//www.gec123.com/propertyman/home.jsp", '_bank');
    });
    $("#topNavigation #navigation_wrap").find("#stockserver").on("click", function () {
        window.open("//www.gec123.com/srvsubscribe/stock_toService.action", '_bank');
    });
    $("#topNavigation #navigation_wrap").find("#maintenance").on("click", function () {
        window.open("//xygh.gec123.com/ec/#!/maintenance-service", '_self');
    });
    //询价中心
    $("#topNavigation #navigation_wrap").find("#enquiryWeb").on("click", function () {
        window.open("//www.ccgp-chongqing.gov.cn/enquiry/home.action", "_bank");
    });
    //典型商品展示
    $("#topNavigation #navigation_wrap").find("#specialGodds").on("click", function () {
        window.open("//xygh.gec123.com/goods/preferentialgoods_preferentialGoodsView.action", "_self");
    });
    var selectedNumber = $("#topNavigation #navigation_wrap").attr("selectedNumber") * 1;
    if (selectedNumber >= 0) {
        $("#topNavigation #navigation_wrap").find("li").eq(selectedNumber).addClass("nav_selected");
        $("#topNavigation #navigation_wrap").find("li").eq(selectedNumber).off("click");
    }
});

function showSearchTypeT(jqobj) {
    var data_id = jqobj.attr("data-id");
    $("#topNavigation .nav_wrap_menu .nav_wrap").removeClass("div_nav_wrap_HOVER_nav_title");
    jqobj.addClass("div_nav_wrap_HOVER_nav_title");
    $("#topNavigation .nav_wrap_content .nav_more").hide();
    $("#topNavigation .nav_wrap_content .nav_more[data-id='" + data_id + "']").show();
    var obj = $("#topNavigation .nav_wrap_content .nav_more[data-id='" + data_id + "']");
    var nav_more_height = obj.outerHeight(true);
    var windowheight = eval($(window).height());
    nav_more_height = eval(nav_more_height);
    var top = 0;
    var win_top = eval(jqobj.offset().top - $(document).scrollTop());
    var par_top = eval(jqobj.position().top);
    $("#topNavigation .J_content_Shadow").attr("style", "height:" + nav_more_height + "px;width:" + obj.outerWidth(true) + "px");
    if (nav_more_height + 25 > windowheight - win_top) {
        top = par_top - (nav_more_height + 25 - (windowheight - win_top));
    } else {
        top = par_top;
    }
    if (top < 0) {
        top = 0;
    }
    $("#topNavigation .nav_wrap_content").attr("style", "top:" + top + "px");
}

function leavesearchTypeT() {
    //$("#topNavigation .nav_title b em").removeClass("nav_title_b_em");
    $("#topNavigation .nav_wrap_menu .nav_wrap").removeClass("div_nav_wrap_HOVER_nav_title");
    $("#topNavigation .nav_title").removeClass("nav_title_top_bottom");
    $("#topNavigation .nav_wrap_content .nav_more").hide();
    $("#topNavigation .J_content_Shadow").hide();

}

