var loadFun = [];
function setFrame() {
	var _width = document.documentElement.clientWidth;
	var _heigh = document.documentElement.clientHeight;
	var mfm = document.getElementById("main");
	if (_width < 900) {
		mfm.style.left = "0px";
	} else {
		mfm.style.left = _width / 2 - 450 + "px";
	}
	var mct=document.getElementById('mainContent');
	var mctl=document.getElementById('mainContentLeft');
	var mctr=document.getElementById('mainContentRight');
	if(mct&&mctl&&mctr) mct.style.height=Math.max(mctl.clientHeight,mctr.clientHeight)+20+'px';
}
loadFun.push(setFrame);

function initMainmenu() {
	var menubar = document.getElementById("mainMenubar");
	for (i in mm) {
		var menu = document.getElementById(i);
		if (!menu) {
			menu = document.createElement("div");
			menu.id = i;
			menu.className="mainMenu";
		}
		menu.innerHTML = mm[i].text + "";
		menu.onmousemove = displayList;
		menu.onmouseout = hideList;
		menubar.appendChild(menu);
	}
}

function displayList(evt) {
	var oid=this.id.split("_fall")[0];
	var m=document.getElementById(oid);
	var fall_menu_items = mm[oid].fall;
	if(typeof fall_menu_items=="string"){
		m.onclick = menuClick;
		m.onmouseout = hideList;
	}
	else{
		var fall_id = oid + "_fall";
		var fall_menu = document.getElementById(fall_id);
		if (!fall_menu) {
			fall_menu = document.createElement("div");
			fall_menu.className = "fallMenu";
			fall_menu.id = fall_id;
			for (l in fall_menu_items) {
				var item = document.createElement("div");
				item.id=fall_menu_items[l];
				item.innerHTML = l;
				item.onclick=fallMenuClick;
				fall_menu.appendChild(item);
			}
			fall_menu.onmousemove = displayList;
			fall_menu.onmouseout = hideList;
			document.body.appendChild(fall_menu);
		}
		fall_menu.style.left=getX(m)+"px";
		fall_menu.style.top=(getY(m)+m.clientHeight)+"px";//without border!!
		fall_menu.style.display = "block";
	}
	m.className="mainMenuHover";	
}

function hideList(evt) {
	var oid=this.id.split("_fall")[0];
	var menu=document.getElementById(oid);
	var fall_id = oid + "_fall";
	var fall_menu = document.getElementById(fall_id);
	if (fall_menu) {
		fall_menu.style.display = "none";
	}
	menu.className="mainMenu";
}

function fallMenuClick(evt){
	
	if(this.id.indexOf("http://") != -1){
	window.location = this.id;
}
else{
	window.location = basePath + this.id;}
}

function menuClick(evt){
	if(mm[this.id].fall.indexOf("http://") != -1){
	window.location = mm[this.id].fall;
}
else{
	window.location = basePath + mm[this.id].fall;}
}
loadFun.push(initMainmenu);

window.onload = function () {
	for (var i = 0; i < loadFun.length; i++) {
		loadFun[i]();
	}
	window.onresize = setFrame;
	
	setBasePath();
};
var basePath;
function setBasePath(){
	var path = window.location.pathname;
        
	path = path.substr(1);
	
	path = path.substring(0, path.indexOf("/"));
	//basePath = window.location.protocol+ '//'+ window.location.host + '/' + path + '/';
	basePath = window.location.protocol+ '//'+ window.location.host + '/';
        
}


