$(document).ready(function() {
	
	$("body").addClass("js");
	
	// previous fair dropdown
	$("#subnav li.prev").mouseenter(function() {
		$(this).find("ul").show();
	}).mouseleave(function() {
		$(this).find("ul").hide();
	});
	
	// homepage map
	$("#map area").hover(function() {
		i = parseInt($(this).attr("class")) * -340;
		$("#map").css("background-position", "0 " + i + "px");
	}, function() {
		$("#map").css("background-position", "0 0");
	});
	
	// last classes
	$("#news-listing li:last").addClass("last");
	$(".content table tr:last").addClass("last");
	
	// news scroller
	scrollerUpdate = function(link) {
		$("#news-scroller-read").attr("href", link);
	}
	$("#news-scroller div").after('<a id="news-scroller-read" class="read" href="#">Read</a>').cycle({
		fx: "scrollUp",
		speed: 500,
		timeout: 5000,
		slideExpr: "p",
		pause: true,
		cleartype: true,
		cleartypeNoBg: true,
		after: function() {
			scrollerUpdate($(this).find("a").attr("href"));
		}
	});
	
	// subnav points
	$("#subnav li").each(function() {
		w = $(this).innerWidth() + 7;
		if($.browser.msie) { w -= 5; }
		if($(this).hasClass("prev")) { w -= 7; }
		$(this).find("span").width(w);
	});
	
	// feature buttons
	$("#features li").click(function() {
		window.location.href = $(this).find("a").attr("href");
	});
	
	// remove margin from last paragraph of each column
	$(".column").each(function() {
		$(this).find("p:last").addClass("last");
	});
	
	// align text with bottom of map on homepage
	$("#home-right").css("margin-top", 338 - $("#home-right").innerHeight());	
	
	// photos scroller
	$("#more a").click(function() {
		h = Math.ceil($("#multimedia li").length / 10) * 94;
		$("#multimedia ul").animate({ height: h + "px" }, "fast", function() {
			$("#more").slideUp("fast");
		});
		return false;
	});
	
	// multimedia fancybox
	$("#multimedia ul a").fancybox({
		titleShow: false,
		overlayColor: "#000",
		overlayOpacity: 0.8,
		centerOnScroll: true
	});
	
	// leaflet fancybox
	$(".page-prev .content-right a").fancybox({
		titleShow: false,
		overlayColor: "#000",
		overlayOpacity: 0.8,
		autoScale: false
	});
	
	// application - focus fields
	$(".application input, .application select, .application textarea").focus(function() { $(this).addClass("focus"); }).blur(function() { $(this).removeClass("focus"); });
	
	// application - dynamic total
	$(".application .total").show().find("td").eq(0).html("Total:");
	totalCalculate = function() {
		t = $("#totals").text().split(",");
		i = 0;
		tot = 0;
		$(".application .booking input").each(function() {
			if($(this).is(":checked")) {
				tot += parseFloat(t[i]);
			}
			i++;
		});
		$("#total").text("£" + tot.toFixed(2));
	}
	totalCalculate();
	$(".application .booking input").click(function() { totalCalculate(); })
	
	// application - payment fields show/hide
	$(".application #card, .application #bank").hide();
	paymentTypeChange = function() {
		s = $(".application #row_payment_type input:checked").attr("id");
		if(s=="id_payment_type_0") {
			$("#card").show();
			$("#bank").hide();
		} else if(s=="id_payment_type_1") {
			$("#card").hide();
			$("#bank").show();
		}
	}
	paymentTypeChange();
	$(".application #row_payment_type input").change(function() { paymentTypeChange(); });
	
	// application form - print link
	$(".application .print a").click(function() {
		window.print();
		return false;
	});
	
});
