// JavaScript Document
var numPantallas=0;
var pantallaActual=0;
var numPantallasB=0;
var pantallaActualB=0;



var peliActiva="";
var cambiando =false;
var audioPlay =true;
$(document).ready(function(){
	
	
		showRecaptcha();
		
		
		$('#contenedorNoticias').load('scripts/getNotas.php',function(){
				$('#reelNoticias').width($('#contenedorNoticias').children().children().length*333);
				timer_is_on=0;
				pa=0;
				fotoT = ($('#contenedorNoticias').children().children().length)-1;
				doTimer();
			});
			
		$('#insideTiendas').load('scripts/getTiendas.php',function(){
				$('#insideTiendas').height($('#contenedorTiendas').children().children().children().children().length*96);
			});	
			
			
		$('#thumbCont1').load('scripts/getThumbs_ISO.php?tipo=ilustracion',function(){
			$('#thumbCont1 .galeria .thumbsPage .thumbImg').click(function (){mostrar_proyecto1($(this).attr("id"))});
			mostrar_proyecto1($('#thumbCont1').first().children().children().children().attr("id"));
			});
	
		$('#thumbCont2').load('scripts/getThumbs_ISO.php?tipo=modelos',function(){
			$('#thumbCont2 .galeria .thumbsPage .thumbImg').click(function (){mostrar_proyecto3($(this).attr("id"))});
			mostrar_proyecto3($('#thumbCont2').first().children().children().children().attr("id"));
			});	
		$('#thumbContSmall1').load('scripts/getThumbs_small_ISO.php?tipo=ropa_chicas',function(){
			$('#thumbContSmall1 .galeria .thumbsPageSmall .thumbImg').click(function (){mostrar_proyecto2($(this).attr("id"))});
			mostrar_proyecto2($('#thumbContSmall1').first().children().children().children().attr("id"));
		
			});
		$('#thumbContSmall2').load('scripts/getThumbs_small_ISO.php?tipo=ropa_chicos',function(){
			$('#thumbContSmall2 .galeria .thumbsPageSmall .thumbImg').click(function (){mostrar_proyecto2($(this).attr("id"))});
			
			});
		$('#thumbContSmall3').load('scripts/getThumbs_small_ISO.php?tipo=ropa_accesorios',function(){
			$('#thumbContSmall3 .galeria .thumbsPageSmall .thumbImg').click(function (){mostrar_proyecto2($(this).attr("id"))});
			
			});
		
		
		$("#nextNoticia").click(avanza_feed);
		$("#prevNoticia").click(retrocede_feed); 
		
		$('#prevTienda').click(function (event){movPagGeneral("prev",event.target)});
		$('#nextTienda').click(function (event){movPagGeneral("next",event.target)});
		
		$('#prevBtn').click(function (event){movPagGeneral("prev",event.target)});
		$('#nextBtn').click(function (event){movPagGeneral("next",event.target)});
		
		
		$('#prevBtn2').click(function (event){movPagGeneral("prev",event.target)});
		$('#nextBtn2').click(function (event){movPagGeneral("next",event.target)});
		
		$('#prevBtnS1').click(function (event){movPagGeneral("prev",event.target)});
		$('#nextBtnS1').click(function (event){movPagGeneral("next",event.target)});
		$('#prevBtnS2').click(function (event){movPagGeneral("prev",event.target)});
		$('#nextBtnS2').click(function (event){movPagGeneral("next",event.target)});
		$('#prevBtnS3').click(function (event){movPagGeneral("prev",event.target)});
		$('#nextBtnS3').click(function (event){movPagGeneral("next",event.target)});
		
		$('.thumbImg').mouseenter(function(){
			if(!cambiando){
										//	showThumbNail(this);
			}
											});
											
		$('.thumbImg').mouseleave(function(){
			if(!cambiando){
										//	hideThumbNail(this);
			}
											});
		$('#InfoContainer').mouseenter(function(){
										//	corrigeThumb();
											});
											
	});
