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;
	}
}

function TabTable(handles,tables,paramHandleEvent) {
	this.arHandles = null;
	this.arTables = null;
	this.handleEvent = 'onclick';
	this.curHandleId = null;
	this.init(handles,tables,paramHandleEvent);
}

TabTable.prototype.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);
	}
}

TabTable.prototype.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");
		}
	}
}

TabTable.prototype.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';
		}
	}
}

TabTable.prototype.proxycall = function(obj,method,args){
	var f = (function(){ method.apply(obj, args);});
	return f;
}

TabTable.prototype.attachEventEx = function (eid,env,action){
	var object = typeof(eid)=='object'?eid:document.getElementById(eid);
	if (object && object.addEventListener){
		if(/^(on)/i.test(env)) env = env.substring(2);
		//alert(env+","+object.id+","+action);
		object.addEventListener(env,action,true);
	}else if(object){
		object.attachEvent(env,action);
	}
}

