var pos = 0;
var anchoTotCarru =0;
var anchoCaja=0;
var cuenta=0;
var numItems = 0;
var anchoStrip = 0;
var clip="";
var myIndexClip=0;

var videoPlaying="";
var videoPlayingAnt="";
var newVideo="";
/**/

var anchoStripVideos = 0;
var posVideos= 0;
var anchoCajaVideos = 0;

var vengoBot= false;

$(document).ready(function(){
	
	// ------------------------------------------------------------------------------------------------------ //
	// SLIDER MARCAS
	// ------------------------------------------------------------------------------------------------------ //
		
	numItems=$("#stripLogos li").length;	
	anchoStrip=($("#stripLogos li").width()+30)*numItems; // 30 es el del margin de left y right de cada LI!		
	$("#stripLogos").css("width", anchoStrip);
	anchoCaja = $("#stripLogos li").width()+30;
	/**/	
	anchoStripVideos= $("#stripVideo li").width()*numItems;	
	anchoCajaVideos=  $("#stripVideo li").width();
	$("#stripVideo").css("width", anchoStripVideos);
	
	cuenta = numItems;
			
	onMarcas($("#stripLogos li:eq("+myIndexClip+")"));	
	
	$("#stripLogos li").bind('click', function(){

		clearInterval(timer);

		vengoBot= true;
		clip=$(this);
		myIndexClip = $(this).index();
		 
		newPosVideo = ((anchoCajaVideos*myIndexClip)-anchoStripVideos);
		posVideos = (newPosVideo+anchoStripVideos)*-1;
		
		newPosLogos = ((anchoCaja*myIndexClip)-anchoStrip);
		pos = (newPosLogos+anchoStrip)*-1;
	
		carruHeader();
		timer = setInterval("carruHeader()", 10000)
		
		
	});	
	
	
	// ------------------------------------------------------------------------------------------------------ //
	// CARRUSEL
	// ------------------------------------------------------------------------------------------------------ //

	$("#flechaIzq").bind('click', function(){									   
		carruHeaderBack();   			
		clearInterval(timer);
		timer = setInterval("carruHeader()", 10000)
		//schauVideo();
	});
	
	$("#flechaDer").bind('click', function(){
		clearInterval(timer);
		carruHeader();
		timer = setInterval("carruHeader()", 10000)
		//chauVideo();
	});	
	
	videoPlaying = $("#stripVideo li:eq("+myIndexClip+") #contenedorVideo iframe").attr("src");
		
});


// ------------------------------------------------------------------------------------------------------ //
// NOVEDADES FUNCTIONS
// ------------------------------------------------------------------------------------------------------ //
/*
function avanzarNovedad(posNov)
	{
		$("#stripLogos").stop().animate({left:(posNov+'px')},{queue:false, duration:700, easing: 'easeOutSine'})	
	}
*/
// ------------------------------------------------------------------------------------------------------ //
// CARRUSEL FUNCTIONS
// ------------------------------------------------------------------------------------------------------ //

function chauVideo(){
	videoPlaying = ($("#stripVideo li:eq("+myIndexClip+") #contenedorVideo iframe").attr("src")).toString();
	//$("#stripVideo li:eq("+myIndexClip+") #contenedorVideo").hide();
	//$("#stripVideo li:eq("+myIndexClip+") #contenedorVideo iframe").attr( 'src', '" "' );
}


function offMarcas(){
	for(i = 0; i<numItems; i++){
		$("#stripLogos li:eq("+i+")").html('<img src="content/img/marca'+i+'_off.png"/>');
	}
}
	
function onMarcas(clip){
	offMarcas();
	clip.html('<img src="content/img/marca'+myIndexClip+'_on.png"/>');
}

function carruHeaderBack(){	
	if(pos<0){
		myIndexClip--;
		onMarcas($("#stripLogos li:eq("+myIndexClip+")"));
		cuenta++;
		/**/
		pos = pos+anchoCaja;
		posVideos = posVideos+anchoCajaVideos;
		
		$("#stripLogos").stop().animate({left:(pos+'px')},{queue:false, duration:1000, easing: 'easeOutSine'})
		$("#stripVideo").stop().animate({left:(posVideos+'px')},{queue:false, duration:1000, easing: 'easeOutSine'})

	}
	
	//$("#stripVideo li:eq("+myIndexClip+") #contenedorVideo").show();
	//$("#stripVideo li:eq("+myIndexClip+") #contenedorVideo iframe").attr( 'src',videoPlaying);
	
}

function carruHeader(){			
		
	if(numItems>7){ // anda si la cantidad de fotos es mayor a las mostradas	
				
		if(myIndexClip==(numItems-1)){
			cuenta=1;
			}
		
		if(!vengoBot){
		
			if(cuenta>1){ // 7 es la cantidad que mostramos por defaut					
				pos =(pos - anchoCaja);	
				posVideos =(posVideos - anchoCajaVideos);		
			}else{
				pos = 0;
				posVideos = 0;
				cuenta=numItems+1;	
				myIndexClip=-1;	
			}			
			
			myIndexClip++;
			onMarcas($("#stripLogos li:eq("+myIndexClip+")"));	
			
			$("#stripLogos").stop().animate({left:(pos+'px')},{queue:false, duration:1000, easing: 'easeOutSine'})
			$("#stripVideo").stop().animate({left:(posVideos+'px')},{queue:false, duration:1000, easing: 'easeOutSine'})
			
		}else{			
			vengoBot = false;									
			onMarcas($("#stripLogos li:eq("+myIndexClip+")"));	
			$("#stripLogos").stop().animate({left:(pos+'px')},{queue:false, duration:1000, easing: 'easeOutSine'})
			$("#stripVideo").stop().animate({left:(posVideos+'px')},{queue:false, duration:1000, easing: 'easeOutSine'})
		}
		
		cuenta--;
		
	}
		
}
	
timer = setInterval("carruHeader()", 10000); // intervalo de la pasada de las marcas













/*		
	for(var i=0; i<numItems; i++){
	   posItem = i*$("#strip li").width();
	   itemsarray.push(posItem*(-1));		
	}
	*/	
		
	/*
	$("#stripLogos li").each(function () {
	});
	*/
