﻿function makesplit(p){p.innerHTML = '<div class="MenuSplit"></div>';}

 var img123 = new Image();img.src="Files/nEn/Images/PMenu_O.gif"

var MenuAligmnet = {TopRight:0,TopCenter:1,TopLeft:2,
					CenterRight:4,CenterCenter:5,CenterLeft:6,
					BottomRight:8,BottomCenter:9,BottomLeft:10};

function GetPosition(e){
	var curleft =0 ;var curtop = 0;
	while(e){curleft+=e.offsetLeft;curtop+=e.offsetTop;e=e.offsetParent;}
	return [curleft,curtop];
}
function GetSize(e){return [e.clientWidth,e.clientHeight];}
function CalPos(pp,ps,es,xp,yp,o){
	ox = o & 3;
	var nx = [0,0];
	var ss;
	switch(ox){
		case 0://right
			nx[0] = pp[0] + xp + ps[0];
			ss= "H : Right";
			break;
		case 1://center
			nx[0] = pp[0] + xp + ps[0] / 2;
			ss= "H : Center";
			break;
		case 2://left		
			ss= "H : Left";	
			nx[0] = pp[0] - es[0] - xp;
			break;
		default:alert('Error');
	}
	oy = o & 12;
	oy = oy >> 2;
	switch(oy){
		case 0://top
			ss += "  V : Top";
			nx[1] = pp[1] - es[1] - yp;
			break;
		case 1://center
			ss += "  V : Center";
			nx[1] = pp[1] + yp;
			break;
		case 2://bottom
			ss += "  V : Bottom";
			nx[1] = pp[1] + ps[1] + yp;
			break;
		default:alert('Error');
	}
	return nx;
}
				
function Menu_Show(e){
	if(window.navigator.appName.indexOf('Microsoft') >= 0){
		e.style.filter ="progid:DXImageTransform.Microsoft.RandomDissolve(duration=3)";
		e.filters[0].apply();
		e.style.display= '';
		e.filters[0].play();
		e.style.filter = '';
	}else e.style.display= '';
}

function Menu_Hide(e){
	if(window.navigator.appName.indexOf('Microsoft') >= 0){
		e.style.filter ="progid:DXImageTransform.Microsoft.RandomDissolve(duration=3)";
		e.filters[0].apply();
		e.style.display= 'none';
		e.filters[0].play();
		e.style.filter = '';
	}else e.style.display = 'none';
}

function addEvent(obj,evn,fn,useCapture){
	if(obj.addEventListener)obj.addEventListener(evn,fn,useCapture);
	else if(obj.attachEvent)obj.attachEvent('on'+evn,fn);
}

function MenuItem(idp, id,t,l){
    this.ParentId = idp;
    this.Id = id;
    this.Title = t;
    this.Link = l;
    this.Childs = null;
}
var MList = new Array();
function MHideAll(){
	for(var i = 0 ; i < MList.length ; i++)
		MList[i].HideAll();
}
addEvent(document,'click',MHideAll,false);
function MenuManager(pid,isV){
	MList.push(this);
    this.ParentId = pid;
    this.Items = new Array();
    this.Roots = new Array();
    this.Show = new Array();
    this.XPadding = 5;
    this.YPadding = 2;
    this.Css = "MItem_";
    this.PCss = "PItem_";
    this.Over = "_O";
    this.Select = "_S";
    this.Mode = MenuAligmnet.CenterRight;
    this.Befor = null;
    this.After = makesplit;
	this.Timer = null;
}

