Event.observe(window,"load",function(){
	slider();
});

function slider()
{
	var tiempo;
	var tiempoNoticia;
	var cuadro=$("divNoticiaVideo");
	var duracionAutoSlide=5000;
	if(!cuadro)
	{
		return;
	}
	var slideNews=function(){	
		var activos=$$(".cuadroNoticias .listaNoticias ul li.activo");
		if(activos.length<=0)
		{
			return;
		}
		var activo=activos[0];
		var next;
		if(activo.next())
		{
			next=activo.next();
		}
		else
		{
			next=$$(".cuadroNoticias .listaNoticias ul li")[0];
		}
		cambiarNoticiaPrincipal(next);
		tiempo=setTimeout(function(){slideNews();},duracionAutoSlide);
	}
	cuadro.observe("mouseover",function(){
		clearTimeout(tiempo);		
	});
	cuadro.observe("mouseout",function(){
		tiempo=setTimeout(function(){slideNews();},duracionAutoSlide);		
	});
	var titulares=cuadro.select("ul.ulNoticia li");
	if(titulares.length>0)
	{		
		var cambiarNoticiaPrincipal=function (elemento)
		{			
			var duracion=.3;
			var duracion2=duracion;			
			if(Prototype.Browser.IE)
			{
				duracion2=0;
			}
			
			var lista=elemento.up("ul");
			var activo=lista.down(".activo");
			if(activo)
			{
				activo.down(".tituloNoticia a").setStyle({color:'#555'});
					new Effect.Fade(activo.down(".fondo"),{duration:duracion,afterFinish:function(){
						activo.removeClassName("activo");
					}});
			}
			elemento.addClassName("activo");
			elemento.down(".tituloNoticia a").setStyle({color:'#fff'});
			new Effect.Appear(elemento.down(".fondo"),{duration:duracion2,afterFinish:function(){
			}});
			var fondo=new Element("div",{'class':'fondo'});
			cuadro.select(".imagenOculta").invoke("hide");		
			cuadro.down(".imagenPreview").insert(fondo);
			var nuevaImagen=cuadro.down("[imagen='"+elemento.readAttribute("imagen")+"']");
			nuevaImagen.show();
			new Effect.Fade(fondo,{duration:.3,afterFinish:function(){
				fondo.remove();
			}});
			if(Prototype.Browser.IE && BrowserDetect.version<7 && !elemento.down(".fondo").hasClassName("procesado"))
			{
				elemento.down(".fondo").setStyle({behavior:"url(../javascript/libs/iepngfix.htc)"});
				elemento.down(".fondo").addClassName("procesado");
			}
		}
		titulares.each(function(item){
			item.observe("mouseover",function(){
				clearTimeout(tiempoNoticia);
				if(item.hasClassName("activo"))
				{
					return;
				}
				tiempoNoticia=setTimeout(function(){	
					cambiarNoticiaPrincipal(item);
				},500);
			});
		});
	}
	tiempo=setTimeout(function(){slideNews();},duracionAutoSlide);
}

Event.observe(window,"load",function(){
	var banner=$("linkMinutoAnimado");
	if(!banner)
	{
		return;
	}
	setTimeout(function(){animarBanner(banner);},2000);
});

function animarBanner(banner)
{
	var actual=banner.down(".mostrado");
	var otro=banner.down(".nomostrado");
	actual.addClassName("nomostrado").removeClassName("mostrado");
	otro.addClassName("mostrado").removeClassName("nomostrado");
	setTimeout(function(){animarBanner(banner)},2000);
}

function comenzarAutoSlide()
{
	clearTimeout(tiempoNoticia);
	tiempoSlideNoticia=setTimeout(function(){slideNews();},duracionAutoSlide);
}

function verVideo(video,desc,campo)
{
	 var so = new SWFObject("/swf/flvPlayer.swf", "swfplayer", "320", "240", "9", "#000000"); // Player loading  
     so.addVariable("videoPath", "/videos/flv/"+video); // File Name
     //so.addVariable("imagePath", "/images/videos/"); // Image preview name 
     so.addVariable("autoStart", "true"); // Image preview name
     so.addVariable("hideLogo", "true"); // Image preview name
     so.addVariable("volAudio", "50"); // Image preview name
     so.addVariable("extendVideo", "true"); // Image preview name
     so.addParam("allowFullScreen","true"); // Allow fullscreen, disable with false
     so.addParam("wmode","transparent"); // Allow fullscreen, disable with false
     so.addVariable("bgcolo","000000"); // Background color of controls in html color code  
	 so.addVariable("frontcolor","CCCCCC"); // Foreground color of controls in html color code    
     so.write("reproductor"); // This needs to be the name of the div id
	campo=$(campo);
	var lista=campo.up(".ulVideos");
	var links=lista.select("a");	
	links.invoke("removeClassName","activo");
	$(campo).addClassName("activo");
	$("nombreVideo").update(desc);
}

function verVideoTube(texto,desc,campo)
{
	var video='\
		<object width="320" height="240">\
			<param name="movie" value="http://www.youtube.com/v/'+texto+'&hl=es&fs=1&"></param>\
			<param name="allowFullScreen" value="true"></param>\
			<param name="allowscriptaccess" value="always"></param>\
			<embed src="http://www.youtube.com/v/'+texto+'&hl=es&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="240"></embed>\
		</object>\
	';
	$("reproductor").update(video);
	$("nombreVideo").update(desc);
	campo=$(campo);
	var lista=campo.up(".ulVideos");
	var links=lista.select("a");	
	links.invoke("removeClassName","activo");
	$(campo).addClassName("activo");
}