﻿/*===================================================
菜单
===================================================*/

var MenuOption = new Array();   //每个菜单的子菜单数
var _MenuHeight = new Array();   //每个菜单的子菜单总高度
var LowerMenuHeight = new Array();  //子菜单的总高度
var HiddenMenuOption = new Array(); //隐藏菜单时的句柄
var IntervalTime = 1;   //速度
/*===================================================
创建菜单类
===================================================*/
function Menu()
{
}
/*===================================================
创建菜单类的属性和方法
===================================================*/
Menu.prototype = 
{
    /*==============================================
    创建菜单类的属性
    ==============================================*/
    Name : "",  //菜单名称,每个菜单名称用|分隔,如:公司简介|公司动态
    NameArray : new Array(),    //菜单名称数组
    Series : 0, //菜单项数
    Url : "",   //菜单链接地址,每个菜单链接地址用|分隔,如:info.aspx|list.aspx
    UrlArray : new Array(), //菜单链接地址数组
    Target : "",   //打开方式,默认为当前页面
    TargetArray : new Array(),  //打开方式数组
    ID : "",    //菜单的ID
    Color : "#000000",  //菜单字体的颜色,默认为黑色
    BgColor : "#FFFFFF",    //菜单的背景颜色,默认为白色
    Class : "", //菜单的Class属性
    FontStyle : "宋体", //菜单的字体样式,默认为宋体
    FontSize : "12px",  //菜单的字体大小,默认为12像素
    BackGround : "",    //背景图片
    Width : "", //菜单的宽度
    WidthArray : new Array(),   //菜单的宽度数组
    Top : "0",    //菜单的上边距
    Bottom : "0", //菜单的下边距
    Height : "",    //菜单的高度
    HeightArray : new Array(),  //菜单的高度数组
    Rapidity : 1,   //速度
    /*==============================================
    创建菜单类的方法
    ==============================================*/
    GetName : function()    //获取每个菜单名称
    {
        this.NameArray = this.Name.split("|");
    },
    GetNameSeries : function()  //获取菜单项数
    {
        this.GetName();
        this.Series = this.NameArray.length - 1;
    },
    GetUrl : function() //获取每个菜单链接地址的名称
    {
        var UrlSeries = 0;
        var i = 0;
        this.UrlArray = this.Url.split("|");
        UrlSeries = this.UrlArray.length;
        for (i = UrlSeries;i < this.Series;i ++)
            this.UrlArray[i] = "#";
        
    },
    GetTarget : function()  //获取每个菜单的打开方式
    {
        var TargetSeries = 0;
        var i = 0;
        this.TargetArray = this.Target.split("|");
        TargetSeries = this.TargetArray.length;
        for (i = TargetSeries;i < this.Series;i ++)
            this.TargetArray[i] = "_self";
    },
    GetWidth : function()   //获取每个菜单的宽度
    {
        var WidthSeries = 0;
        var i= 0;
        this.WidthArray = this.Width.split("|");
        WidthSeries = this.WidthArray.length
        for (i = WidthSeries;i < this.Series;i ++)
            this.WidthArray[i] = "100%";
    },
    GetHeight : function()  //获取每个菜单的高度
    {
        var HeightSeries = 0;
        var i =0;
        this.HeightArray = this.Height.split("|");
        HeightSeries = this.HeightArray.length;
        for (i = HeightSeries;i< this.Series;i ++)
            this.HeightArray[i] = "100%";
    },
    MainMenu : function()   //主菜单
    {
        var MenuHtml = "";
        var i = 0;
        this.GetNameSeries();
        this.GetUrl();
        this.GetTarget();
        this.GetWidth();
        for (i;i < this.Series;i++)
        {
            MenuHtml += "<td id=\"Menu" + i.toString() + "\" background = \"" + this.BackGround + "\" align=\"center\" style=\"width:" + this.WidthArray[i] + "px;\" onmouseover=\"ShowMenu('" + i + "');\" onmouseout = \"HiddenMenu('" + i + "');\" >";
            MenuHtml += "<a href = \"" + this.UrlArray[i] + "\" target=\"" + this.TargetArray[i] + "\" class=\"" + this.Class + "\" >" + this.NameArray[i] + "</a>";
            MenuHtml += "</td>";
        }
        document.write(MenuHtml);
    },
    LowerMenu : function(j) //子菜单
    {
        var MenuHtml = "";
        var i = 0;
        this.GetNameSeries();
        this.GetUrl();
        this.GetTarget();
        this.GetHeight();
        IntervalTime = this.Rapidity;
        MenuHtml += "<div id=\"LowerMenu" + j.toString() + "\" style=\"display:none;z-index:99;height:1px;position:absolute;width:100%;background-color:#F1f5f9;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80);padding-top:" + this.Top + ";padding-bottom:" + this.Bottom + ";overflow:hidden;\" onmouseover=\"KeepMenu('" + j.toString() + "');\" onmouseout=\"HiddenMenu('" + j.toString() + "');\">";
        MenuHtml += "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">";
        _MenuHeight[j] = 0;
        if (parseInt(this.Top) == this.Top)
            _MenuHeight[j] += parseInt(this.Top);
        if (parseInt(this.Bottom) == this.Bottom)
            _MenuHeight[j] += parseInt(this.Bottom);
        for (i;i < this.Series;i++)
        {
            MenuHtml += "<tr>";
            MenuHtml += "<td nowrap style=\"height:" + this.HeightArray[i] + "px;text-align:center;vertical-align: middle; padding-top:5px;\" >";
            MenuHtml += "<div style=\"width:100%;\">";
            MenuHtml += "<a href = \"" + this.UrlArray[i] + "\" target=\"" + this.TargetArray[i] + "\" class=\"" + this.Class + "\" >" + this.NameArray[i] + "</a>";
            MenuHtml += "</div>";
            MenuHtml += "</td>";
            MenuHtml += "</tr>";
            if (parseInt(this.HeightArray[i]) == this.HeightArray[i])
                _MenuHeight[j] += parseInt(this.HeightArray[i]) + 5;
        }
        MenuHtml += "</table>";
        MenuHtml += "</div>";
        LowerMenuHeight[j] = 0;
        document.write(MenuHtml);
    }
}
/*======================================================
显示菜单
======================================================*/
function ShowMenu(i)
{
    var objID = "LowerMenu" + i;
    var obj = document.getElementById(objID);
    
    if (obj != undefined)
    {
        if (window.event.srcElement.tagName == "TD")
        {
            obj.style.left = window.event.srcElement.offsetLeft + window.event.srcElement.offsetParent.offsetLeft;
            obj.style.width = window.event.srcElement.offsetWidth;
        }
        DragShow(i,objID);
    }
}
/*=====================================================
隐藏菜单
=====================================================*/
function HiddenMenu(i) //隐藏菜单
{
    var objID = "LowerMenu" + i;
    var obj = document.getElementById(objID);
    DragHidden(i,objID);
}
/*===================================================
保持菜单状态
===================================================*/
function KeepMenu(j)
{
    var objID = "LowerMenu" + j;
    var obj = document.getElementById(objID);
    
   obj.style.display = "";
   DragShow(j,objID);
}
/*===================================================
慢慢地显示菜单
===================================================*/
function DragShow(i,objID)
{
    window.clearInterval(HiddenMenuOption[i]);
    MenuOption[i] = window.setInterval("DragShowMenu('" + i + "','" + objID + "')",IntervalTime);
}
/*==================================================
慢慢显示菜单
==================================================*/
function DragShowMenu(i,objID)
{
    var obj = document.getElementById(objID);
    
    if (LowerMenuHeight[i] < _MenuHeight[i])
    {
        LowerMenuHeight[i] += 8;
        obj.style.height = LowerMenuHeight[i] + "px";
    }
    else
        window.clearInterval(MenuOption[i]);   
    obj.style.display = "";
}
/*================================================
慢慢地隐藏菜单
================================================*/
function DragHidden(i,objID)
{
    window.clearInterval(MenuOption[i]);
    HiddenMenuOption[i] = window.setInterval("DragHiddenMenu('" + i + "','" + objID + "')",IntervalTime);
    
}
/*===============================================
慢慢隐藏菜单
===============================================*/
function DragHiddenMenu(i,objID)
{
    var obj = document.getElementById(objID);
   
    if (LowerMenuHeight[i] > 0)
    {
        obj.style.height = LowerMenuHeight[i] + "px";
        LowerMenuHeight[i] -= 8;
    }
    else
    {
        window.clearInterval(HiddenMenuOption[i]);
        obj.style.display = "none";
    }
}
