	var pos=0; 

	$(document).ready(function()
	{
/*		
		// Flash principal de la HOME:
		$("#movie-estrenos").flashembed(
			{src: "/assets/swf/coverflow.swf", wmode: 'transparent', scale: 'noscale', salign: 't1'},
			{settingsXML: '/assets/swf/settings.xml'}
		);

		// Banner rotativo:
		$(".banner-rotativo").flashembed(
			{src: "/assets/swf/banner-home/imageFlip.swf", wmode: 'transparent'},
			{urlXml: '/assets/swf/banner-home/data/imagenes.xml'}
		);	
*/	
		jQuery('#sliderProximosEstrenos').jcarousel({
				wrap: 'circular',
				auto: 2
    	});
		
		if($('.triggerEstrenoSemana').length > 0)
		{
			// Activo el trigger de onclick
			$('.triggerEstrenoSemana').click(function()
			{        
				// Limpio el timer:
				clearTimeout(estrenosGlobalTimer);
				
				$('.triggerEstrenoSemana').each(function(){
					$(this).removeClass("active");
				});
			
				var data = $(this).metadata();
				$("#aficheEstrenoGrandeHref").attr("href","peliculas/" + data.path);
				$("#aficheEstrenoGrande").attr("src", ebowe.cdn + "/assets/afiches/" + data.id + "/thumbs_" + data.afiche +"/260-386_" + data.afiche);
				$("#aficheEstrenoGrande").attr("title", data.titulo);
				$("#aficheEstrenoGrande").attr("alt", data.titulo);
				$("#tituloEstreno").html(data.titulo);			
				$(this).addClass("active");
				
				setTimeout("estrenosTimer()", 8000);	
			});					

			estrenosTimer();
		}
			

		$("#cartelera-siguiente").click(function()
		{        
			$.ajax({
				url: '/include/lib/home/cartelera.php',
				type: "POST",
				//data: "submit=&paginaPelisCarteleraHome="+pagina,
				dataType:'json', 
				success: function(datos){
					var pagina = $("#paginaPelisCarteleraHome").val();
					//alert("Posicion actual: " + pagina);
					//alert("largo" + datos.length);
					if(datos.length>6)
					{
						$("#pelis-cartelera-home").animate({
							opacity: 0.25,
							left: '+=50',
							width: 'toggle'
						}, 1000, function(){
							for(i=0;i<6;i++)
							{
								pos = parseInt(pagina) + parseInt(i);
								if(pos >= datos.length)
								{
								  pagina = 0;  
								  pos = 0;
								}         
								var nro = parseInt(i)+1;
								$("#cartelera-pelis-afiche-link"+nro).attr("href","/peliculas/" + datos[parseInt(pos)].path)
								$("#cartelera-pelis-titulo-link"+nro).attr("href","/peliculas/" + datos[parseInt(pos)].path)
								$("#cartelera-pelis-afiche"+nro).attr("src", ebowe.cdn + "/assets/afiches/" + datos[parseInt(pos)].id + "/thumbs_" + datos[parseInt(pos)].afiche + "/120-176_" + datos[parseInt(pos)].afiche);
								$("#cartelera-pelis-titulo"+nro).html(datos[parseInt(pos)].titulo);
							}
							$("#paginaPelisCarteleraHome").val(pos+1);
							$("#pelis-cartelera-home").animate({
							opacity: 1,
							left: '+=50',
							width: 'toggle'
						}, 1000, function(){});
						});                      
					}                                                                      
				}
			});                    
		});
		
		$("#cartelera2").change(function(){
			window.location.href = "/carteleras/" + $(this).val();        
		});
		
		$.fn.loopedSlider.defaults.addPagination = true;
		$('#loopedSlider').loopedSlider({
			autoStart: 5000,
			containerClick: false,
			restart: 5000
		});	
	});

	var estrenosGlobalTimer;

	function estrenosTimer()
	{
		var markNext = false;
		var first = '';
		var elements = $('.triggerEstrenoSemana').length;												
		//var arr = jQuery.makeArray($('.triggerEstrenoSemana'));
		var i = 0;
		$('.triggerEstrenoSemana').each(function()
		{			
			if(first == '')
				first = $(this).attr('id');
			
			if(markNext)
			{								
				var data = $(this).metadata();
				$("#aficheEstrenoGrandeHref").attr("href","peliculas/" + data.path);
				$("#aficheEstrenoGrande").attr("src", ebowe.cdn + "/assets/afiches/" + data.id + "/thumbs_" + data.afiche +"/260-386_" + data.afiche);
				$("#aficheEstrenoGrande").attr("title", data.titulo);
				$("#aficheEstrenoGrande").attr("alt", data.titulo);
				$("#tituloEstreno").html(data.titulo);			
				$(this).addClass("active");
				markNext = false;
			}
			else if($(this).hasClass("active"))
			{								
				if(i == (elements - 1))
				{
					var data = $('#' + first).metadata();
					$("#aficheEstrenoGrandeHref").attr("href","peliculas/" + data.path);
					$("#aficheEstrenoGrande").attr("src", ebowe.cdn + "/assets/afiches/" + data.id + "/thumbs_" + data.afiche +"/260-386_" + data.afiche);
					$("#aficheEstrenoGrande").attr("title", data.titulo);
					$("#aficheEstrenoGrande").attr("alt", data.titulo);
					$("#tituloEstreno").html(data.titulo);			
					$('#' + first).addClass("active");
				}			
				markNext = true;
				$(this).removeClass("active");				
			}							
			
			i++;
		});	

		estrenosGlobalTimer = setTimeout("estrenosTimer()", 8000);			
	}