function mostrar_proyecto1(p){
			//p.offsetParent.parentNode.parentNode.parentNode.children[1].children[0].children[0].src="imgData/big/"+p.id+".jpg";
		//$("#bigDisplay1").children().attr("src","imgData/big/"+p+".jpg");
		$("#bigDisplay1").load("socialPhotoDesign.php?idf="+p);	
			$.ajax({
						   type: "POST",
						   url: "scripts/getDetalleProyecto.php",
						   data: "c="+ p,
						   success: function(msg){
							 res= new Array();
							   
							 res= msg.split("+");
							  
							 tituloDetalle=res[0];
							 descDetalle=res[1]; 
							 precioDetalle=res[2];
							 claveDetalle=res[3];
							  videoDetalle=res[4];
							  //alert(msg);
							 $("#regInfo1 .tituloRegInfo h3").text(tituloDetalle); 
							 $("#regInfo1 .descRegInfo p").text(descDetalle); 
							 if(videoDetalle != ""){
								 $("#galleryControl_1 .galleryVideo_btn a ").css("display","block");
							$("#galleryControl_1 .galleryVideo_btn a").attr("href","javascript:abrir_lightBox('"+ videoDetalle+"')");	 
								 }else{
									$("#galleryControl_1 .galleryVideo_btn a ").css("display","none"); 
									 }
							// $("#regInfo1 .precioRegInfo p").text("Precio: $"+precioDetalle); 
						   }
						 });
 }
 function mostrar_proyecto2(p){
		//$("#bigDisplay2").children().attr("src","imgData/big/"+p+".jpg");
			$("#bigDisplay2").load("socialPhoto.php?idf="+p);
	$.ajax({
						   type: "POST",
						   url: "scripts/getDetalleProyecto.php",
						   data: "c="+ p,
						   success: function(msg){
							 res= new Array();
							   
							 res= msg.split("+");
							  
							 tituloDetalle=res[0];
							 descDetalle=res[1]; 
							 precioDetalle=res[2];
							 claveDetalle=res[3];
							   videoDetalle=res[4];
							  //alert(msg);
							 $("#regInfo2 .tituloRegInfo h3").text(tituloDetalle); 
							 $("#regInfo2 .descRegInfo p").text(descDetalle); 
							 $("#regInfo2 .precioRegInfo p").text("Price: $"+precioDetalle); 
							 $('#wishlistForm #idp').val(claveDetalle);
							 $('#wishlistForm #precioP').val(precioDetalle);
							 $('#wishlistForm #tituloP').val(tituloDetalle);
							 
							 if(videoDetalle != ""){
								 $("#galleryControl_2 .galleryVideo_btn a ").css("display","block");
							$("#galleryControl_2 a").href("javascript:abrir_lightBox('"+ videoDetalle+"')");	 
								 }else{
									$("#galleryControl_2 .galleryVideo_btn a ").css("display","none"); 
									 }
							 //$("#regInfo2 .shoppingCart a").attr('href','carrito.php?op=add&idp='+claveDetalle+'&cantF=1&tituloP='+tituloDetalle+'&precioP='+precioDetalle);
						   }
						 });	//p.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].children[0].src="imgData/big/"+p.id+".jpg";

 }
  function mostrar_proyecto3(p){
	 // alert(p);
		//$("#bigDisplay3").children().attr("src","imgData/big/"+p+".jpg");
		$("#bigDisplay3").load("socialPhotoModelo.php?idf="+p);
	$.ajax({
						   type: "POST",
						   url: "scripts/getDetalleProyecto.php",
						   data: "c="+ p,
						   success: function(msg){
							 res= new Array();
							   
							 res= msg.split("+");
							  
							 tituloDetalle=res[0];
							 descDetalle=res[1]; 
							 precioDetalle=res[2];
							 claveDetalle=res[3];
							   videoDetalle=res[4];
							  //alert(msg);
							 $("#regInfo3 .tituloRegInfo h3").text(tituloDetalle); 
							 $("#regInfo3 .descRegInfo p").text(descDetalle); 
							 
							 if(videoDetalle != ""){
								 $("#galleryControl_3 .galleryVideo_btn a ").css("display","block");
							$("#galleryControl_3 a").href("javascript:abrir_lightBox('"+ videoDetalle+"')");	 
								 }else{
									$("#galleryControl_3 .galleryVideo_btn a ").css("display","none"); 
									 }
							// $("#regInfo3 .precioRegInfo p").text("Precio: $"+precioDetalle); 
						   }
						 });	//p.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].children[0].src="imgData/big/"+p.id+".jpg";

 }
 





function movPagGeneral(d,t){
	if (d == "next"){
		
			PA_gen = Number(t.parentNode.attributes['pa'].nodeValue);
			numP_gen = Number(t.parentNode.parentNode.firstElementChild.firstElementChild.childElementCount);
			if(PA_gen < (numP_gen-1)){
				PA_gen++;
				t.parentNode.attributes['pa'].nodeValue=PA_gen;
			//	$('#prevBtnS1').removeClass("botonInactivo");
			$(t.parentNode.children[0]).removeClass("botonInactivo");
				//$('#prevBtnS1').addClass("botonActivo");
				$(t.parentNode.children[0]).addClass("botonActivo");
$(t.parentNode.parentNode.firstElementChild.firstElementChild).animate({top:-PA_gen*289});
				if(PA_gen == (numP_gen-1)){
					//	$('#nextBtnS1').removeClass("botonActivo");
					$(t.parentNode.children[1]).removeClass("botonActivo");
						//$('#nextBtnS1').addClass("botonInactivo");
						$(t.parentNode.children[1]).addClass("botonInactivo");
					}
				}
				
					
		}else{
		if(PA_gen > 0){
				PA_gen--;
				t.parentNode.attributes['pa'].nodeValue=PA_gen;
				//$('#nextBtnS1').removeClass("botonInactivo");
				$(t.parentNode.children[1]).removeClass("botonInactivo");
				//$('#nextBtnS2').addClass("botonActivo");
				$(t.parentNode.children[1]).addClass("botonActivo");
				///$("#thumbContSmall1").children().animate({top:-PA_gen*295});
				$(t.parentNode.parentNode.firstElementChild.firstElementChild).animate({top:-PA_gen*289});
				if(PA_gen == 0){
					
					//$('#prevBtnS1').removeClass("botonActivo");
					$(t.parentNode.children[0]).removeClass("botonActivo");
					//$('#prevBtnS1').addClass("botonInactivo");
					$(t.parentNode.children[0]).addClass("botonInactivo");
					}
				}
		}}

