
/**
 * Iguala el tamaño de las columnas del menu y de destacados
 */
OnResizeWindow.onReizeWidth = function() {
	setHeight('destacados', null);
	if ($$('menu')) setHeight('menu', null);

	var offset = $$('financiacion').offsetTop;
	if ($$('cuerpo').clientHeight > $$('destacados').clientHeight)
	{
		setHeight('destacados', $$('cuerpo').clientHeight);
		var i = 1;
		while ($$('financiacion').offsetTop > offset) {
			setHeight('destacados', $$('cuerpo').clientHeight - i);
			i += 2;
		}
	}

	if ($$('menu'))
	{
		setHeight('menu', $$('destacados').clientHeight - ($$('buscador') ? $$('buscador').clientHeight : 0) );
		var i = 1;
		while ($$('financiacion').offsetTop > offset) {
			setHeight('menu', $$('destacados').clientHeight - ($$('buscador') ? $$('buscador').clientHeight : 0) - i);
			i += 2;
		}
	}
}

EventosOnLoad.addEvento('TextoForms.run()');
EventosOnLoad.addEvento('OnResizeWindow.run()');


/**
 * Muestra el reproductor
 */
function showPlayer(rutaPlayer, rutaDescriptor, dimensiones, idContenedor, js)
{
	var dimensiones = ajustaDimensiones(dimensiones, idContenedor);

	var s = new SWFObject(rutaPlayer, 'mediaplayer', dimensiones.ancho, dimensiones.alto, 9);
	s.addParam('allowfullscreen', 'true');
	s.addParam('allowscriptaccess', 'sameDomain');
	s.addParam('wmode', 'opaque');
	s.addVariable('width', dimensiones.ancho);
	s.addVariable('height', dimensiones.alto);
	s.addParam('seamlesstabbing', 'true');
	s.addVariable('file', rutaDescriptor);
	s.addVariable('backcolor', '0x000000');
	s.addVariable('frontcolor', '0xFFFFFF');
	s.addVariable('lightcolor', '0x6CAE23');
	if (js) {
		s.addVariable('enablejs', 'true');
		s.addVariable('javascriptid', 'mediaplayer');
	}
	s.write(idContenedor);
}



/**
 * Modifica la estructura del documento por javascript
 */
function reestructurarSecciones(rutaImgs)
{
	//la portada no se toca
	if ($$('interior'))
	{
		//mover RSS a zona de menu
		var li = document.createElement('LI');
		li.appendChild( $$('destacados').getElementsByTagName('H2')[0] );
		$$('menu').insertBefore( li, $$('menu').firstChild );

		//mover banners a zona de menu
		if ($$('banners'))
		{
			li = document.createElement('LI');
			li.appendChild( $$('banners') );
			$$('menu').appendChild( li );
		}

		//mover destacados y añadir esquinas redondeadas
		if ($$('contenidos_destacados'))
		{
			$$('contenido').appendChild( $$('contenidos_destacados') );
			var des = $$('contenidos_destacados').getElementsByTagName('LI');
			for (i=0; i<des.length; i++)
			{
				var top = document.createElement('DIV');
				top.className = 'top';
				var subtop = document.createElement('DIV');
				subtop.appendChild( document.createTextNode(' ') );
				top.appendChild( subtop );
				
				des[i].insertBefore(top, des[i].firstChild);
	
				var bottom = document.createElement('DIV');
				bottom.className = 'bottom';
				var subbottom = document.createElement('DIV');
				subbottom.appendChild( document.createTextNode(' ') );
				bottom.appendChild( subbottom );
				
				des[i].appendChild(bottom);
			}
		}
		
		//ocultar columna destacados
		$$('destacados').style.padding = '0';
		$$('destacados').style.backgroundImage = 'none';
		if (isIE6()) $$('destacados').style.width = '1px';
		else $$('destacados').style.width = '0';
		
		//alargar cuerpo y hacerlo ligeramente mas grande
		if (isIE6()) $$('cuerpo').style.width = '99.5%';
		else $$('cuerpo').style.width = '100%';
		if (isIE()) $$('contenido').childNodes[1].style.marginLeft = '22.5em';
		else $$('contenido').childNodes[3].style.marginLeft = '22.5em';
		$$('menu').style.width = '17em';
		$$('menu').style.backgroundImage = 'none';
		$$('menu').style.paddingTop = '1em';
		$$('contenido').style.background = 'transparent url(' + rutaImgs + 'destacados.png) repeat-y scroll 19.5em top';
	}
}

function muestraTitulo(titulo)
{
	var completo = titulo.innerHTML.replace('<span class="oculto">','').replace('</span>','').replace('...','');
	if (isIE()) completo = completo.replace('<SPAN class=oculto>','').replace('</SPAN>','')
	
	var h4 = document.createElement('h4');
	h4.appendChild( document.createTextNode(completo) );
	h4.className = 'completo';
	h4.onmouseout = function() { ocultaTitulo(h4) };
	titulo.parentNode.appendChild(h4);
}

function muestraTitulo1(titulo,link)
{
	var completo = titulo.innerHTML.replace('<span class="oculto">','').replace('</span>','').replace('...','');
	if (isIE()) completo = completo.replace('<SPAN class=oculto>','').replace('</SPAN>','')
	
	var h4 = document.createElement('h4');
	h4.appendChild( document.createTextNode(completo) );
	var enlace = documento.createElement('a');
	enlace.setAttribute('href', link);
	h4.appendChild(enlace);
	h4.appendChild( document.createTextNode(completo) );
	h4.className = 'completo';
	h4.onmouseout = function() { ocultaTitulo(h4) };
	titulo.parentNode.appendChild(h4);
}

function ocultaTitulo(titulo)
{
	titulo.parentNode.removeChild(titulo);
}

var Staff = {
	
	visible : false,
	
	show : function()
	{
		if (!this.visible)
		{
			if (!$$('fondoStaff'))
			{
				var div = document.createElement('DIV');
				div.setAttribute('id', 'fondoStaff');
				div.style.height = document.body.clientHeight+'px';
				div.onclick = function() { Staff.close(); }
				document.body.appendChild(div);
			}
			else {
				$$('fondoStaff').style.display = 'block';
			}
			
			if (!$$('frameStaff'))
			{
				var frame = document.createElement('IFRAME');
				frame.setAttribute('id', 'frameStaff');
				frame.src = '/ticmania/contenidos/system/modules/com.fti.ticmania/templates/staff.html';
				frame.width = '600px';
				frame.height = '295px';
				frame.frameBorder = '0';
				frame.style.left = ((document.body.clientWidth - 500) / 2) + 'px';
				document.body.appendChild(frame);
				setTimeout('Staff.resize()', 200)
			}
			else {
				$$('frameStaff').style.display = 'block';
			}
			
			this.visible = true;
		}
	},
	
	close : function()
	{
		if (this.visible)
		{
			$$('fondoStaff').style.display = 'none';
			$$('frameStaff').style.display = 'none';
			this.visible = false;
		}
	},
	
	resize : function()
	{
		$$('frameStaff').height = ($$('frameStaff').contentDocument.body.scrollHeight + 5) + 'px';
	}
}