var noticia = 1;
var noticiaAntigua;
var avanzar = true;

window.onload = function()
{
	// alert("entro1");
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		
		for (c=2; c<=limite; c++)
		{
			$("foto" + c).style.filter = "alpha(opacity=0)";
			$("contenedorNoticia" + c).style.filter = "alpha(opacity=0)";
		}
		
	}
	else
	{
		
		for (c=2; c<=limite; c++)
		{
			$("foto" + c).style.opacity = 0;
			$("contenedorNoticia" + c).style.opacity = 0;
		}
	}
	tempo = setInterval('desaparecer()', 5000);
	
}


/* ************************** */
function desaparecer()
{
	// alert("entro2");
	new Effect.Opacity('foto' + noticia, { from: 1, to: 0, duration: 0.5});
	new Effect.Opacity('contenedorNoticia' + noticia, { from: 1, to: 0, duration: 0.5, afterFinish: aparecer});
	// alert("entro3");
}

function aparecer()
{
	$("foto" + noticia).style.display = "none";
	$("contenedorNoticia" + noticia).style.display = "none";
	
	if (avanzar)
	{
	noticia++;
	}
	else
	{
	noticia--;
	}
	if (noticia > 5 || noticia > limite)
	{
		noticia=1;
	}
	if (noticia < 1)
	{
		noticia=5;
		if (limite < 5)
		{
			noticia = limite;
		}
		else
		{
			noticia = 5;
		}
	}
	$("foto" + noticia).style.display = "block";
	$("contenedorNoticia" + noticia).style.display = "block";
	new Effect.Opacity('foto' + noticia, { from: 0, to: 1, duration: 0.5});
	new Effect.Opacity('contenedorNoticia' + noticia, { from: 0, to: 1, duration: 0.5});
}

/* ************************** */

function cambiar(valor)
{
	clearInterval(tempo);
	noticiaAntigua = noticia;
	noticia=valor;
	new Effect.Opacity('foto' + noticia, { from: 1, to: 0, duration: 0.5});
	new Effect.Opacity('contenedorNoticia' + noticia, { from: 1, to: 0, duration: 0.5, afterFinish: sustitucion});
	
}

function sustitucion()
{
	$("foto" + noticiaAntigua).style.display = "none";
	$("contenedorNoticia" + noticiaAntigua).style.display = "none";
	$("foto" + noticia).style.display = "block";
	$("contenedorNoticia" + noticia).style.display = "block";
	new Effect.Opacity('foto' + noticia, { from: 0, to: 1, duration: 0.5});
	new Effect.Opacity('contenedorNoticia' + noticia, { from: 0, to: 1, duration: 0.5});
}

/* ************************** */

function noticiaAnterior()
{
	avanzar= false;
	clearInterval(tempo);
	new Effect.Opacity('foto' + noticia, { from: 1, to: 0, duration: 0.5});
	new Effect.Opacity('contenedorNoticia' + noticia, { from: 1, to: 0, duration: 0.5, afterFinish: aparecer});
	tempo = setInterval('desaparecer()', 10000);
}

function noticiaSiguiente()
{
	avanzar= true;
	clearInterval(tempo);
	new Effect.Opacity('foto' + noticia, { from: 1, to: 0, duration: 0.5});
	new Effect.Opacity('contenedorNoticia' + noticia, { from: 1, to: 0, duration: 0.5, afterFinish: aparecer});
	tempo = setInterval('desaparecer()', 10000);
}

function buscarLibros()
{
	$('buscadorG').style.top=3 + "px";
	$('buscadorG').style.left=((document.documentElement.clientWidth/2) + 240)  + "px";
	$('buscadorG').style.display="block";
}

function _buscar(){
	if ($('select').value==2)
	{
		location.href = "buscar_noticias.cfm?busqueda=" + $("txtBusqueda").value;
	}
	if($('select').value==1){
		location.href = "buscar_libros.cfm?busqueda=" + $("txtBusqueda").value;
		}
}

function cerrarBuscador()
{
	$('buscadorG').style.display="none";
}