//JQuery***********************************************************************************************************************************************
$(document).ready(function() {
	
	// Menu principal***********************************************************************************************************************************
	$("#HeaderMenu a").mouseenter(function(){
		$("span",this).animate({padding:'6px 8px', bottom:'4px', background:'#a27e4f' }, 200);
		$("img",this).animate({opacity:1.0, }, 200);
	}).mouseleave(function(){
		$("span",this).animate({padding:'2px 8px', bottom:'0', background:'#FEF8ED' }, 200);
		$("img",this).animate({"opacity":"0"}, 200);
	});

	// Mostrar sub menus desarrollos*******************************************************************************************************************
	$(".menuDesarrollo").mouseenter(function(){
		var valorID = $(this).attr("id");
		$('#txtSubcategoria' + valorID ).load('genera-select.php',{id:valorID});
	});

	// Slide de imagenes con difusion******************************************************************************************************************
	function slideShow() {
		$('#Slide img').css({opacity: 0.0});
		$('#Slide img:first').css({opacity: 1.0});
		setInterval('gallery()',4000);
	};

	function gallery() {
		var current = ($('#Slide img.show')?  $('#Slide img.show') : $('#Slide img:first'));
		var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#Slide img:first') :current.next()) : $('#Slide img:first'));	
		next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
		current.animate({opacity: 0.0}, 1000).removeClass('show');
	};

	// Slide Seccion Corinoticias********************************************************************************************************************
	var imageWidthCN = $(".image_reelCN").width();
	var imageSumCN = $(".contReelCN").size();
	var imageReelWidthCN = imageWidthCN * imageSumCN;
	$(".image_reelCN").css({'width':imageReelWidthCN});
	$('.arrowLeftCN').css({display:'none'});
	
	$('.arrowRightCN').click(function(){
		var actualSlide = $(".image_reelCN").position().left;
		var nextSlide = actualSlide - 700;
		$('.image_reelCN').animate({left: nextSlide}, 0);
		$('.arrowLeftCN').css({display:'block'});
		if(actualSlide < (-1*(imageWidthCN - 700))){
			$('.arrowRightCN').css({display:'none'});
		}
	});

	$('.arrowLeftCN').click(function(){
		var actualSlide = $(".image_reelCN").position().left;
		var nextSlide = actualSlide + 700;
		$('.image_reelCN').animate({left: nextSlide}, 0);
		$('.arrowRightCN').css({display:'block'});
		if(actualSlide > -800){
			$('.arrowLeftCN').css({display:'none'});
		}
	});

	// Slide Seccion Testimoniales********************************************************************************************************************
	var imageWidthST = $(".image_reelST").width();
	var imageSumST = $(".contReelST").size();
	var imageReelWidthST = imageWidthST * imageSumST;
	$(".image_reelST").css({'width':imageReelWidthST});
	$('.arrowLeftST').css({display:'none'});

	$('.arrowRightST').click(function(){
		var actualSlide = $(".image_reelST").position().left;
		var nextSlide = actualSlide - 700;
		$('.image_reelST').animate({left: nextSlide}, 0);
		$('.arrowLeftST').css({display:'block'});
		if(actualSlide < -5500){
			$('.arrowRightST').css({display:'none'});
		}
	});

	$('.arrowLeftST').click(function(){
		var actualSlide = $(".image_reelST").position().left;
		var nextSlide = actualSlide + 700;
		$('.image_reelST').animate({left: nextSlide}, 0);
		$('.arrowRightST').css({display:'block'});
		if(actualSlide > -800){
			$('.arrowLeftST').css({display:'none'});
		}
	});

	// Slide Seccion Tips de Compra********************************************************************************************************************
	var imageWidthTC = $(".image_reelTC").width();
	var imageSumTC = $(".contReelTC").size();
	var imageReelWidthTC = imageWidthTC * imageSumTC;
	$(".image_reelTC").css({'width':imageReelWidthTC});
	$('.arrowLeftTC').css({display:'none'});

	$('.arrowRightTC').click(function(){
		var actualSlide = $(".image_reelTC").position().left;
		var nextSlide = actualSlide - 538;
		$('.image_reelTC').animate({left: nextSlide}, 0);
		$('.arrowLeftTC').css({display:'block'});
		if(actualSlide < (-1*(imageWidthTC - 600))){
			$('.arrowRightTC').css({display:'none'});
		}
	});

	$('.arrowLeftTC').click(function(){
		var actualSlide = $(".image_reelTC").position().left;
		var nextSlide = actualSlide + 538;
		$('.image_reelTC').animate({left: nextSlide}, 0);
		$('.arrowRightTC').css({display:'block'});
		if(actualSlide > -800){
			$('.arrowLeftTC').css({display:'none'});
		}
	});

	// Slide Index********************************************************************************************************************
	//Show the paging and activate its first link
	$(".pagingI").show();
	$(".pagingI a:first").addClass("activeI");

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidthI = $(".slideIndex").width();
	var imageSumI = $(".image_reelI img").size();
	var imageReelWidthI = imageWidthI * imageSumI;

	//Adjust the image reel to its new size
	$(".image_reelI").css({'width':imageReelWidthI});

	//Paging  and Slider Function
	rotateI = function(){
		var triggerIDI = $activeI.attr("rel") - 1; //Get number of times to slide
		var image_reelPositionI = triggerIDI * imageWidthI; //Determines the distance the image reel needs to slide

		$(".pagingI a").removeClass('activeI'); //Remove all active class
		$activeI.addClass('activeI'); //Add active class (the $active is declared in the rotateSwitch function)

		//Slider Animation
		$(".image_reelI").animate({
			left: -image_reelPositionI
		}, 500 );
	};

	//Rotation  and Timing Event	
	rotateSwitchI = function(){
		playI = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
			$activeI = $('.pagingI a.activeI').next(); //Move to the next paging
			if ( $activeI.length == false) { //If paging reaches the end...
				$activeI = $('.pagingI a:first'); //go back to first
			}
			rotateI(); //Trigger the paging and slider function
		}, 5000); //Timer speed in milliseconds (7 seconds)
	};

	rotateSwitchI(); //Run function on launch

	$(".image_reelI img").hover(function(){
		clearInterval(playI); //Stop the rotation
		}, function(){
			rotateSwitchI(); //Resume rotation timer
		}
	);

	//On Click
	$(".pagingI a").click(function(){
		$activeI = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(playI); //Stop the rotation
		rotateI(); //Trigger rotation immediately	
		rotateSwitchI(); // Resume rotation timer
		return false; //Prevent browser jump to link anchor
	});

	// Slide Index Desarrollos********************************************************************************************************************
	//Show the paging and activate its first link
	$(".pagingD").show();
	$(".pagingD a:first").addClass("activeD");

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidthD = $(".slideDesarrollos").width();
	var imageSumD = $(".image_reelD img").size();
	var imageReelWidthD = imageWidthD * imageSumD;

	//Adjust the image reel to its new size
	$(".image_reelD").css({'width':imageReelWidthD});

	//Paging  and Slider Function
	rotateD = function(){
		var triggerIDD = $activeD.attr("rel") - 1; //Get number of times to slide
		var image_reelPositionD = triggerIDD * imageWidthD; //Determines the distance the image reel needs to slide

		$(".pagingD a").removeClass('activeD'); //Remove all active class
		$activeD.addClass('activeD'); //Add active class (the $active is declared in the rotateSwitch function)

		//Slider Animation
		$(".image_reelD").animate({
			left: -image_reelPositionD
		}, 500 );
	};

	//Rotation  and Timing Event	
	rotateSwitchD = function(){
		play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
			$activeD = $('.pagingD a.activeD').next(); //Move to the next paging
			if ( $activeD.length == false) { //If paging reaches the end...
				$activeD = $('.pagingD a:first'); //go back to first
			}
			rotateD(); //Trigger the paging and slider function
		}, 4000); //Timer speed in milliseconds (7 seconds)
	};

	rotateSwitchD(); //Run function on launch

	$(".image_reelD img").hover(function(){
		clearInterval(play); //Stop the rotation
		}, function(){
			rotateSwitchD(); //Resume rotation timer
		}
	);

	//On Click
	$(".pagingD a").click(function(){
		$activeD = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotateD(); //Trigger rotation immediately	
		rotateSwitchD(); // Resume rotation timer
		return false; //Prevent browser jump to link anchor
	});

	// Slide de imagenes Bienvenido a casa********************************************************************************************************************
	//Show the paging and activate its first link
	$(".pagingBc").show();
	$(".pagingBc a:first").addClass("activeBc");

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidth = $(".slideBienvenidoACasa").width();
	var imageSum = $(".image_reelBc img").size();
	var imageReelWidth = imageWidth * imageSum;

	//Adjust the image reel to its new size
	$(".image_reelBc").css({'width':imageReelWidth});

	//Paging  and Slider Function
	rotateBc = function(){
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".pagingBc a").removeClass('activeBc'); //Remove all active class
		$active.addClass('activeBc'); //Add active class (the $active is declared in the rotateSwitch function)

		//Slider Animation
		$(".image_reelBc").animate({
			left: -image_reelPosition
		}, 500 );
	};

	//Rotation  and Timing Event	
	rotateSwitchBc = function(){
		playBc = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
			$active = $('.pagingBc a.activeBc').next(); //Move to the next paging
			if ( $active.length == false) { //If paging reaches the end...
				$active = $('.pagingBc a:first'); //go back to first
			}
			rotateBc(); //Trigger the paging and slider function
		}, 4000); //Timer speed in milliseconds (7 seconds)
	};

	rotateSwitchBc(); //Run function on launch

	$(".image_reelBc a").hover(function(){
		clearInterval(playBc); //Stop the rotation
		}, function(){
			rotateSwitchbC(); //Resume rotation timer
		}
	);

	//On Click
	$(".pagingBc a").click(function(){
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(playBc); //Stop the rotation
		rotateBc(); //Trigger rotation immediately	
		rotateSwitchBc(); // Resume rotation timer
		return false; //Prevent browser jump to link anchor
	});

	// Slide de imagenes Prototipo********************************************************************************************************************
	//Show the paging and activate its first link
	$(".pagingP").show();
	$(".pagingP a:first").addClass("activeP");

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidthP = $(".slidePrototipo").width();
	var imageSumP = $(".image_reelP img").size();
	var imageReelWidthP = imageWidthP * imageSumP;

	//Adjust the image reel to its new size
	$(".image_reelP").css({'width':imageReelWidthP});

	//Paging  and Slider Function
	rotateP = function(){
		var triggerIDP = $activeP.attr("rel") - 1; //Get number of times to slide
		var image_reelPositionP = triggerIDP * imageWidthP; //Determines the distance the image reel needs to slide

		$(".pagingP a").removeClass('activeP'); //Remove all active class
		$activeP.addClass('activeP'); //Add active class (the $active is declared in the rotateSwitch function)

		//Slider Animation
		$(".image_reelP").animate({
			left: -image_reelPositionP
		}, 500 );
	};

	//On Click
	$(".pagingP a").click(function(){
		$activeP = $(this); //Activate the clicked paging
		rotateP(); //Trigger rotation immediately	
		return false; //Prevent browser jump to link anchor
	});

	// Slide de imagenes Amenidades********************************************************************************************************************
	//Show the paging and activate its first link
	$(".pagingA").show();
	$(".pagingA a:first").addClass("activeA");

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidthA = $(".slideAmenidades").width();
	var imageSumA = $(".image_reelA img").size();
	var imageReelWidthA = imageWidthA * imageSumA;

	//Adjust the image reel to its new size
	$(".image_reelA").css({'width':imageReelWidthA});

	//Paging  and Slider Function
	rotateA = function(){
		var triggerIDA = $activeA.attr("rel") - 1; //Get number of times to slide
		var image_reelPositionA = triggerIDA * imageWidthA; //Determines the distance the image reel needs to slide

		$(".pagingA a").removeClass('activeA'); //Remove all active class
		$activeA.addClass('activeA'); //Add active class (the $active is declared in the rotateSwitch function)

		//Slider Animation
		$(".image_reelA").animate({
			left: -image_reelPositionA
		}, 500 );
	};

	//On Click
	$(".pagingA a").click(function(){
		$activeA = $(this); //Activate the clicked paging
		rotateA(); //Trigger rotation immediately	
		return false; //Prevent browser jump to link anchor
	});

	// Slide de imagenes Acabados********************************************************************************************************************
	//Show the paging and activate its first link
	$(".pagingAc").show();
	$(".pagingAc a:first").addClass("activeAc");

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidthAc = $(".slideAcabados").width();
	var imageSumAc = $(".image_reelAc img").size();
	var imageReelWidthAc = imageWidthAc * imageSumAc;

	//Adjust the image reel to its new size
	$(".image_reelAc").css({'width':imageReelWidthAc});

	//Paging  and Slider Function
	rotateAc = function(){
		var triggerIDAc = $activeAc.attr("rel") - 1; //Get number of times to slide
		var image_reelPositionAc = triggerIDAc * imageWidthAc; //Determines the distance the image reel needs to slide

		$(".pagingAc a").removeClass('activeAc'); //Remove all active class
		$activeAc.addClass('activeAc'); //Add active class (the $active is declared in the rotateSwitch function)

		//Slider Animation
		$(".image_reelAc").animate({
			left: -image_reelPositionAc
		}, 500 );
	};

	//On Click
	$(".pagingAc a").click(function(){
		$activeAc = $(this); //Activate the clicked paging
		rotateAc(); //Trigger rotation immediately	
		return false; //Prevent browser jump to link anchor
	});
	
 
});

//Funciones generales*****************************************************************************************************************************************
function goBack(){
  window.history.back()
}

