function MasterTabs()
{
	this.contenedor = null;
	this.contenedorPrincipal = null;
	this.websiteId;
	this.tabSeleccionado = null;
	
	this.tabs = new ObjectoManager();
	
	this.traer = function(etiqueta)
	{
		var tab = this.tabs.trater(etiqueta);	
		return tab;
	}
	
	this.agregarTab = function(etiqueta)
	{
		var tab = this.tabs.traer(etiqueta);
		
		if(null == tab)
		{
			var tab = new Tab()
			tab.id = etiqueta;
			
			this.tabs.agregar(etiqueta, tab);
		}
		
		return tab;
	}	
	
	this.construir = function(contenedor)
	{	
		this.contenedor = contenedor;
		this.crearTabs();
		this.dibujar();
	}
	
	this.crearTabs = function()
	{		
		var tab = this.agregarTab("player");
		tab.nombre = masterConf.idiomaManager.tabPlayer;
		tab.funcion = dibujarPlayer;
		
/*		var tab = this.agregarTab("noticias");
		tab.nombre = masterConf.idiomaManager.tabNoticias;
		tab.funcion = dibujarNoticias;*/
		
		var tab = this.agregarTab("explorar");
		tab.nombre = masterConf.idiomaManager.tabExplorar;
		tab.funcion = dibujarExplorar;
	}
	
	this.dibujar = function()
	{	
		this.contenedor.innerHTML = "";
		
		var tbody = crearTabla(this.contenedor);
		tbody.parentNode.style.height = 40;
		
		var tr = cE("tr", tbody);
		
		for(var i=0; i<this.tabs.length; i++)
		{
			var thisObj = this;
			
			var tab = this.tabs.traerNo(i);
			
			var td = cE("td", tr);
	
			td.vAlign = "bottom";
			td.style.paddingLeft = "12px";
			
			var className = (thisObj.tabSeleccionado == tab) ? "master_tabs_on" : "master_tabs_off";
			
			var divTab = cE("div", td);
			divTab.style.cursor = "pointer";
			divTab.className = className;

			if(tab.primeraVez)
			{
				var div = cE("div", this.contenedorPrincipal);
				div.style.height = "100%";
				div.style.display = "none";
				tab.contenedorPrincipal = div;	
				
				if(masterConf.headerInicialId == "player" && tab.id == "player")
				{
					tab.primeraVez = false;
					tab.funcion(tab)
					divTab.className = "master_tabs_on";
					div.style.display = "block";
				}				
				else if(tab.id == masterConf.headerInicialId && tab.id != "player")
				{
					tab.primeraVez = false;
					tab.funcion(tab)
					divTab.className = "master_tabs_on";
					div.style.display = "block";			
				}
				else if(masterConf.headerInicialId != "player" && tab.id == "player")
				{
					tab.primeraVez = false;
					tab.funcion(tab)
				}
			}
			else
			{
				var display = (thisObj.tabSeleccionado == tab) ? "block" : "none";
				tab.contenedorPrincipal.style.display = display;				
				
				if(thisObj.tabSeleccionado == tab)
				{
					masterConf.thisUrl = thisObj.tabSeleccionado.id;
				}		
				
				masterConf.actualizarUrl();				
			}
			
			tab.construir(divTab)	
			
			tab.onclick = function()
			{			
				thisObj.tabSeleccionado = this;
				
				if(this.primeraVez)
				{
					this.funcion(this);
					this.primeraVez = false;					
				}
				
				thisObj.dibujar();
			}
		}
	}
}	

function Tab()
{
	this.id = null;
	this.nombre = "";	
	
	this.contenedor = null;
	this.funcion = null;
	this.primeraVez = true;
	this.display = true;
	
	this.construir = function(contenedor)
	{
		contenedor.innerHTML = this.nombre;
		contenedor.style.cursor = "pointer";
		
		var thisObj = this;
		
		contenedor.onclick = function()
		{			
		 	thisObj.onclick();
		}
	}	
}

function dibujarPlayer(tab)
{
	div = cE("div", tab.contenedorPrincipal);
	
	masterPlayer.dibujar(div);
}

function dibujarNoticias(tab)
{
	var iFrame = document.createElement("iframe");
	iFrame.frameBorder = "no";
	iFrame.style.border = 0;
	iFrame.style.width = "100%";
	iFrame.style.height = (BrowserDetect.browser == "Explorer") ? masterConf.windowAltura - 41 : "100%";
	iFrame.src = masterConf.noticiasIFrame;
	tab.contenedorPrincipal.appendChild(iFrame);
}

function dibujarExplorar(tab)
{
	var iFrame = document.createElement("iframe");
	iFrame.id = "explorar";
	iFrame.frameBorder = "no";
	iFrame.style.border = 0;
	iFrame.style.width = "100%";
	iFrame.style.height = (BrowserDetect.browser == "Explorer") ? masterConf.windowAltura - 41 : "100%";
	iFrame.src = masterConf.explorarIFrame;
	tab.contenedorPrincipal.appendChild(iFrame);
}

