// Plugins JQuery.

// Vertical Align.
(function ($) {
	$.fn.vAlign = function(container) {
		return this.each(function(i){
			if(container == null) {
				container = 'div';
			}
			$(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
			var el = $(this).children(container + ":first");
			var elh = $(el).height(); //new element height
			var ph = $(this).height(); //parent height
			var nh = (ph - elh) / 2; //new height to apply
			$(el).css('margin-top', nh);
		});
	};
})(jQuery);

// Preloader de "Send Content".
var sendContent = function() {
	xajax.dom.create("loading","div", "loading");
  	xajax.$('loading').innerHTML='<div class="procesando"><img src="img/loading_form.gif" width="39" height="13" class="middle loading" alt=""/></div>';
}

// Preloader de "Plan your wedding".
var sendPlanWedding = function() {
	xajax.dom.create("form_loading","div", "form_loading");
  	xajax.$('form_loading').innerHTML='<div class="procesando"><img src="img/loading_form.gif" width="39" height="13" class="middle loading" alt=""/></div>';
}

// Preloader de "Plan an event".
var sendPlanEvent = function() {
	xajax.dom.create("form_loading","div", "form_loading");
  	xajax.$('form_loading').innerHTML='<div class="procesando"><img src="img/loading_form.gif" width="39" height="13" class="middle loading" alt=""/></div>';
}

// Preloader de "How to book".
var sendHowToBook = function() {
	xajax.dom.create("form_loading","div", "form_loading");
  	xajax.$('form_loading').innerHTML='<div class="procesando"><img src="img/loading_form.gif" width="39" height="13" class="middle loading" alt=""/></div>';
}

// Funcion para seleccionar un elemento del footer.
function footerSection(ID_seccion){
	
	$(document).ready(function(){
							   
		var text_link = $(".footer_navigation li").eq(ID_seccion - 1).text();
		$(".footer_navigation ul li").eq(ID_seccion - 1).addClass("selected").find("a").replaceWith('<span>'+ text_link +'</span>');
	
	});	

}

// Rotacion de header.
function slideShowHeader(){
	
	$(document).ready(function(){
		
		// Detengo la rotacion del header.
		$('#banners').hover(function(){
			clearInterval(0);							 
		});
						
		// Header interno.
		$('#banners').jqFancyTransitions({effect: 'wave', direction: 'random', width: 930, height: 213, delay: 1000});	
	
	});	

}

// Rotacion del header del home.
function slideShowHome(){
	
	$(document).ready(function(){
							   
		// Home.
		$('#banners').jqFancyTransitions({effect: 'wave', direction: 'random', width: 930, height: 437, delay: 4000});	
	
	});	

}

// Funcion para enviar el contenido.
function comprueba_enviar (ID_busqueda, valor) {

	if(document.getElementById(ID_busqueda).value == ''){
		document.getElementById(ID_busqueda).value = 'Your em@il here';	
	} else{
		if(document.getElementById(ID_busqueda).value == 'Your em@il here'){
			document.getElementById(ID_busqueda).value = '';
		} else {
			document.getElementById(ID_busqueda).value = valor;	
		}
	}

}

// DOM Ready General.
$(document).ready(function(){
						   
	// Counters.
	$(".been_there span").css("opacity","0");
	$(".been_there").click(function(){
		if($(this).find("span").attr("class") == "selected"){
			$(this).find("span").stop().animate({opacity: 0}, 250).removeClass("selected");
		} else {									
			if($(this).find("span").css("opacity") != "1"){
				$(this).find("span").stop().animate({opacity: 1}, 500).animate({opacity: 1}, 1000).animate({opacity: 0}, 500);
			} else {
				$(this).find("span").stop().animate({opacity: 0}, 250);
			}
		}
		
	});

	// Menu.
	$(".menu span").css("opacity","0");
	$(".submenu div").css("opacity","0");	
	$(".menu li").hover(function(){
		var submenu = "#" + $(this).find("span").attr("id") + "_submenu";								 
		if(submenu != "#_submenu"){
			//$(submenu).animate({width: "show"}, 500);
			$(submenu).show();					
		}
		$(this).find("span").stop().animate({opacity: 1}, 150, function(){
			$(submenu).find("div").animate({opacity: 1}, 150).show();																		
		});		
	}, function(){
		$(".submenu div").animate({opacity: 0}, 150).hide();
		$(this).find("span").stop().animate({opacity: 0}, 150);
		//$(".submenu").animate({width: "hide"}, 150);
		$(".submenu").hide();		
		$(".submenu div").stop();
	});
	
	// Home.
	$(".contact_us ul li").hover(function() {
		$(this).find(".contact_method").show();
	}, function() {
		$(this).find(".contact_method").hide();
	});
	
	// Formulario enviar contenido.
	$("#send_form_content").click(function(){
		$("#text_mensaje span.form_error, #text_mensaje span.success_form").fadeOut(500);
		xajax_sendContent(xajax.getFormValues('form_send_content'));		
	});
	
	// Facilities.
	$(".bg_window_installation").each(function(){
		var altura_ventana = ($(this).parent().height()) - 164;
		$(this).parent().find(".bottom_window_installation").height(altura_ventana);
	});
	
	// Spa.
	$(".spa .spa_services .service .right_service").vAlign();
	
	// Vallarta.
	$(".bg_window_feature").each(function(){
		var altura_ventana = ($(this).parent().height()) - 164;
		$(this).parent().find(".bottom_window_feature").height(altura_ventana);
	});	
	
	// Gallery.
	$("#mosaic li img").hover(function(){
		$(this).animate({opacity: 1}, 100);									   
	}, function () {
		$(this).animate({opacity: .8}, 100);									   
	});
	
	$(".wrapper_photo_gallery #mosaic li").each(function(index){
		if((index + 1) % 8 == 0){
			$(this).addClass("no_margin_right");
		}
		
	});
	
    $('.rollover').hover(function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    }, function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    });
	
	// Formulario enviar el formulario de "Plan your wedding".
	$(".send_us").click(function(){
		$("#text_message span.form_error_message, #text_message span.success_form_message").fadeOut(500);
		xajax_sendPlanWedding(xajax.getFormValues('form_plan_wedding'));		
	});
	
	// Formulario enviar el formulario de "Plan an event".
	$(".send_us_event").click(function(){
		$("#text_message span.form_error_message, #text_message span.success_form_message").fadeOut(500);
		xajax_sendPlanEvent(xajax.getFormValues('form_plan_event'));		
	});	
	
	// Formulario enviar el formulario de "How to book".
	$(".send_us_how_to_book").click(function(){
		$("#text_message span.form_error_message, #text_message span.success_form_message").fadeOut(500);
		xajax_sendHowToBook(xajax.getFormValues('form_how_to_book'));		
	});	
	
	// Experience.
	$(".interest .interest_content").each(function(){
		$(this).vAlign();										   
	});
	
});	
