$(document).ready(function () {
	$("#topmenu div.item:not(.active)").hover(
		function () {
			$(this).stop();
			$(this).animate({'padding-top': '18px', top: '-10px'},'fast');
		},
		function () {
			$(this).stop();
			$(this).animate({'padding-top': '8px', top: '0px'},'fast');
		}
	);
	$("#topmenu div.item").click(function () {
		document.location.href = $(this).find("a").attr("href");
	}).css("cursor","pointer");

	$("#gallery div.selector div.item a").hover(
		function () {
			var marker = $("#gallery div.selector div.marker");
			marker.stop();
			var top = Math.round($(this).parent().prevAll("div.item").size() * 58);
			marker.animate({'top': top+"px"}, "fast");
		},
		function () {
			var marker = $("#gallery div.selector div.marker");
			marker.stop();
			var top = Math.round($("#gallery div.selector div.item.active").prevAll("div.item").size() * 58);
			marker.animate({'top': top+"px"}, "fast");
		}
	);

	$("#gallery div.selector div.item a").click(function (e) {
		e.preventDefault();
		$(this).parent().siblings().removeClass("active");
		$(this).parent().addClass("active");
		$("#gallery_img img.image").addClass("removing").fadeOut("slow", function () {
			$(this).remove();
		});
		var image = new Image();
		$(image).hide();
		image.onload = function() {
			$(image).fadeIn();
		};
		image.src = $(this).attr("rel2");
		$(image).addClass("image");
		$("#gallery_img div.img").append(image);
		$("#gallery_img div.img a.show").attr("href", $(this).attr("rel"));
	});

	$("#gallery_img a.show").fancybox();
	$("div.textmod div.img a.show").fancybox();
	$("div.table td a").fancybox();
	$("div.promociones div.l div.image a.show").fancybox();

	var nitems = $("#highlights div.item").size();
	var hheight = $("#highlights").height();
	var HITEM_HEIGHT = hheight - ((28*nitems)-2);
	$("#highlights div.item:first div.content").height(HITEM_HEIGHT+"px");
	$("#home #highlights p.head").click(function (e) {
		e.preventDefault();
		if ($(this).parent().is(".selected")) {
			return;
		}
		else {
			$("#highlights div.item.selected").removeClass("selected").find("div.content").animate({"height":"0"});
			$(this).parent().addClass("selected").find("div.content").animate({"height":HITEM_HEIGHT+"px"});
		}
	});

	$("div.table table td:first-child, div.table table th:first-child").addClass("first-child");

	$("#home #llegada").datepicker({
		dateFormat: 'dd/mm/yy',
		minDate: new Date(),
		onSelect: function(dateText, inst) {
			$("#home #salida").datepicker("option","minDate",$("#home #llegada").datepicker("getDate"));
		}

	});
	$("#home #salida").datepicker({
		dateFormat: 'dd/mm/yy',
		minDate: new Date()
	});
});

window.onload = function () {
	$("#container").prepend('<div id="cont-shadow"></div>');
	$("#cont-shadow").height($("#container").height() + 1);

	$("div.promociones div.block").each(function () {
		var n = $(this).prevAll("div.block").size() + 1;
		if (n % 2 == 0) {
			var h1 = $(this).prev().height();
			var h2 = $(this).height();
			if (h1 > h2) {
				$(this).height(h1);
			}
			else {
				$(this).prev().height(h2);
			}
		}
	});
}

function imaginanet(item) {
	if ($("#in_credits_cloned").size() > 0) {
		$("#in_credits_cloned").remove();
		return false;
	}
	var html=$("#in_credits").clone().attr("id","in_credits_cloned").prepend("<a class='close' href='#'>X</a>");
	html.css({
		position: "absolute",
		border: "#666 solid 1px",
		padding: "10px 15px",
		background: "#FFF",
		color: "#333",
		width: "140px",
		top: ($(item).offset().top - ($(item).height() + 22))+"px",
		left: ($(item).offset().left - (170 - $(item).width()))+"px",
		display: "block",
		"z-index": 1000
	}).find("a").css({
		color: "#333",
		"text-decoration": "none"
	}).end().find("a:first").css({
		position: "absolute",
		top: "2px",
		right: "2px",
		"text-decoration": "none",
		color: "#333"
	}).click(function (e) {
		e.preventDefault();
		html.remove();
	});
	$("body").append(html);
}
