/*********Class for top10tabs
**Should work together with PHP to create tab templates
**Required MooTools for work
*/

function top10tabs(emptyArray){
	
	
	this.curOpenTabNum = 0;
	this.elIDs 				= new Array();	
	//ID`s for elements that owns this tabs
	this.actionNames	= new Array();	
	//actions for every tab
	
	this.hrLineL	=	null;
	this.hrLineR	=	null;
	
		
	
	this.togleTab = function(tabNumber){
		for(var i = 0; i< this.elIDs.length;i++){
			if(this.elIDs[i] == tabNumber){
				this.openTabByIndex(this.elIDs[i]);
				if(this.actionNames[i] != "no"){
					this.executeAction(this.actionNames[i]);
				}
			}else{
				this.closeTabByIndex(this.elIDs[i]);
			}
		}			
		//redrawing underline
		this.drawLines(tabNumber);		
	}	
	
	this.hide = function(tabNum){
		togle_element($("top_tab_id_"+this.elIDs[tabNum]),false);		
	}	
	this.hideByName = function(tabName){
		for(var i = 0; i< this.elIDs.length;i++){
			if(this.actionNames[i] == tabName){
				this.hide(i);
				//this.init();
				return;
			}
		}
	}		
	this.unHide = function(tabNum){		
		togle_element($("top_tab_id_"+this.elIDs[tabNum]),true);		
	}	
	this.unHideByName = function(tabName){
		for(var i = 0; i< this.elIDs.length;i++){
			if(this.actionNames[i] == tabName){
				this.unHide(i);
				//this.init();
				return;
			}
		}
	}
	
	this.getIdByName = function(tabName){
		for(var i = 0; i< this.elIDs.length;i++){
			if(this.actionNames[i] == tabName){
				return this.elIDs[i];
			}
		}
	return null;		
	}
	
	this.executeAction = function(actionName){
		switch(actionName){
			
			case "showFindCity":
				load_node("showFindCity");
			break;
			
			case "showVotingHistory":				
				descr.togleVotingTable();
			break;			
			
			case "showComments":
				//first close other openedthings
				descr.togleCommentsTbl();
			break;
			case "showPostCommentPage":
				//first close other openedthings
				descr.toglePostCommentTbl();
			break;			
			
			
			case "showSaveSend":
				descr.togleSaveSendTbl();
			break;
			
			case "showMap":
				showMapForCurPlace();
			break;
			
			case "showOwnerInfo":
				toggleOwnerData();
				//defined in main_place_list.js
			break;
						
			case "showRegister":
				load_node("showRegister");
			break;			
			
			case "showAbout":
				load_node("showAbout");
			break;				
			
			case "showMyMobile":
				load_node("showMyMobile");
			break;							
			
			case "showHome":
				load_node("showHome");
			break;					
			
			case "showAdvertising":			
				load_node("showAdvertising");				
			break;					
			
			case "showWhoItWorks":
				load_node("showWhoItWorks");
			break;								
			case "showMyPage":
				load_node("showMyPage");
			break;											
			
		}		
		/**/
	}
	
	/*this.init_lines = function(){
		window.setTimeout("placeMenu.redrawLines();",10);
		window.setTimeout("topTabsManager.redrawLines();",10);		
	}*/
	/*this.redrawLines = function(){
		if(this.elIDs.length>1){
			var hrLineR = $('tabs_L_underline_pict_'+this.elIDs[0]+'_id');
			var curTabCoords 		= $("cur_tab_top_"+this.elIDs[0]).getCoordinates();			
			var lastTabCoords		= $("cur_tab_top_"+this.elIDs[this.elIDs.length-1]).getCoordinates();				
			//draw RIGHT line
			hrLineR.style.left=(curTabCoords.left-$('vt_ls_top_id1').width+6)+"px";		
			hrLineR.style.top=(curTabCoords.bottom)+"px";		
			hrLineR.style.width=(lastTabCoords.right - curTabCoords.left - 5)+"px";		
			hrLineR.height="1";
			hrLineR.style.display ="inline";						
		}		
	}*/
	
	this.drawLines = function(pressedTabNum){
		//draws line under tabs
		/*
		var hrLineL = $('tabs_L_underline_pict_'+this.elIDs[0]+'_id');
		var hrLineR = $('tabs_R_underline_pict_'+this.elIDs[0]+'_id');

		var curTabCoords 		= $("cur_tab_top_"+pressedTabNum).getCoordinates();
		var firstTabCoords	= $("cur_tab_top_"+this.elIDs[0]).getCoordinates();	
		var lastTabCoords		= $("cur_tab_top_"+this.elIDs[this.elIDs.length-1]).getCoordinates();	
		
		//draw LEFT line
		hrLineL.style.left=(firstTabCoords.left)+"px";		
		hrLineL.style.top=(curTabCoords.bottom)+"px";		
		hrLineL.style.width=(curTabCoords.left - firstTabCoords.left)+"px";		
		hrLineL.height="1";						
		hrLineL.style.display ="inline";			

		//draw RIGHT line
		hrLineR.style.left=(curTabCoords.right-$('vt_ls_top_id1').width+1)+"px";		
		hrLineR.style.top=(curTabCoords.bottom)+"px";		
		hrLineR.style.width=(lastTabCoords.right - curTabCoords.right)+"px";		
		hrLineR.height="1";
		hrLineR.style.display ="inline";		*/	
		
	}
	
	this.openMyName = function(pName){
		this.openTabByIndex(this.getIdByName(pName));
	}
	this.closeMyName = function(pName){
		this.closeTabByIndex(this.getIdByName(pName));
	}	
	
	this.closeTabByIndex = function(ind){
		$('vt_ls_top_id'+ind).setStyle('background-image','url(images/tabs/tab_left_side.png)');
		$('vt_cs_top_id'+ind).setStyle('background-image','url(images/tabs/tab_center.png)');
		$('vt_cs_top_id2'+ind).setStyle('background-image','url(images/tabs/tab_center.png)');		
		$('vt_rs_top_id'+ind).setStyle('background-image','url(images/tabs/tab_right_side.png)');		
	}
	this.openTabByIndex = function(ind){		
		$('vt_ls_top_id'+ind).setStyle('background-image','url(images/tabs/tab_left_side_sel.png)');
		$('vt_cs_top_id'+ind).setStyle('background-image','url(images/tabs/tab_center_sel.png)');
		$('vt_cs_top_id2'+ind).setStyle('background-image','url(images/tabs/tab_center_sel.png)');		
		$('vt_rs_top_id'+ind).setStyle('background-image','url(images/tabs/tab_right_side_sel.png)');		
	}
	
	this.closeAll = function(){
		for(var i = 0; i< this.elIDs.length;i++){
			this.closeTabByIndex(this.elIDs[i]);			
		}
		//this.curOpenTabNum = 0;
		//this.init_lines();
	}
	
}

var topTabsManager = new top10tabs();
var placeMenu = new top10tabs();
