var posNov = 0;
var voy = 0;
var anchoStrip=0;
var itemsarray = [];

var pos = 0;
var anchoTotCarru =0;
var anchoCaja=0;
var cuenta=0;

var numItemsNov=0;
var anchoCajaNov=0;
var cuentaNov=0;
var posNov = 0;
var itemNov=0;

var miVid="";

$(document).ready(function(){	

	$("#contFotosFicha ul").hide();
	
	numItemsNov=$("#strip li").length;
	anchoStripNov=$("#strip").width()*numItemsNov;				   
	$("#strip").css("width", anchoStripNov);	
	anchoCajaNov = $("#strip li").width();		
	cuentaNov = numItemsNov;

	/**/						   
						   
	numItemsObras=$("#stripObras li").length;
	anchoStripObras=$("#stripObras").width()*numItemsObras;
	$("#stripObras").css("width", anchoStripObras);	
	anchoCaja = $("#stripObras li").width();		
	cuenta = numItemsObras;
	
	if(numItemsObras<5){
		$("#contFlechasObras").hide();
	}else{
		$("#contFlechasObras").show();
	}
	
	
	// ------------------------------------------------------------------------------------------------------ //
	// ROTATIVO DE OBRAS HOME
	// ------------------------------------------------------------------------------------------------------ //
	
	$("#solapa2").hide();
	$("#solapa3").hide();
	
	$("#navRotativoObras li").click(function(){	
		for(i = 1; i<=3; i++){
			if(i == $(this).text()){
				$("#solapa"+i).show();	
				$("#btnSolapa"+i).removeClass('solapa'+i+'Off').addClass('solapa'+i+'On');
			}else if(i != $(this).text()){
				$("#solapa"+i).hide();
				$("#btnSolapa"+i).removeClass('solapa'+i+'On').addClass('solapa'+i+'Off');
			}
		}		
	});	
		
	
	// ------------------------------------------------------------------------------------------------------ //
	// NOVEDADES
	// ------------------------------------------------------------------------------------------------------ //
			
	numItems=$("#strip li").length;
	anchoStrip=$("#strip").width()*numItems;
	$("#strip").css("width", anchoStrip);
	
	for(var i=0; i<numItems; i++){
	   posItem = i*$("#strip li").width();
	   itemsarray.push(posItem*(-1));		
	}	
	
	$("#itemNov li").each(function () {
		$(this).addClass('itemNovOff');				   
	});
	
	$("#itemNov li").click(function(){									
								
		clearInterval(timerNov);
									
		for(i = 0; i<numItems; i++){
			if(i == $(this).text()){				
				
				$(this).removeClass('itemNovOff').addClass('itemNovOn');				
			}else if(i != $(this).text()){
				$("#itemNov li"+"#"+i).removeClass('itemNovOn').addClass('itemNovOff');				
			}
		}
		
		itemNov = $(this).index();
		avanzarNovedad(itemsarray[itemNov]);

		
	});	
	
	
	// ------------------------------------------------------------------------------------------------------ //
	// CARRUSEL
	// ------------------------------------------------------------------------------------------------------ //


	$("#flechaIzqObras").click(function(){	   
		carruHeaderBack();   	       	
		clearInterval(timer);
		timer = setInterval("carruHeader()", 6000)
	});
	
	$("#flechaDerObras").click(function(){		
		clearInterval(timer);
		carruHeader();
		timer = setInterval("carruHeader()", 6000)
	});	


	// ------------------------------------------------------------------------------------------------------ //
	// EMPRESAS
	// ------------------------------------------------------------------------------------------------------ //

	$("#laEmp1").addClass('laEmp1On');
	$("#laEmp2").addClass('laEmp2Off');
	$("#laEmp3").addClass('laEmp3Off');
	$("#laEmp4").addClass('laEmp4Off');
	/**/
	$("#contEmp2").hide();
	$("#contEmp3").hide();
	$("#contEmp4").hide();


	$('#navEmpresas li').bind('click', function(){
		var id=($(this).index()+1);
		for(i = 1; i<=4;i++){
			if(i!=id){
				$('#navEmpresas li #laEmp'+i).removeClass('laEmp'+i+'On').addClass('laEmp'+i+'Off');
				$("#contEmp"+i).hide();
			}else{
				$('#navEmpresas li #laEmp'+id).addClass('laEmp'+id+'On');				
				$("#contEmp"+id).show();
			}
		}
	});
	
	// ------------------------------------------------------------------------------------------------------ //
	// AGENDA
	// ------------------------------------------------------------------------------------------------------ //
	
	$("#grupoAg1").addClass('ag1On');
	$("#grupoAg2").addClass('ag2Off');
	/**/
	$("#grupoAg2").hide();
	$("#contAg2").hide();

	$('#navGrupoLaPlaza li').bind('click', function(){
		var id=($(this).index()+1);
		for(i = 1; i<=2;i++){
			if(i!=id){
				$('#navGrupoLaPlaza li #grupoAg'+i).removeClass('ag'+i+'On').addClass('ag'+i+'Off');
				$("#contAg"+i).hide();
			}else{
				$('#navGrupoLaPlaza li #grupoAg'+id).addClass('ag'+id+'On');				
				$("#contAg"+id).show();
			}
		}
	});
	
	// ------------------------------------------------------------------------------------------------------ //
	// GRUPO LA PLAZA
	// ------------------------------------------------------------------------------------------------------ //
	
	$("#grupoEmp1").addClass('grupo1On');
	$("#grupoEmp2").addClass('grupo2Off');
	//$("#grupoEmp3").addClass('grupo3Off');
	/**/
	$("#contEmp2").hide();
	//$("#contEmp3").hide();

	$('#navGrupoLaPlaza li').bind('click', function(){
		var id=($(this).index()+1);
		for(i = 1; i<=3;i++){
			if(i!=id){
				$('#navGrupoLaPlaza li #grupoEmp'+i).removeClass('grupo'+i+'On').addClass('grupo'+i+'Off');
				$("#contEmp"+i).hide();
			}else{
				$('#navGrupoLaPlaza li #grupoEmp'+id).addClass('grupo'+id+'On');				
				$("#contEmp"+id).show();
			}
		}
	});
	
	
	
	// ------------------------------------------------------------------------------------------------------ //
	// FICHA OBRAS
	// ------------------------------------------------------------------------------------------------------ //
	
	$("#data2").hide();
	$("#data3").hide();
	$("#data4").hide();

	$('#botonera li').bind('click', function(){
		var id=($(this).index()+1);
		for(i = 1; i<=4;i++){
			if(i!=id){				
				$("#data"+i).hide();
			}else{
				$("#data"+id).show();
			}
		}							
	});
	
	/**/
	
	$('#horariosFun ul').hide();
	$('#preciosFun ul').hide();
	
	$('#horariosFun').click(function() {
  		$('#horariosFun ul').slideToggle(300);		
	});
	
	$('#preciosFun').click(function() {
  		$('#preciosFun ul').slideToggle(300);
	});	
	
	/* LIGHTBOX ----------------------------------------------------------------------------------------------- */

	var myIndexFoto=0;
	var cantItems=0;	
	var myGal="";
	var prevGal="";
	
	$('#backLighBox').hide();
	$('#placaFotosVideo').hide();		
	$("#contVideosFicha li").hide(); 		
	$("#contFotosFicha li").hide();
	$("#contVideofoto li").hide();
	$("#contMapaDeSala li").hide();

			
	$("#fotosDetalle li").bind('click',function(){																
		myIndexFoto = $(this).index();		
		myGal = "";
		myGal = "#contFotosFicha";
		entraLight();
	});	
	
	$("#videosDetalle li").bind('click',function(){		
		myIndexFoto = $(this).index();		
		myGal = "";
		myGal = "#contVideosFicha";		
		entraLight();
	});	
	
	/* PARA EL MAPA DE SALA */
	
	$("#imgTeatro").bind('click',function(){		
		myIndexFoto = 0;		
		myGal = "";
		myGal = "#contMapaDeSala";		
		entraLight();
	});		
	
	// fin
	
		$("#contFotosMuseo li").bind('click',function(){			
		myIndexFoto = $(this).index();
		myGal = "";
		myGal = "#contVideofoto";
		entraLight();
	});		
			
	$(".verMasFotos").bind('click',function(){		
		myIndexFoto = 0;		
		myGal = "";
		myGal = "#contFotosFicha";		
		entraLight();
	});	
	
	$("#galeriaSalas").bind('click',function(){		
		myIndexFoto = 0;		
		myGal = "";
		myGal = "#contVideofoto";
		entraLight();
	});	
	
	
	$(".verMasVideos").bind('click',function(){		
		myIndexFoto = 0;		
		myGal = "";
		myGal = "#contVideosFicha";		
		entraLight();
	});	
	
	/* PARA EL HISTORICO -------------------------- */ 	
	
	$("#internaListHistorico li").bind('click',function(){			
		myIndexFoto = $(this).index();
		myGal = "";
		myGal = "#contVideofoto";
		entraLight();
	});
	
	$("#contHistorico li").bind('click',function(){			
		myIndexFoto = $(this).index();
		myGal = "";
		myGal = "#contVideofoto";
		entraLight();
	});
	
	/* FIN PARA HISTORICO --------------------------- */
	
	$("#backLighBox").bind('click',function(){		
		$(this).hide();
		$('#placaFotosVideo').hide();
		//$f(miVid).pause();
	});	
	
	$("#btnCerrar").bind('click',function(){		
		$("#backLighBox").hide();
		$('#placaFotosVideo').hide();
		$f(miVid).pause();
	});	
	
	function entraLight(){
		
		$("#contFotosFicha ul").show();	
		$("#contFotosFicha li").hide();	
		$("#contMapaDeSala li").hide();
		$("#salaMp").hide();
		
	
		if(myGal == "#contVideosFicha"){
			$("#contFotosFicha ul").hide();	
		}
		
		if(myGal == "#contMapaDeSala"){
			$("#contFlechaIzq").hide();
			$("#contFlechaDer").hide();
			$("#salaMp").show();

		}else{
			$("#contFlechaIzq").show();
			$("#contFlechaDer").show();
		}	
	
		cantItems=($(myGal+" li").length-1);
		
		var anchoVentana = $(window).width();
		var altoVentana = $(window).height();
		
		if(prevGal != ""){
			$(prevGal+" li").hide();
		}		
		
		$(myGal+" li").hide();	
		
		prevGal = myGal;
		
		$('#backLighBox').css('height', altoVentana);
		$('#backLighBox').css('height', anchoVentana);		
		$('#backLighBox').show();
		$('#backLighBox').stop().animate({
				opacity: 0.8
		}, 100,
		// termina y llamo al cont de las fotos y nav
		function (){
			//
			$('#placaFotosVideo').css('top',(altoVentana/2)-($('#placaFotosVideo').height()/2));
			$('#placaFotosVideo').css('left',(anchoVentana/2)-($('#placaFotosVideo').width()/2));	
			//		
			$('#flechaIzq').css('top',($('#placaFotosVideo').height()/2)-($('#flechaIzq').height()/2));
			$('#flechaDer').css('top',($('#placaFotosVideo').height()/2)-($('#flechaDer').height()/2));
			//
			if(myIndexFoto>=1){
				$(myGal+" li:eq("+(myIndexFoto-1)+")").hide();
			}
			$('#placaFotosVideo').show(500,function(){
				reposClip();				
			});			
		});				
	};	
	
	function reposClip(){	
		//
		if(myGal=="#contVideosFicha"){
			miVid= $(myGal+" li:eq("+myIndexFoto+") a").attr("id");
			$f(miVid).pause();	
		}
		//
		$(myGal+" li:eq("+myIndexFoto+")").fadeIn(100);
		$(myGal+" li:eq("+myIndexFoto+")").css("left",($('#placaFotosVideo').width()/2)-($(myGal+" li:eq("+myIndexFoto+")").width()/2));
		$(myGal+" li:eq("+myIndexFoto+")").css("top",($('#placaFotosVideo').height()/2)-($(myGal+" li:eq("+myIndexFoto+")").height()/2));
	};
	
	$('#flechaDer').bind('click',function(){
		//
		if(myGal=="#contVideosFicha"){
			$f(miVid).pause();	
		}		
		//
		$(myGal+" li:eq("+myIndexFoto+")").fadeOut(100,function(){
			$(this).hide();
			if(myIndexFoto>=cantItems){
				myIndexFoto=0;
			}else{
				myIndexFoto++;
			}
			reposClip();	
		});	
	});
	
	$('#flechaIzq').bind('click',function(){
		//	
		if(myGal=="#contVideosFicha"){
			$f(miVid).pause();	
		}
		//
		$(myGal+" li:eq("+myIndexFoto+")").fadeOut(100,function(){
			$(this).hide();	
			//$(this).stop().animate({left: '+=1150'}, 300);
			if(myIndexFoto>=cantItems-1){
				myIndexFoto--;
				}else{			
				myIndexFoto = cantItems;
			}
			reposClip();
		});			
	});
	
	$("#itemNov li"+"#"+0).removeClass('itemNovOff').addClass('itemNovOn');
	
	/* FORMS CONTACTO */
	
	var  indexCamp = 0;
	
	var arrayCampos = ["nombre y apellido","mail","asunto","INGRESE SU BUSQUEDA","nombre y apellido","mail" ];
	
	$('#nombre').focus(function() {
		indexCamp = 0;
		vaciarCampo($(this));
	});
	
	$('#nombre').blur(function() {
	  contacto($(this));	  
	});	
	
	/**/
	
	$('#mail').focus(function() {
		indexCamp = 1;
		vaciarCampo($(this));
	});
	
	$('#mail').blur(function() {
	    contacto($(this));	  
	});	
	
	/**/

	$('#asunto').focus(function() {
		indexCamp = 2;
		vaciarCampo($(this));
	});
	
	$('#asunto').blur(function() {
	    contacto($(this));	  
	});	
	
	/**/

	$('#busqueda').focus(function() {
		indexCamp = 3;
		vaciarCampo($(this));		
	});
	
	$('#busqueda').blur(function() {
	    contacto($(this));	  
	});	
	
	/* NEWSLWTTER */
	
	$('#nombre_news').focus(function() {
		indexCamp = 4;
		vaciarCampo($(this));
	});
	
	$('#nombre_news').blur(function() {
	  contacto($(this));	  
	});	
	
	$('#email_news').focus(function() {
		indexCamp = 5;
		vaciarCampo($(this));
	});
	
	$('#email_news').blur(function() {
	   contacto($(this));	  
	});	
	
	/* FIN -- ------------------------------------------------ NEWSLWTTER */
	
	function vaciarCampo(camp){
		if($(camp).attr('value')== arrayCampos[indexCamp]){
			$(camp).attr('value',"");		
		}
	}
	
	function contacto(camp){		
	  var campo =$(camp).attr('value');
	  $(camp).attr('value',campo)
	  if($(camp).attr('value')==""){
		 $(camp).attr('value',arrayCampos[indexCamp])  
	  }
	}
		
});


