var viendoVideo = 0;

function init(){	
	timerRecarga = setTimeout("recargarPortada()",180000);
}
function mostrandoVideo(opc){
	viendoVideo = opc;
}
function recargarPortada(){
	
	if (viendoVideo==1) timerRecarga = setTimeout("recargarPortada()",10000);
	else top.location.reload(true);
	
}

$(document).ready(function(){
    $("#pestanaAreas").click(function(){
    	if(document.getElementById('areas').style.display == ''){
    		document.getElementById('areas').style.display = 'none';
    	}
    	else{
    		document.getElementById('areas').style.display = '';
    	}
    	
	});
    $("#cajaBusquedas").click(function(){
    	$("#masbusquedas").slideToggle("high");
		$("#masbusquedas").css({ display: 'none' });
    });
});

function desplegarPersiana(seccion){
	
	document.getElementById('trabajosPersiana').className = "";
	document.getElementById('cursosPersiana').className = "";
	document.getElementById('mastersPersiana').className = "";
	document.getElementById('oposicionesPersiana').className = "";
	//document.getElementById('inmobiliariaPersiana').className = "";
	//document.getElementById('amarillasPersiana').className = "";
	document.getElementById(seccion).className = "on";
		
} // Fin desplegarPersiana

function cambiarBusqueda(tipo){
	
	// SE LE PONE EL CLASS ULTIMA AL ULTIMO ITEM
	var formulario  = document.getElementById('buscador');
	var botonBuscar = document.getElementById('Submit');
	
	if(tipo == 'imagenes'){
		formulario.setAttribute("action", "http://buscar.hispavista.com/imagenes.phtml");
		$("#imagenes").css({display:'none'});
		$("#noticias").css({display:''});
		$("#directorio").css({display:''});
		$("#web").css({display:''});
		botonBuscar.setAttribute("value", "Imágenes");
	}
	else if(tipo == 'noticias'){
		formulario.setAttribute("action", "http://es.globedia.com/buscar/");
		$("#noticias").css({display:'none'});
		$("#imagenes").css({display:''});
		$("#directorio").css({display:''});
		$("#web").css({display:''});
		botonBuscar.setAttribute("value", "Noticias");
	}
	else if(tipo == 'directorio'){
		formulario.setAttribute("action", "http://guia.hispavista.com/buscar/");
		$("#directorio").css({display:'none'});
		$("#noticias").css({display:''});
		$("#imagenes").css({display:''});
		$("#web").css({display:''});
		botonBuscar.setAttribute("value", "Directorio");
	}
	else if(tipo == 'web'){
		formulario.setAttribute("action", "http://buscar.hispavista.com/");
		$("#web").css({display:'none'});
		$("#noticias").css({display:''});
		$("#directorio").css({display:''});
		$("#imagenes").css({display:''});
		botonBuscar.setAttribute("value", "Buscar");
	}
	
	$("#masbusquedas").slideToggle("high");
	$("#masbusquedas").css({ display: 'none' });
	
}

function rellenarString(){
	var cadena = document.getElementById('cadena').value;
	document.getElementById('str').setAttribute("value", cadena);
}

function mostrarDeportes(seccion){
	
	var param = "SECCION=" + seccion;
	$.ajax({url: '/obtenerSeccionDeportes.phtml',
		type: 'POST',
		data: param,
		dataType: 'html',
		success: function(resultado){
			$('#resultadosDeportes').fadeOut('fast', function() {
				$('#resultadosDeportes').html(resultado).fadeIn('fast');
				var pestanas = document.getElementById('clasificacion');
				if(seccion == 'res1'){
					pestanas.getElementsByTagName('a')[0].className = "on";
					pestanas.getElementsByTagName('a')[1].className = "";
					pestanas.getElementsByTagName('a')[2].className = "";
					pestanas.getElementsByTagName('a')[3].className = "";
				}
				else if(seccion == 'clas1'){
					pestanas.getElementsByTagName('a')[0].className = "";
					pestanas.getElementsByTagName('a')[1].className = "on";
					pestanas.getElementsByTagName('a')[2].className = "";
					pestanas.getElementsByTagName('a')[3].className = "";
				}
				else if(seccion == 'res2'){
					pestanas.getElementsByTagName('a')[0].className = "";
					pestanas.getElementsByTagName('a')[1].className = "";
					pestanas.getElementsByTagName('a')[2].className = "on";
					pestanas.getElementsByTagName('a')[3].className = "";
				}
				else if(seccion == 'clas2'){
					pestanas.getElementsByTagName('a')[0].className = "";
					pestanas.getElementsByTagName('a')[1].className = "";
					pestanas.getElementsByTagName('a')[2].className = "";
					pestanas.getElementsByTagName('a')[3].className = "on";
				}
				/*else if(seccion == 'mundial'){
					pestanas.getElementsByTagName('a')[0].className = "on";
					pestanas.getElementsByTagName('a')[1].className = "";
					pestanas.getElementsByTagName('a')[2].className = "";
				}*/
			});
		}
	});
	
} // Fin javascript:mostrarDeportes(