function timedCount()
{ 	
	if(pa < fotoT){
		avanza_feed();
	}else{
		$('#reelNoticias').animate({"left": "0px"}, "slow");
		pa=0;
}
//fotoA == 6 ? fotoA=1 : fotoA++;
t=setTimeout("timedCount()",5000);
} 

function doTimer(){
// fotoT = ($("#carrusel_feed").children().length)-1;
	if (!timer_is_on)
		{
			timer_is_on=1;
			timedCount();
		}
}

function avanza_feed(){
	//alert("avanza");
	if(pa < fotoT){
		$('#reelNoticias').animate({"left": "-=333px"}, "slow");
		pa++;
	}
}

function retrocede_feed(){
	//alert("avanza");
	if(pa>0){
		$('#reelNoticias').animate({"left": "+=333px"}, "slow");
		pa--;
	}
}

function validarEnvioMail(){
	//alert("ingui");
//	/$.fancybox({'autoDimensions'	: true,
		//		'href'				: "scripts/verify.php",
//				'type'				: "iframe"});
			///	$("#mailerFormContainer").validate();
			var variables =$('#mailerFormContainer').serialize();
			//alert(variables);
			$.ajax({
						   type: "POST",
						   url: "scripts/verify.php",
						   data: variables,
						   success: function(msg){
							  
							 		$.fancybox(msg,{'autoDimensions'	: false,
													'width':300 ,
													'height':200,
													'overlayColor':'#000',
													'overlayOpacity':.3
													});
						   }
						 });
			
	}

function showRecaptcha() {

		  Recaptcha.create("6LfqY8cSAAAAAEBtchiYKlJDswUWdbiyFVEnUY5u",
    "cajaCaptcha",
    {
      theme: "red",
      callback: Recaptcha.focus_response_field
    }
  );
		}



/******************************************************/
 function abrir_lightBox(l){
	$.fancybox(l,{'autoDimensions'	: true});
	}

function corrigeThumb(){
	$('#dataContainerAux').fadeIn('slow');
	$("#stripcontainer").attr("src","imgData/strips/"+peliActiva+".jpg");
	}
	
function showThumbNail(a){
	$("#nameIndicator h1").text($(a).attr("alt"));
	  $("#stripcontainer").css("display","block");
	$("#stripcontainer").attr("src","imgData/strips/"+$(a).attr("id")+".jpg");
	$('#dataContainerAux').fadeOut('slow');
	}
	
function hideThumbNail(a){
	$("#nameIndicator h1").text("");
	}
	
function verVideo(c){
	
	$('#megAux').fadeOut('slow', function() {
    	//$('#presentadorContainer').animate({ height:640 },2000, function() {
   			$('#videoScreenContainer').fadeIn('slow',function(){
					$.ajax({
						   type: "POST",
						   url: "/scripts/getTrailer.php",
						   data: "c="+ c,
						   success: function(msg){
							   $("#videoScreenContainerAux").html(msg);
							 // t1= $("#videoScreenContainerAux").children().width()-932;
							  t2= $("#videoScreenContainerAux").children().height()+50;
							  $('#presentadorContainer').animate({ height:t2 },1000);
							//  $("#videoScreenContainerAux").children().css("margin-left",t1/2);
							//   $("#videoScreenContainerAux").children().css("margin-right",t1/2);
							//   $("#videoScreenContainerAux").children().css("margin-top",t2/2);
							//   $("#videoScreenContainerAux").children().css("margin-bottom",t2/2);
						   }
						 });
	   		//});
  		});
	 });

}
	/*function verVideo(c){
			$.ajax({
   type: "POST",
   url: "/scripts/getTrailer.php",
   data: "c="+ c,
   success: function(l){
	   if(l != ""){
	 $.fancybox(l,{'autoDimensions'	: true});
	   }
   }
 });
		}*/
	function playSound() {
		if(!audioPlay){
		audioPlay =true;
$("#audioControl").html("<embed enablejavascript=\"true\" src=\"audio/bgm.mp3\" loop=\"true\" hidden=\"true\" type=\"mp3\" autostart=\"true\" id=\"audioLoop\" volume=\"75\"></embed> ");
		}
}
function stopSound() {
		if(audioPlay){
			audioPlay =false;
  			$("#audioControl").empty();
		}
}
function switchAudio(){
	if(!audioPlay){
		playSound();
	}else{
		stopSound();
		}
}

function cerrarVideo(){

	playSound();
	$('#videoScreenContainer').fadeOut('slow', function() {
    	$('#presentadorContainer').animate({ height:311 },2000, function() {
   $('#megAux').fadeIn('slow',function(){
	   cambiando=false;
	   		 $("#videoScreenContainerAux").empty();
	   });
  });

  });
	
	}