// ------------------------------------------------------------------------------------------------------ //
// NOVEDADES FUNCTIONS
// ------------------------------------------------------------------------------------------------------ //



function avanzarNovedad(posNov)
{
	$("#strip").stop().animate({left:(posNov+'px')},{queue:false, duration:700, easing: 'easeOutSine'},function(){
		clearInterval(timerNov);
		timerNov = setInterval("carruNov()", 10000);
	})	
}


function carruNov(){

	if(numItemsNov>1){ 
		
		if(cuentaNov>1){ 
			cuentaNov--;
			itemNov++;
		}else{ 
			itemNov= 0;			
			cuentaNov=numItemsNov;
		}		
		
		$("#strip").stop().animate({left:((itemsarray[itemNov])+'px')},{queue:false, duration:700, easing: 'easeOutSine'});		
		$("#itemNov li").removeClass('itemNovOn').addClass('itemNovOff');	
		$("#itemNov li"+"#"+itemNov).removeClass('itemNovOff').addClass('itemNovOn');	
		

	}
}

timerNov = setInterval("carruNov()", 10000);


// ------------------------------------------------------------------------------------------------------ //
// CARRUSEL FUNCTIONS
// ------------------------------------------------------------------------------------------------------ //

function carruHeaderBack(){		
		if(pos<0){
			pos = pos+anchoCaja;
			$("#stripObras").stop().animate({left:(pos+'px')},{queue:false, duration:700, easing: 'easeOutSine'})
		}
	}

function carruHeader(){
	if(numItemsObras>4){ // anda si la cantidad de fotos es mayor a las mostradas
		if(cuenta>4){ // 4 es la cantidad que mostramos por defaut
			pos =(pos - anchoCaja);			 
		}else{ 
			pos = 0;
			cuenta=numItemsObras+1;
		}
		cuenta--;
		$("#stripObras").stop().animate({left:(pos+'px')},{queue:false, duration:700, easing: 'easeOutSine'})
	}
	
}
	
timer = setInterval("carruHeader()", 6000);


