﻿function tab(tabMenuId,tabContentId,menuTag,bodyTag,curClass,n){
	 if(!document.getElementById(tabContentId)) return false;
	 if(!document.getElementById(tabMenuId)) return false;
	 this.div=document.getElementById(tabContentId).getElementsByTagName(bodyTag);
     this.tabTagLi=document.getElementById(tabMenuId).getElementsByTagName(menuTag);
	 this.cur=curClass;
	 this.n=n;
	 this.objh=null;
	 this.autoTabTagLiIndex=0;
}
tab.prototype.changDiv=function(tabTagId){
	document.getElementById(tabTagId).style.display="block";
	if(this.objh!=""&&this.objh!=tabTagId){document.getElementById(this.objh).style.display="none";}
	this.objh=tabTagId;	
}
tab.prototype.changMenu=function(tabTagId){
 for(var i=0;i<this.tabTagLi.length;i++){
	if(!this.tabTagLi[i].getAttribute("id")||this.tabTagLi[i].getAttribute("id").indexOf("_")==-1) continue;
	if(this.objh==null && this.tabTagLi[i].className.indexOf(this.cur)!=-1){
	 this.objh=this.tabTagLi[i].getAttribute("id").split("_")[1];
    }
    var menuID=this.tabTagLi[i].getAttribute("id").split("_")[1];
    this.tabTagLi[i].className=this.tabTagLi[i].className.replace(this.cur,"");
	if(menuID==tabTagId){this.tabTagLi[i].className+=" "+this.cur}
 }
}
tab.prototype.tabLiAction=function(){
 if(!this.div) return false;
 if(!this.tabTagLi) return false;
 var eventType=["onclick","onmouseover"];
 var _this = this;
 for(var i=0;i<this.tabTagLi.length;i++)
   { 
   	 if(!this.tabTagLi[i].getAttribute("id")||this.tabTagLi[i].getAttribute("id").indexOf("_")==-1)  continue;
	 this.tabTagLi[i][eventType[this.n]]=function(){
		   var tabTagId=this.getAttribute("id").split("_")[1];
		   if(!document.getElementById(tabTagId)) return false;
		   _this.changMenu(tabTagId);
		   _this.changDiv(tabTagId);
		 }
   }
}
tab.prototype.autoTabLiAction=function()
{
	try
	{
		var tabTagId='';
		var _this = this;
		if(!_this.div) return false;
		if(!_this.tabTagLi) return false;
		if(_this.autoTabTagLiIndex>=_this.tabTagLi.length)
		{
			_this.autoTabTagLiIndex=0;
		}
		for(var i=_this.autoTabTagLiIndex;i<_this.tabTagLi.length;i++)
		{	
			if(!_this.tabTagLi[i].getAttribute("id")||_this.tabTagLi[i].getAttribute("id").indexOf("_")==-1)
			{	
				continue;
			}
			_this.autoTabTagLiIndex=i+1;
			var tabTagId=_this.tabTagLi[i].getAttribute("id").split("_")[1];
			break;
		}
		if(document.getElementById(tabTagId))
		{
			_this.changMenu(tabTagId);
			
			_this.changDiv(tabTagId);
		}
		setTimeout(function (){_this.autoTabLiAction()},5000);
	}
	catch(e)
	{
	
	}
}


