﻿var Tab = function(_varName,_currentItemName,tabItem,_onClickCallback,_bgClass,_foregroundClass,_backgroundClass,_separatorClass,_style,_prefixDivWidth){
	this.varname			= _varName;
	this.menuItem 			= tabItem;
	this.currentItemName	= _currentItemName;
	this.onClickCallback	= _onClickCallback;
	this.bgClass			= _bgClass;
	this.foregroundClass	= _foregroundClass;
	this.backgroundClass	= _backgroundClass;
	this.separatorClass		= _separatorClass;
	this.style				= _style ? _style : "111";
	this.prefixDivWidth		= _prefixDivWidth ? _prefixDivWidth : "0";
	this.currentIndex;
	this.flag				= false;
	
		
	this.onClick = function(targetId){
		var len = this.menuItem.length;
		var id;
		var tabItem;
		var currentIndex;
		var i;
		for(i=0; i<len; i++){
				if(targetId == this.menuItem[i][0]){
					currentIndex = i;
					try{$("tab_separator_"+i).style.display ="none";}catch(e){}
					try{$("tab_separator_"+(i+1)).style.display ="none";}catch(e){}
					$("tab_" + this.menuItem[i][0]).className = this.foregroundClass;
					$("tab_" + this.menuItem[i][0] + "_l").style.display ="block";
					$("tab_" + this.menuItem[i][0] + "_r").style.display ="block";
				}else{
					$("tab_separator_"+i).style.display ="block";
					$("tab_" + this.menuItem[i][0]).className = this.backgroundClass;
					$("tab_" + this.menuItem[i][0] + "_l").style.display ="none";
					$("tab_" + this.menuItem[i][0] + "_r").style.display ="none";	
				}
		}
		$("tab_separator_"+i).style.display ="block";
		
		
		
/*		var len = this.menuItem.length;
		var id;
		var tabItem;
		var currentIndex;
		for(var i=0; i<len; i++){
			id = "tab_"+this.menuItem[i][0];
			tabItem = document.getElementById(id);
			if(id == targetId){
				if(this.menuItem[i][2] == "")
					break;
				currentIndex = i;
				this.currentItemName  = this.menuItem[i]
[0];
				this.currentIndex=i;
				tabItem.className = this.foregroundClass;
			}else{
				tabItem.className = this.backgroundClass;
			}
			try{
				document.getElementById(id+"_l").style.display ="none";
				document.getElementById(id+"_r").style.display ="none";
				tabItem = document.getElementById("tab_separator_"+i);	
				tabItem.style.display = "block";
			}catch(e){}
		}
		document.getElementById("tab_"+this.menuItem[currentIndex][0]+"_l").style.display = "block";
		document.getElementById("tab_"+this.menuItem[currentIndex][0]+"_r").style.display = "block";
		if(this.style == "1"){
			if(currentIndex > 0)
				document.getElementById("tab_separator_"+(currentIndex-1)).style.display = "none";
			if(currentIndex < this.menuItem.length-1 )
				document.getElementById("tab_separator_"+currentIndex).style.display = "none";
		}
*/
		eval(this.onClickCallback);
		try{
			if(this.menuItem[currentIndex][2]!="#" && this.flag){
				document.location = this.menuItem[currentIndex][2];
			}
		}catch(e){}

	}
	
	this.init = function(){
		var tabHTML = '';
		tabHTML += '<div id="tab_separator_'+0+'" style="display:block;" class="'+this.separatorClass+'"></div>';
//		tabHTML += '<div style="width: '+this.prefixDivWidth+'px;clear: right;float: left;"></div>';
		var len = this.menuItem.length;
		for(var i=0; i<len; i++){
			if(this.currentItemName==this.menuItem[i][0])
				this.currentIndex =  i;
			tabHTML += '<div id="tab_'+this.menuItem[i][0]+'_l" class="' + this.foregroundClass + '_l" style="display:none"></div>';
			tabHTML += '<div  nowrap="nowrap" onclick="'+this.varname+'.onClick(\''+this.menuItem[i][0]+'\');" id="tab_'+this.menuItem[i][0]+'" class="'+((this.currentItemName==this.menuItem[i][0]) ? (this.foregroundClass) : this.backgroundClass)+'">';
			tabHTML += this.menuItem[i][1]+'</div>';
			tabHTML += '<div id="tab_'+this.menuItem[i][0]+'_r"  class="' + this.foregroundClass + '_r" style="display:none"></div>';
			tabHTML += '<div id="tab_separator_'+(i+1)+'" style="display:block;" class="'+this.separatorClass+'"></div>';	
		}
		document.write('<div id="tab_temp" class="'+this.bgClass+'">' + tabHTML + "</div>");
		//alert(tabHTML);
		this.onClick(this.currentItemName);
		this.flag=true;
	}
	this.init();
	
}