/* ---------- Common Method Congregate ---------- */
var CommonFunctions = new Object();
var ismouseover = 0;
CommonFunctions.Interval  = [];
CommonFunctions._isIE	  = window.navigator.appName == "Microsoft Internet Explorer"?true:false;
CommonFunctions._isIE6    = window.navigator.appVersion.indexOf("MSIE 6") != -1;
CommonFunctions._isIE5    = window.navigator.appVersion.indexOf("MSIE 5") != -1;
CommonFunctions._isIE4    = window.navigator.appVersion.indexOf("MSIE 4") != -1;
CommonFunctions._isIE3    = window.navigator.appVersion.indexOf("MSIE 3") != -1;
CommonFunctions._isIE7    = ((navigator.userAgent.indexOf("MSIE 7.0") != -1) && (navigator.userAgent.indexOf("Windows") != -1)); 
CommonFunctions._isOpera  = window.navigator.appName == "Opera"?true:false;

CommonFunctions.getAbsolutePoint = function(e){
	var t = e.offsetTop; 
	var l = e.offsetLeft; 
	var w = e.offsetWidth; 
	var h = e.offsetHeight; 
	while(e = e.offsetParent){ 
		t += e.offsetTop; 
		l += e.offsetLeft; 
	}
	return {"l": l, "t": t};
}

// JavaScript Document
var oSysMenus = [];

var menu_styles = {
						menu:"sysmenuBar",
						menu_frame:"sysmenuBarTable",
						iconwidth:"iconwidth",
						defaultwidth:"defaultwidth",
						textminiwidth:"textMiniWidth"
					};
					
function SysMenu(menuarr,styles){
	this.menuarr = menuarr == null ? [] : menuarr;
	this.styles = styles;
	
	var oMenu;
	var oMenu_table;
	var oMenu_tbody;
	var oMenu_tr = [];
	var oMenu_td = [];
	var oMenu_a = [];
	
	var superthis;
	
	this.createToObj = function(obj){
		oMenu = document.createElement('div');
		oMenu_table = document.createElement('table');
		oMenu_table.cellPadding = 0;
		oMenu_table.cellSpacing = 0;
		oMenu_table.border = 0;
		if(CommonFunctions._isIE) oMenu_tbody = document.createElement('tbody');

		oMenu.className = this.styles.menu;
		oMenu_table.className = this.styles.menu_frame;
		
		
		if(this.menuarr != []){
			for(var i = 0; i < this.menuarr.length; i++){
				oMenu_tr[i] = document.createElement('tr');
				oMenu_td[i] = document.createElement('td');
				oMenu_a[i] = document.createElement('a');
				
				oMenu_a[i].innerHTML = this.menuarr[i].name;
				oMenu_a[i].title = this.menuarr[i].title;
				oMenu_a[i].href = this.menuarr[i].href == "" ? "javascript:void(0)" : this.menuarr[i].href;
				oMenu_a[i].sId = i;
				oMenu_a[i].onclick =  function(){		
					if(superthis.menuarr[this.sId].onclick != null) superthis.menuarr[this.sId].onclick();	
					superthis.hide();
				}
				oMenu_td[i].appendChild(oMenu_a[i]);
				oMenu_tr[i].appendChild(oMenu_td[i]);
				if(CommonFunctions._isIE) oMenu_tbody.appendChild(oMenu_tr[i]); else oMenu_table.appendChild(oMenu_tr[i]);
				oMenu_a[i].className = this.menuarr[i].classname + " " + (this.menuarr[i].name == "" ? this.styles.iconwidth : this.styles.defaultwidth);
				if(this.menuarr[i].classname == "") oMenu_a[i].style.textIndent = 0;
			}
			
		}
		
		if(CommonFunctions._isIE) oMenu_table.appendChild(oMenu_tbody);
		oMenu.appendChild(oMenu_table);
		
		obj.appendChild(oMenu);
		
		var maxwidth = 0;
		for(var i = 0; i < this.menuarr.length; i++){
			if(oMenu_a[i].innerHTML != ""){
				for(var j = i + 1; j < this.menuarr.length - 1; j++){
					if(oMenu_a[i].offsetWidth > oMenu_a[j].offsetWidth){
						maxwidth = oMenu_a[i].offsetWidth;
					}else{
						maxwidth = oMenu_a[j].offsetWidth;
					}
				}
			}
			
		}
		if(maxwidth != 0){
			for(var i = 0; i < this.menuarr.length; i++){
				if(maxwidth < 100){
					oMenu_a[i].className = oMenu_a[i].className.split(" ")[0] + " " + this.styles.textminiwidth;
				}
			}
		}
		superthis = this;
		this.hide();
		oSysMenus.push(this);
	}
	
	this.show = function(o){
		var _self = this;
		
		for(var i = 0; i < oSysMenus.length; i++){
			if(oSysMenus[i].returnObject() != oMenu){
				oSysMenus[i].hide();
				
			}
			
		}
		
		oMenu.style.top = CommonFunctions.getAbsolutePoint(o).t + o.offsetHeight - 2 + "px";
		oMenu.style.left = CommonFunctions.getAbsolutePoint(o).l + "px";
		oMenu.style.display == "none" ? oMenu.style.display = "" : oMenu.style.display = "none";
		var interval = 0;
		clearTimeout(interval);
		
		oMenu.onmouseover = function(){
			clearTimeout(interval);
			
			
		}
		
		o.onmouseout = oMenu.onmouseout = function(){
			
			interval = setTimeout(_self.hide,100);
			
			
		}
		
	}
	this.hide = function(){
		oMenu.style.display = "none";
	}
	
	this.returnObject = function(){
		return oMenu;
	}
}