MenuManager.prototype = {
    _Find : function(id){
        var i, t;
        for (i = 0; i < this.Items.length; i++){
            t = this.Items[i];
            if (t.Id == id)return t;
        }
        return null;
    },
    _MakeItem : function(item){
    	var d = document.createElement('div');
    	d.innerHTML = "<a href="+item.Link+">"+item.Title+"</a>";
    	return d;
    },
    
     _MakeItem2 : function(item){
    	var d = document.createElement('div');
    	d.innerHTML = "<a href="+item.Link+">"+item.Title+"</a>";
    	return d;
    },

	_Make2 : function(mp,lst,id,l){
		var div = document.createElement("div");
		div.setAttribute("id","M_P_" + id);
		div.className = "MenuPlace_" + l;
		div.style.display = 'none';
		div.style.position= 'absolute';
		var tbl = document.createElement("table");
		tbl.cellSpacing = 0;
		tbl.cellPadding = 0;
    	tbl.Man = this;
    	tbl.onmouseover = function(){this.Man.Event(10,null);}
    	tbl.onmouseout = function(){this.Man.Event(11,null);}
		var tb = document.createElement("tbody");
		tbl.appendChild(tb);
		div.appendChild(tbl);
		var c,tr,td;
		for(var i = 0 ; i < lst.length ; i++){
			c = lst[i];
			if(this.Befor){
				tr = document.createElement("tr");
				td = document.createElement("td");
				this.Befor(td);
				tr.appendChild(td);
				tb.appendChild(tr);
			}
			tr = document.createElement("tr");
			td = document.createElement("td");
			if(c.Childs)td.className = this.PCss + l;
			else td.className = this.Css + l;
			td.appendChild(this._MakeItem(c));
		   	td.onclick = function(e){this.Man.Event(3,this.ManItem,e);}
	    	td.Man = this;
		   	td.ManItem = c;
	    	td.onmouseover = function(){this.Man.Event(1,this.ManItem);}
	    	td.onmouseout = function(){this.Man.Event(2,this.ManItem);}
	    	td.setAttribute("id","M_I_" + c.Id);
			tr.appendChild(td);
			tb.appendChild(tr);			
			if(this.After){
				tr = document.createElement("tr");
				td = document.createElement("td");
				this.After(td);
				tr.appendChild(td);
				tb.appendChild(tr);
			}
			if(c.Childs)
				this._Make2(mp,c.Childs,c.Id, l + 1);
		}
		mp.appendChild(div);
	},
	
	_Make : function(lst,parent,l){
		var tbl = document.createElement("table");
		tbl.cellSpacing = 0;
		tbl.cellPadding = 0;
		tbl.style.width = '100%';
    	tbl.Man = this;
    	tbl.onmouseover = function(){this.Man.Event(10,null);}
    	tbl.onmouseout = function(){this.Man.Event(11,null);}
		var tb = document.createElement("tbody");
		tbl.appendChild(tb);
		var c,tr,td;
		for(var i = 0 ; i < lst.length ; i++){
			c = lst[i];
			if(this.Befor){
				tr = document.createElement("tr");
				td = document.createElement("td");
				this.Befor(td);
				tr.appendChild(td);
				tb.appendChild(tr);
			}
			tr = document.createElement("tr");
			td = document.createElement("td");
			td.appendChild(this._MakeItem(c));
			if(c.Childs)td.className = this.PCss + l;
			else td.className = this.Css + l;
		   	td.onclick = function(e){this.Man.Event(3,this.ManItem,e);}
	    	td.Man = this;
		   	td.ManItem = c;
	    	td.onmouseover = function(e){this.Man.Event(1,this.ManItem,e);}
	    	td.onmouseout = function(e){this.Man.Event(2,this.ManItem,e);}
	    	td.setAttribute("id","M_I_" + c.Id);
			tr.appendChild(td);
			tb.appendChild(tr);			
			if(this.After){
				tr = document.createElement("tr");
				td = document.createElement("td");
				this.After(td);
				tr.appendChild(td);
				tb.appendChild(tr);
			}
			if(c.Childs)
				this._Make2(parent,c.Childs,c.Id, l + 1);
		}
		parent.appendChild(tbl);
	},
	
	FindS : function(d){
		for(var i = 0 ; i < this.Show.length ; i++)
			if(this.Show[i] == d)return true;
		return false;
	},
	
	_SetCss : function(e,t){
		if(!e.OrgCss)e.OrgCss=e.className;		
		switch(t){
			case 1 : //Normal
				e.className = e.OrgCss;
				break;
			case 2 : //Over
				e.OrgClassN = e.className;
				e.className = e.OrgCss+this.Over;
				break;
			case 3 : //Out
				e.className = e.OrgClassN;
				e.OrgClassN = '';
				break;
			case 4 : //Selected
				e.className = e.OrgCss+this.Select;
				break;
		}
	},
	_HideUntil : function(ParentId){
		while(this.Show.length > 0){
			var tmp = this.Show.pop();
			if(tmp == ParentId){this.Show.push(tmp);break;}
			var tmpE = document.getElementById("M_P_" + tmp);
			Menu_Hide(tmpE);
			tmpE = document.getElementById("M_I_" + tmp);
			this._SetCss(tmpE,1);
		}
	},
	
	Event : function(eid,item,e){	
		if(eid >=10){
			if(eid == 10){
				clearTimeout(this.Timer);
				this.Timer = null;
			}else if(eid == 11){
				if(this.Timer!=null)clearTimeout(this.Timer);
				this.Timer = setTimeout("MHideAll();",500)
			}
		}else{
			var ItemE = document.getElementById("M_I_" + item.Id);
			if(eid == 1){ // Over
				this._HideUntil(item.ParentId);
				if(item.Childs){				
					this._SetCss(ItemE,4);
					this.Show.push(item.Id);
					var chilsE = document.getElementById("M_P_" + item.Id);
					var p = CalPos(GetPosition(ItemE),GetSize(ItemE),GetSize(chilsE),this.XPadding,this.YPadding,this.Mode);
					chilsE.style.left = p[0]+'px';
					chilsE.style.top = p[1]+'px';
					Menu_Show(chilsE);
				}else this._SetCss(ItemE,2);
			}else if(eid == 2){//Out
				if(!item.Childs)
					this._SetCss(ItemE,3);
			}else if(eid == 3){//Click
				if(item!=null)window.location = item.Link;
				this.HideAll();
			}
		}
	},
	
	HideAll : function(){
		this._HideUntil(0);		
	},
	
	addItem : function(item){
        this.Items.push(item);
        var cc;
        if (item.ParentId == this.ParentId)this.Roots.push(item);
        else if ((cc = this._Find(item.ParentId)) != null){
            if (cc.Childs == null)cc.Childs = new Array();
            cc.Childs.push(item);
        }
    },
    
    Make : function(pname){
    	var p = document.getElementById(pname);
    	if(p)this._Make(this.Roots,p,1);
    	p.Man = this;
    	p.onmouseover = function(){this.Man.Event(10,null);}
    	p.onmouseout = function(){this.Man.Event(11,null);}
    }
};

<!-- 





