
$(document).ready(function () {
	//arreglaIEBug();
	$('a[rel*=external][href]').click(function() {
		window.open(this.href);
		return false;
	});
	if ($.datepicker) {
		$('.'+$.datepicker.markerClassName).removeClass($.datepicker.markerClassName);
		$(".hasDatePicker").removeClass(".hasDatePicker");
		$(".cal_inicio, .cal_fin").unbind();
		iniciarDatePicker();
	}
	$(".abreOcupacion").click(function() {
		$(this).parent().parent().find(".ocupaciones").slideToggle();
	});
	$("#offers_destinos ul li a").click(function() {
		$("#offers_destinos ul li a").removeClass("active");
		$(this).addClass("active");
		$("#tbPlaya, #tbMontana").hide();
		$("#"+$(this).attr("rel")).show();
	});
	$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 5000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 900,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
	});
	$("#slide-jump").click(function(){
		$('.anythingSlider').anythingSlider(6);
	});
	fancy();
});
function fancy() {
	$("a.fancybox").fancybox({
		'autoScale'     	: false,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
}
function iniciarDatePicker() {
	$(".cal_inicio, .cal_fin").datepicker({
		beforeShow: verificaRango,
		numberOfMonths: 2
	});
	$(".cal").datepicker();
}
function verificaRango(campo) {
	var antelacion = 0;
	var minimo = null;
	var maximo = null;
	var act = new Date();
	var inicio = $(campo).hasClass("cal_inicio") ? campo : ($(this).siblings(".cal_inicio").length ? $(this).siblings(".cal_inicio") : $(this).parent().siblings().find(".cal_inicio"));
	var fin =  $(campo).hasClass("cal_fin") ? campo : ($(this).siblings(".cal_fin").length ? $(this).siblings(".cal_fin") : $(this).parent().siblings().find(".cal_fin"));
	var campo_inicio = $(inicio).attr("value")!="" ? diaMesAnoDateSumaDia($(inicio).datepicker("getDate"), antelacion) : null;
	if ($(campo).hasClass("cal_inicio")) {
		var minimo = diaMesAnoDateSumaDia(act, antelacion);
		var maximo = null;
	} else {
		var minimo = campo_inicio;
	}
	return {
		minDate: minimo,
		maxDate: maximo
	};
}
function diaMesAnoDate(fecha) {
	if (fecha) {
		var t = fecha.split("/");
		return new Date(t[2],t[1]-1,t[0]);
	} else {
		return null;
	}
}
function diaMesAnoDateSumaDia(act, dias) {
	act.setDate(act.getDate()+dias);
	return act;
}
function formatText(index, panel) {
	return index + "";
}

function arreglaIEBug() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
}
