//<![CDATA[

// Desarrollado por Julio loayza para stanque. noviembre 2010.

$(document).ready(function() {

	//$.fx.off = !$.fx.off;

	// Fix for IE7's lack of :focus pseudo-class

	$("a").mousedown(function() {
    	 this.blur();
	     this.hideFocus = true;
	     this.style.outline = 'none';
	});
	
	// 
	
	$("#reservation .date-selector").click(function() {
    
		$("#reservation fieldset.calendar").show();
		
		$("#reservation fieldset.date dd").css("visibility","hidden");
		
		$("#reservation fieldset.products").hide();
		
		loadCalendars($("#reservation-date").val());

		return false;

	});
	
	if($("body").hasClass("bienvenida")) {
		$('.galeria a').lightBox({fixedNavigation:true});
	}
	
	if($("body").hasClass("interior")) {
	
		$(".galeria .mini a").click(function() {
		
			$(this).parent().parent().parent().parent().find(".imagen-principal img").attr("src", $(this).attr("href"));
			
			return false;
		
		});
	
	}

});


$(document).ready(function() {

    function staticNav() {
        var sidenavHeight = $("#navigation-level-2").height(); //Get height of sidenav
        var winHeight = $(window).height(); //Get height of viewport
        var browserIE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false; //Check for IE6

        if (browserIE6) { //if IE6...
            $("#sidenav").css({'position' : 'absolute'});  //reset the sidenav to be absolute
        } else { //if not IE6...
            $("#sidenav").css({'position' : 'fixed'}); //reset the sidenav to be fixed
        }

        if (sidenavHeight > winHeight) { //If sidenav is taller than viewport...
            $("#sidenav").css({'position' : 'static'}); //switch the fixed positioning to static. Say good bye to sticky nav!
        }
    }

    staticNav(); //Execute function on load

    $(window).resize(function () { //Each time the viewport is adjusted/resized, execute the function
        staticNav();
    });

});

// 

function loadCalendars(date, url) {

	if (date != null) {
	
		if ($("#reservation-date").val() == "" || $("#reservation-date").val() == "dd/mm/aaaa" || $("#reservation-date").val() == "dd/mm/yyyy") {
		
			$("#calendar-container").load("../stanquecms/modulos/gestion_de_reservas/libs/calendario.asp?idioma=" + $("#language-input").val(), function() {
			  functionalityToMonthNav();
			});	
		
		} else {
		
			$("#calendar-container").load("../stanquecms/modulos/gestion_de_reservas/libs/calendario.asp?idioma" + $("#language-input").val() + "&fecha_reserva=" + $("#reservation-date").val() + "&pos_calendario=" + $("#current-calendar-input").val(), function() {
			  functionalityToMonthNav();
			});	
		
		}
	
	} else {
		
		$("#calendar-container").load(url, function() {
			functionalityToMonthNav();
		});	

	}

}

function escribirFecha(date, field, what, period_id, language_id, calendar_number) {

	$("#" + field).val(date);
	
	$("#current-calendar-input").val(calendar_number);
	
	$("#reservation fieldset.calendar").hide();

	$("#reservation fieldset.date dd").css("visibility","visible");

	// si ya hay un periodo asignado y es diferente al nuevo periodo cargamos nuevos productos
	
	if (($("#current-period-id-input").val() != "") && ($("#current-period-id-input").val() != period_id.toString())) {

		$.get("../stanquecms/modulos/gestion_de_reservas/libs/periodo.asp?id_periodo=" + period_id + "&idioma=" + $("#language-input").val(), function(data) {
		
			$("#reservation fieldset.products").replaceWith(data);
			  
			$("#current-period-id-input").val(period_id);
			
			$("#reservation fieldset.products").slideDown();

		});

	} else {
	
		$("#current-period-id-input").val(period_id);
		
		$("#reservation fieldset.products").slideDown();

	}

} 

function functionalityToMonthNav() {

	$("#reservation .go-to-previous-month").click(function() {
	
		loadCalendars(null, $(this).attr("href"));
		return false;

	});

	$("#reservation .go-to-next-month").click(function() {

		loadCalendars(null, $(this).attr("href"));
		return false;

	});

}


// Funciones temporales para emular el aviso de carga de datos

function showDataLoadMessage() {
	$("#overlay").show();
	$("#lightbox").show();
}

function hideDataLoadMessage() {
	$("#overlay").hide();
	$("#lightbox").hide();
}

//]]>