// INICIO NOTICIAS
var first = 0;
var speed = 500;
var pause = 4000;
var numero = 0;

$(document).ready(function(){
   interval = setInterval(removeFirst, pause);
});

function removeFirst(){
	first = $('#listaNoticiasOcultas #timeline_item:last').html();
	if(numero<5){
		numero++;
		$('#listaNoticias #timeline_item:last').remove();
		$('#listaNoticiasOcultas #timeline_item:last').remove();
		addLast(first);
	}
	
} // Fin removeFirst
	
function addLast(first){
	first = '<div id="timeline_item">'+first+'</div>';
	$('#listaNoticias').prepend(first);
	$('#listaNoticias #timeline_item:first').fadeTo('slow',0.2);
	$('#listaNoticias #timeline_item:first').fadeTo('fast',1);
		
	// SE LE PONE EL CLASS ULTIMA AL ULTIMO ITEM
	var listaNoticias  = document.getElementById('listaNoticias');
	listaNoticias.getElementsByTagName('h3')[listaNoticias.getElementsByTagName('h3').length - 1].className = "ultima";
	
} // Fin addLast

function mostrarNoticia(seccion){
	var param = "SECCION=" + seccion;
	$.ajax({url: '/obtenerNoticiaSeccion.phtml',
		type: 'POST',
		data: param,
		dataType: 'html',
		success: function(resultado){
			$('#noticiaPrincipal').fadeOut('fast', function() {
				$('#noticiaPrincipal').html(resultado).fadeIn('fast');
			});
		}
	});
} // Fin mostrarNoticia


function mostrarArticulo(seccion){
	var param = "SECCION=" + seccion;
	$.ajax({url: '/obtenerArticuloSeccion.phtml',
		type: 'POST',
		data: param,
		dataType: 'html',
		success: function(resultado){
			$('#bloqueMotor').fadeOut('fast', function() {
				$('#bloqueMotor').html(resultado).fadeIn('fast');
				var pestanas = document.getElementById('pestanas');
				if(seccion == 'motor'){
					pestanas.getElementsByTagName('a')[0].className = "motor";
					pestanas.getElementsByTagName('a')[1].className = "";
					pestanas.getElementsByTagName('a')[2].className = "";
				}
				else if(seccion == 'mujer'){
					pestanas.getElementsByTagName('a')[1].className = "mujer";
					pestanas.getElementsByTagName('a')[0].className = "";
					pestanas.getElementsByTagName('a')[2].className = "";
				}
				else if(seccion == 'tecno'){
					pestanas.getElementsByTagName('a')[2].className = "tecno";
					pestanas.getElementsByTagName('a')[0].className = "";
					pestanas.getElementsByTagName('a')[1].className = "";
				}
			});
		}
	});
		
	
} // Fin mostrarArticulo
// FIN NOTICIAS

//INICIO VIDEOS
function mostrarVideo(idVideo){
	var param = "IDVIDEO=" + idVideo;
	$.ajax({url: '/obtenerVideo.phtml',
		type: 'POST',
		data: param,
		dataType: 'html',
		success: function(resultado){
			$('#videoDestacado').fadeOut('fast', function() {
				$('#videoDestacado').html(resultado).fadeIn('fast');
			});
		}
	});
	var param = "ID=" + idVideo;
	$.ajax({url: '/obtenerVideo.phtml',
		type: 'POST',
		data: param,
		dataType: 'html',
		success: function(resultado){
			$('#titulovideo').html(resultado);
			document.getElementById('titulovideo').style.display='';
		}
	});
	
	// SE MARCA EL VIDEO ELEGIDO
	var elemento = document.getElementById('video' + idVideo);
	var imagen = elemento.getElementsByTagName('img')[0];
	imagen.setAttribute("class", "on");
	
	// SE DESMARCA EL RESTO
	var bloque = document.getElementById('bloqueVideos');
	for(var i=0;i<bloque.getElementsByTagName('li').length;i++){
		var elemento = bloque.getElementsByTagName('li')[i];
		if(elemento.getAttribute('id') != 'video' + idVideo){
			var imagen = elemento.getElementsByTagName('img')[0].setAttribute("class", "");
		}
	}
	
} // Fin mostrarVideo

function quitartitulovideo() {
	document.getElementById('titulovideo').style.display='none'; 
}
//FIN VIDEOS