$(document).ready(function(){
navList();
tabNav("tabId",0);
});

function navList(){
	var navItem = document.getElementById("nav").getElementsByTagName("li");
	for(var i=0;i<navItem.length;i++){
		if(navItem[i].className == "parentNav"){
			navItem[i].onmouseover = function(){showSubNav(this)};
			navItem[i].onmouseout = function(){hideSubNav(this)};
		}
	}
}
function showSubNav(li){li.getElementsByTagName("ul")[0].style.display = "block";li.getElementsByTagName("ul")[0].getElementsByTagName("li")[0].style.borderTop = "8px solid #000";}
function hideSubNav(li){li.getElementsByTagName("ul")[0].style.display = "none";}

/*-----------------------------------------------------------*/

function $(){
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string'){
			if(document.getElementById(element)){
				element = document.getElementById(element);}
			else{
				element = document.getElementsByName(element);
			}
			if (arguments.length == 1){
				return element;
			}
		}
		elements.push(element);
	}
	return elements;
 };


/*function iniMenu(tabObj,selNum){
       var collection = $(tabObj).getElementsByTagName("LI");
       var selObj = collection[selNum];
       selObj.className = 'focus';
       $(tabObj+"_Content"+selNum).style.display = "block";
       for(var i = 0; i < collection.length; i++){
              collection[i].onmousedown = function(){
                     if(this != selObj){
                            selObj.className = '';
                            this.className = 'focus';
                            $(tabObj+"_Content"+getObjNum(this)).style.display = "block";
                            $(tabObj+"_Content"+getObjNum(selObj)).style.display = "none";
                            selObj = this;
                     }
              };
       }
}
function getObjNum(thisObj){
       var selObj = thisObj.parentNode;
       for(var i=0;i<selObj.childNodes.length;i++){
              if (thisObj == selObj.childNodes[i]){return i;}
       }
}*/

function tabNav(navObj,d){
	if(document.getElementById(navObj)){
		var tabli = $(navObj).getElementsByTagName("li");
	}
	else {return false}
	tabli[d].className = "focus";
	for(var i=0;i<tabli.length;i++){
		var tabA = tabli[i].firstChild;
		tabA.onclick = function(){trunTab(this);return false;}
	}
	function trunTab(btn){
		var target = btn.href.split("#")[1];/*获取被点击元素的href属性中以#分割成数组后的第2段字符串*/
		var targetObj = target.substr(0,target.length-1);/*截取target元素中从第一位至倒数第二位的字符串*/
		for(var j=0;j<tabli.length;j++){
			tabli[j].className = "";
			var n = j+1;
			$(targetObj+n).style.display = "none"
			/*把全部标签项的className清除,内容部分全部隐藏*/
		}
		btn.parentNode.className = "focus";
		$(target).style.display = "block";
		/*打开指定的内容及标签项部分*/
	}
}
