var active = initial;

var timer1, timer2;
var timeout1 = 0;
var timeout2 = 500;

var menuurl = '/common/lib/menu.html';

function getSubmenuID(id) {
	switch (id) {
	case  0: return submenu; break;
	case  1: return 1; break;
	case  2: return 2; break;
	case  3: return 3; break;
	case  4: return 4; break;
	case  5: return 5; break;
	case  6: return 6; break;
	default: return 0; break;
	}
}

function setMenuActive(id) {
	clearTimeout(timer2);
	if (active > 0) document.getElementById('menu' + active).src = getMenuSrcNormal(active);
	active = id;
	if (active > 0) document.getElementById('menu' + active).src = getMenuSrcActive(active);
	if (id == initial) {
		getSubMenu(submenu);
	} else {
		getSubMenu(getSubmenuID(active));
	}
	timeout1 = 300;
}

function initMenu(obj) {
	var x = (event.clientX - obj.offsetLeft);
	var y = (event.clientY - obj.offsetTop);
	if (x <= 0 || x >= obj.offsetWidth || y <= 0 || y >= obj.offsetHeight) {
		timer2 = setTimeout('setMenuActive(initial);timeout1=0', timeout2);
	}
}

function getSubMenu(id) {
	if (xmlhttp = new XMLHTTP) {
		xmlhttp.onreadystatechange = setSubMenu;
		xmlhttp.open('GET', menuurl + menuqry + id);
		xmlhttp.send(null);
	}
}

function setSubMenu() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		document.getElementById('sub_menu_list').innerHTML = xmlhttp.responseText;
	}
}

function XMLHTTP() {
	try { return new ActiveXObject("MSXML2.XMLHTTP"); } catch(e) {
		try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {
			try { return new XMLHttpRequest() } catch(e) { return null; }
		}
	}
}

if (document.getElementById && !document.all) {
	window.addEventListener('mouseover', function(e) { window.event = e; }, true);
	window.addEventListener('mouseout' , function(e) { window.event = e; }, true);
}
