if(typeof(Array.prototype.push) == 'undefined'){

	Array.prototype.push = function(item){
		var max = -1;
		for(i=0;i<this.length;i++){
			max++;
		}
		this[max+1] = item;
	}
}
if(typeof(TabTable) == 'undefined')
{
	function TabTable(){

		this.arHandles = null;
		this.arTables = null;
		this.handleEvent = 'onclick';
		this.curHandleId = null;
		
		this.init = function(handles,tables,paramHandleEvent){
			handles = handles.split(',');
			tables = tables.split(',');
			if(paramHandleEvent) this.handleEvent = paramHandleEvent;
	
			this.arHandles = new Array();
		
			for(var i=0;i < handles.length;i++){
				var tmp = document.getElementById(handles[i]);	
				if(tmp){
					//tmp.style.cursor = 'hand';
					var f = this.proxycall(this,this.showTable,[tmp.id,tables[i]]);
		
					this.attachEventEx(tmp,this.handleEvent,f);
					
					//mouse 放在handle上时，改变样式
			
					if(this.handleEvent.toLowerCase() != 'onmouseover'){
					
			
						var fhover = this.proxycall(this,this.showHover,[tmp.id,tables[i]]);
						this.attachEventEx(tmp,'onmouseover',fhover);
						
						var fout = this.proxycall(this,this.showHover,[null,null]);
						this.attachEventEx(tmp,'onmouseout',fout);
					}
					
					this.arHandles.push(tmp);
				}
			}
	
			this.arTables = new Array();
			for(var i=0;i < tables.length;i++){
				var tmp = document.getElementById(tables[i]);
				if(tmp) this.arTables.push(tmp);
			}
	
			return this;
		}
		
		this.showHover = function(handelId,tableId){
					
			for(var i=0;i < this.arHandles.length;i++){
				var tmp = this.arHandles[i];
				if(tmp && tmp.id == this.curHandleId) continue;
				if(tmp && tmp.id == handelId){
					if(tmp.getAttribute("imghover")) tmp.innerHTML = "<img src='"+ tmp.getAttribute("imghover") +"' />";
					if(tmp.getAttribute("bgimghover")) tmp.style.backgroungImage = tmp.getAttribute("bgimghover");
					if(tmp.getAttribute("bghover")) tmp.style.backgroundColor = tmp.getAttribute("bghover");
					if(tmp.getAttribute("colorhover")) tmp.style.color = tmp.getAttribute("colorhover");
					if(tmp.getAttribute("classhover")) tmp.className = tmp.getAttribute("classhover");
				}else{
					if(tmp.getAttribute("imgoff")) tmp.innerHTML = "<img src='"+ tmp.getAttribute("imgoff") +"' />";
					if(tmp.getAttribute("bgimgoff")) tmp.style.backgroungImage = tmp.getAttribute("bgimgoff");
					if(tmp.getAttribute("bgoff")) tmp.style.backgroundColor = tmp.getAttribute("bgoff");
					if(tmp.getAttribute("coloroff")) tmp.style.color = tmp.getAttribute("coloroff");
					if(tmp.getAttribute("classoff")) tmp.className = tmp.getAttribute("classoff");
				}
			}
		}
	
		this.showTable = function(handelId,tableId){
		
			for(var i=0;i < this.arHandles.length;i++){
				var tmp = this.arHandles[i];
				if(tmp && tmp.id == handelId){
					if(tmp.getAttribute("imgon")) tmp.innerHTML = "<img src='"+ tmp.getAttribute("imgon") +"' />";
					if(tmp.getAttribute("bgimgon")) tmp.style.backgroungImage = tmp.getAttribute("bgimgon");
					if(tmp.getAttribute("bgon")) tmp.style.backgroundColor = tmp.getAttribute("bgon");
					if(tmp.getAttribute("coloron")) tmp.style.color = tmp.getAttribute("coloron");
					if(tmp.getAttribute("classon")) tmp.className = tmp.getAttribute("classon");
					this.curHandleId = handelId;
				}else{
					if(tmp.getAttribute("imgoff")) tmp.innerHTML = "<img src='"+ tmp.getAttribute("imgoff") +"' />";
					if(tmp.getAttribute("bgimgoff")) tmp.style.backgroungImage = tmp.getAttribute("bgimgoff");
					if(tmp.getAttribute("bgoff")) tmp.style.backgroundColor = tmp.getAttribute("bgoff");
					if(tmp.getAttribute("coloroff")) tmp.style.color = tmp.getAttribute("coloroff");
					if(tmp.getAttribute("classoff")) tmp.className = tmp.getAttribute("classoff");
				}
			}
			for(var i=0;i < this.arTables.length;i++){
				var tmp = this.arTables[i];
				if(tmp && tmp.id == tableId){
					tmp.style.display = 'block';
				}else{
					tmp.style.display = 'none';
				}
			}
		}
	
		this.proxycall = function(obj,method,args){
			var f = (function(){ method.apply(obj, args);});
			return f;
		}
	
		this.attachEventEx = function (eid,env,action){
			var object = typeof(eid)=='object'?eid:document.getElementById(eid);
			if (object && object.addEventListener){
				if(/^(on)/gi.test(env)) env = env.substr(2);
				object.addEventListener(env,action,true);
			}else if(object){
				object.attachEvent(env,action);
			}
		}
	}
}
