// JavaScript Document
function $(id){
	return document.getElementById(id);
}
var QQMenu = {
    showMenuSpeed: 30, //二级MENU收放速度
    showMenuAlphaSpeed: 10, //2级MENU 透明度的变化速度 暂不支持
    isFocus: -1,
    focusIndex: -1,
    mRollOverEvent: function(o) {
        window.status = o.i + ":" + this.focusIndex;
        if (o.i == this.focusIndex)
            return;
        o.className = "firstmenushow";
    },
    mRollOutEvent: function(o) {
        if (o.i == this.focusIndex)
            return;
        o.className = "firstmenu";
    },
    showMenu: function(o) {
        o.style.display = "";
        //var maxLength = o.childNodes.length*this.secondmenuHeight;
        var maxLength = o.scrollHeight;
        //alert(o.id+":"+o.scrollHeight);
        if (o.childNodes.length > 0) {
            if (parseInt(o.style.height) < maxLength) {
                var oheight = parseInt(o.style.height) + o.childNodes.length + this.showMenuSpeed;
                oheight = oheight > maxLength ? maxLength : oheight;
                o.style.height = oheight + "px";
                //o.filters.alpha.opacity +=showMenuAlphaSpeed;
                var nextO = o;
                clearTimeout(o.timeA);
                o.timeA = setTimeout(function() { QQMenu.showMenu(nextO) }, '10');
            } else {
                o.style.height = maxLength;
                clearTimeout(o.timeA);
                o.timeA = null;
                //o.filters.alpha.opacity =100;				
            }
        }
        else o.style.display = "none";
    },
    hideMenu: function(o, o2) {
        if (parseInt(o.style.height) > 1) {
            var oheight = parseInt(o.style.height) - o.childNodes.length - this.showMenuSpeed;
            oheight = oheight < 0 ? 1 : oheight;
            o.style.height = oheight + "px";
            //o.filters.alpha.opacity -=showMenuAlphaSpeed;
            var nextO = o;
            var nextO2 = o2;
            clearTimeout(o.timeA);
            QQMenu.timeA = setTimeout(function() { QQMenu.hideMenu(nextO, nextO2) }, '10');
        } else {
            o.style.height = "1px";
            o.style.display = "none";
            //o.filters.alpha.opacity =0
            clearTimeout(o.timeA);
            o.timeA = null;
            if (o2) {
                clearTimeout(QQMenu.timeA);
                QQMenu.timeA = null;
                QQMenu.showMenu(o2);
            }
        }
    },
    init: function(menu, menuTag, showName) {
        var menuHTML = "";
        for (var i in menu) {
            var _name = menu[i]["parentmenu"];
            if (showName == _name) {
                this.isFocus = i;
            }

            menuHTML += '<div id="click' + menuTag + i + '" class="' + (this.isFocus == i ? 'firstmenushow' : 'firstmenu') + '" ' + (this.isFocus != i ? 'onmouseover=\'QQMenu.mRollOverEvent(this)\' onmouseout=\'QQMenu.mRollOutEvent(this)\'' : '') + '><a  class="firstmenuLink" hidefocus=true ' + (!menu[i]["href"] ? '' : ('href="javascript:activeContainerContent(\'' + menu[i]["href"] + '\',\'' + menu[i]["target"] + '\');"')) + '>' + menu[i]["parentmenu"] + '</a></div>';
                menuHTML += '<div id="show' + menuTag + i + '" class="childmenuDIV">';
                for (var j in menu[i]["childmenu"]) {
                    if (menu[i]["childmenu"][0]["name"].length > 0) {
                        menuHTML += '<div class="secondmenu" onmouseover="this.className=\'secondmenu_hover\'" onmouseout="this.className=\'secondmenu\'" onclick="javascript:activeContainerContent(\'' + menu[i]["childmenu"][j]["href"] + '\',\'' + menu[i]["childmenu"][j]["target"] + '\');">' + menu[i]["childmenu"][j]["name"] + '</div>';
                    }
                }
                menuHTML += '</div>';
            
        }
        $(menuTag).innerHTML = menuHTML;
        var btCount = menu.length;
        for (var i = 0; i < btCount; i++) {
            e = $("click" + menuTag + i);
            f = $("show" + menuTag + i);
            //e.className="firstmenu";
            e.f = f;
            f.style.height = "1px";
            f.style.overflow = "hidden";
            f.style.display = "none";
            //f.style.filter="alpha(Opacity=0)";
            e.i = i;
            e.onclick = function() {
                if (parseInt(this.f.style.height) < 5) {
                    var show = true;
                    for (var j = 0; j < btCount; j++) {
                        if (j != this.i) {
                            if ($("show" + menuTag + j).offsetHeight > 5) {
                                QQMenu.hideMenu($("show" + menuTag + j), $("show" + menuTag + this.i))
                                show = false;
                                if (QQMenu.isFocus != j) {
                                    $("click" + menuTag + j).className = "firstmenu";
                                }
                                if (this.nextSibling.childNodes.length > 0) { QQMenu.focusIndex = this.i; $("click" + menuTag + this.i).className = "firstmenushow"; }
                            }
                        }
                    }
                    if (show) {
                        QQMenu.showMenu(this.f);
                        if (this.nextSibling.childNodes.length > 0) {
                            //QQMenu.focusIndex = this.i;
                            this.className = "firstmenushow";
                        }
                    }
                } else {
                    QQMenu.hideMenu(this.f);
                    this.className = "firstmenu";
                }
            };
        }
        if (showName) for (var i = 0; i < menu.length; i++) if (menu[i].parentmenu == showName) { $("click" + menuTag + i).onclick(); break };
    }
}


var menu = new Array;
var childmenu = new Array;

function parentmenuObj(parentmenu, childmenuObj, href, target) {
	this.parentmenu=parentmenu;
	this.childmenu=childmenuObj;
	this.href=href;
	this.target=target;
	childmenu=new Array;
}
function childmenuObj(name,href,target) {
	this.name=name;
	this.href=href;
	this.target=target;
}
