﻿$(function() {
    $.each(menuheader, function(i, m) {

        var strchildheader = "";
        $("#menuUlList").append("<li class='sub' id='" + m.menuid + "li'><a href='" + decodeURIComponent(m.menuurl) + "' target='_parent' >" + unescape(m.menuname) + "</a></li>");
        // alert(unescape(m.menuname));
        if (m.childmenu.length > 0) {
            strchildheader = "";
            strchildheader += "<ul class='menuSubUl' id='" + m.menuid + "liUl'>";
            $.each(m.childmenu, function(k, mm) {
                strchildheader += "<li id='" + mm.menuid + "childli'><a target='_parent' href='" + decodeURIComponent(mm.menuurl) + "' class='menu_12'>" + unescape(mm.menuname) + "</a></li>";
            });
            strchildheader += "</ul>";
            $("#childMenuDiv").append(strchildheader);
        }
    });
});
var menutimeout;
$(function() {//currentHeaderLi
    $("#mian_menudiv>ul").children("li").hover(
               function() {
                   var $this = $(this);
                   var ulid = $(this).attr("id") + "Ul";
                   var $obj = $("#" + ulid);
                   $(".currentHeaderLi").removeClass("currentHeaderLi");
                   $this.addClass("currentHeaderLi");
                   $("ul.menuSubUl").filter(":not(#" + ulid + ")").slideUp("fast");
                   if ($obj.length > 0) {
                       if ($obj.css("top") == "auto" || (!window.event && $obj.css("top") == "0px")) {
                           var position = getPosition(this);
                           $obj.css("top", (parseInt(position[1]) + parseInt(position[5]) + 1)).css("left", (parseInt(position[0]))).css("width", (parseInt(position[4]) - 2));
                           $obj.stop(true, true).slideDown("fast");
                           $obj.hover(
                           function() {
                               if (menutimeout) {
                                   clearTimeout(menutimeout);
                               }
                               var $this2 = $(this);
                               if ($this2.is(":animated")) {
                                   $this2.stop(true, true);
                               }
                               $this2.css("display", "block");
                           },
                           function() {
                               if (menutimeout)
                                   clearTimeout(menutimeout);
                               var $obj = $(this);
                               menutimeout = setTimeout(function() {
                                   if ($obj.length > 0) {
                                       $obj.stop(true, true).slideUp("fast");
                                   }
                               }, 30);
                           }
                           );
                       }
                       else {
                           $obj.stop(true, true).slideDown("fast");
                       }
                   }
               }, function() {
                   if (menutimeout)
                       clearTimeout(menutimeout);

                   var $this = $(this);
                   var ulid = $(this).attr("id") + "Ul";
                   var $obj = $("#" + ulid);

                   menutimeout = setTimeout(function() {
                       if ($obj.length > 0) {
                           $obj.stop(true, true).slideUp("fast");
                       }
                   }, 30);
               });
});

$(function() {
    var url = document.URL;
    var rule = new RegExp("[A-Z0-9a-z]{8}(-[A-Z0-9a-z]{4}){3}-[A-Z0-9a-z]{12}");
    var id = "";
    var idarr = url.match(rule);
    if (idarr && idarr.length > 0) {
        id = idarr[0];
        var $obj = $("#" + id + "childli");

        if ($obj.length > 0) {
            var parentid = $obj.parent("ul").attr("id");
            if (parentid && parentid.length > 0) {
                parentid = parentid.match(rule);
                if (parentid && parentid.length > 0) {
                    $obj = $("#" + parentid[0] + "li");
                    $obj.addClass("currentHeaderLi");
                }
            }
        }
        else {
            $obj = $("#" + id + "li");
            if ($obj.length > 0) {
                $obj.addClass("currentHeaderLi");
            }
        }
    }
    else {
        if (url.indexOf(".aspx") == -1) {
            $obj = $($("#menuUlList>li")[0]);
            if ($obj.length > 0) {
                $obj.addClass("currentHeaderLi");
            }
        }
        else {
            if (url.indexOf("Default.aspx") == -1) {
                $obj = $("li:contains('旗下公司')");
                if ($obj.length > 0) {
                    $obj.addClass("currentHeaderLi");
                }
            }
            else if (url.indexOf("type=1") != -1 || url.indexOf("type=2") != -1) {
                $obj = $("li:contains('集团动态')");
                if ($obj.length > 0) {
                    $obj.addClass("currentHeaderLi");
                }
            }
            else {
                $obj = $($("#menuUlList>li")[0]);
                if ($obj.length > 0) {
                    $obj.addClass("currentHeaderLi");
                }
            }
        }
    }
});