function $(element) {
	return typeof(element) == 'object' ? element : document.getElementById(element);
}

// 菜单
var
defMenu = 0,
arrMenu = {},
menuCount = 0,
doMenu = null;
function initMenu(i){
	defMenu = i;
	arrMenu = $('navMenu').getElementsByTagName('a');
	menuCount = arrMenu.length;
	
	for(var i=0; i<menuCount; i++) {
		var subMenu = $(arrMenu[i].getAttribute('rel'));
		if(!!subMenu){
			arrMenu[i].onmouseover = function() {
				showMenu(this);
			}
			arrMenu[i].onmouseout = function() {
				doMenu = setTimeout(function() {showMenu(arrMenu[defMenu])}, 200);
			}
			subMenu.onmouseover = function() {
				clearTimeout(doMenu);
			}
			subMenu.onmouseout = function() {
				doMenu = setTimeout(function() {showMenu(arrMenu[defMenu])}, 200);
			}
		}
	}
	
	showMenu(arrMenu[defMenu]);
}

function showMenu(m) {
	clearTimeout(doMenu);
	hideMenu();
	var Menu = $(m);
	var subMenu = $(Menu.getAttribute('rel'));
	if(!!subMenu){
		subMenu.style.display = '';
	}
	Menu.className = 'sel';
}

function hideMenu() {
	for(var i=0; i<menuCount; i++) {
		var subMenu = $(arrMenu[i].getAttribute('rel'));
		if(!!subMenu){
			subMenu.style.display = 'none';
		}
		arrMenu[i].className = '';
	}
}

// 标签切换
function tabSwitch() {
	var o = this;
	o.prevID = null;
	o.Init = function() {
		var args = arguments;
		var num = args.length;
		if(num==-1) return;
		for(var i=0; i<num; i++) {
			$(args[i]).onmouseover = function() {
				o.Do(this);
			}
		}
		o.Do($(args[0]));
	}
	o.Do = function(e) {
		try{
			var id = e.id.toString().replace(/tab_/i, '');
			if (id==o.prevID) return;
			
			if(o.prevID!=null) {
				$('tab_'+ o.prevID).className = '';
				$('item_'+ o.prevID).style.display = 'none';
			}
			
			$('tab_'+ id).className = 'sel';
			$('item_'+ id).style.display = '';
			o.prevID = id;
		}catch(e){}
	}
}

