$(document).ready(function(){
	//###############   PRETTYPHOTO, Zoom functionality throughout content   ###############
	$("a[rel^='prettyPhoto']").prettyPhoto({
		showTitle: false,
		counter_separator_label: " of "
	});

	//###############   Top menu   ###############
	$("ul.top-menu li .opener").parent().hoverIntent({
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
		interval: 100, // number = milliseconds for onMouseOver polling interval
		timeout: 50, // number = milliseconds delay before onMouseOut
		over: function() {
			$(this).children(".opener").addClass("ui-state-active");
			$(this).children(".slide").slideDown("normal");
		},
		out: function() {
			$(this).children(".opener").removeClass("ui-state-active");
			$(this).children(".slide").fadeOut();
		}
	});
	$("ul.top-menu .drop-items li").click(function() {
		window.location = $(this).find("a").attr("href");
	});

	//###############   Accordion for content screens (e.g. Kit)   ###############
	var JumpPoint = false;

	if (window.location.hash) { JumpPoint = "h3"+window.location.hash; }
	$("#accordion").accordion({
		autoHeight: false,
		active: JumpPoint,
		collapsible: true,
		change: function(event, ui) {
			$.scrollTo(ui.newHeader, {
				duration:750,
				offset:{left:0,top:-50}
			});
		}
	});

	//###############   Rollover image changes for Sponsors   ###############
	$("#sponsors img").hover(function() { 
		var src = $(this).attr("src").match(/[^\.]+/) + "-over.png";
		$(this).attr("src", src);
	}, function() {
		var src = $(this).attr("src").replace("-over", "");
		$(this).attr("src", src);
	});

	//###############   Contact Form Date Picker   ###############
	$("#contact-form #arrival-date").datepicker();

	//###############   Forms: Custom Checkboxes & Radio Buttons   ###############
	$("input[type=checkbox], input[type=radio]").prettyCheckboxes({
		checkboxWidth: 17,
		checkboxHeight: 17,
		className : 'prettyCheckbox',
		display: 'list'
	});

	//###############   Showing Booking Form   ###############
	if ($(".book-lesson-form:not(#bookings-page .book-lesson-form)").length > 0 ) {
		$(".book-lesson-form").hide().parent().find(".book-button a").toggle(function() {
			$(this).parent().fadeTo("slow", 0.5).parent().find(".book-lesson-form").fadeIn('slow');
			$.scrollTo('.book-lesson-form', {
				duration:750,
				offset:{left:0,top:-50}
			});
		}, function() {
			$(this).parent().fadeTo("slow", 1).parent().find(".book-lesson-form").fadeOut('slow');
			$.scrollTo('.book-lesson-form', {
				duration:750,
				offset:{left:0,top:-250}
			});
		});
	}

	if ($(".book-kit-form").length > 0 ) {
		$("#kit-prices").prev().find(".book-button a").click(function() {
			$.scrollTo('.book-kit-form', {
				duration:750,
				offset:{left:0,top:-150}
			});
		});
/*		$("#kit-prices").prev().find(".book-button a").toggle(function() {
			$("#kit-prices").fadeIn('slow');
			$.scrollTo('.book-kit-form', {
				duration:750,
				offset:{left:0,top:-150}
			});
		}, function() {
			$(this).parent().fadeTo("slow", 1);
			$("#kit-prices").fadeOut('slow');
		}); */
	}

	if ($(".book-clinic-form").length > 0 ) {
		$(".book-clinic-form").hide().parent().find(".book-button a").toggle(function() {
			$(this).parent().fadeTo("slow", 0.5).parent().find(".book-clinic-form").fadeIn('slow');
			$.scrollTo('.book-clinic-form', {
				duration:750,
				offset:{left:0,top:-200}
			});
		}, function() {
			$(this).parent().fadeTo("slow", 1).parent().find(".book-clinic-form").hide();
			$.scrollTo('.book-clinic-form', {
				duration:750,
				offset:{left:0,top:-300}
			});
		});
	}

	//###############   Login - Booking Side Module   ###############
	$(".sidebar #login-module").children().hide();
	$(".sidebar #login-module .book-button:first").show().click(function() {
		$(this).hide().nextAll(":not(.form-success)").fadeIn("slow");
	});

	//###############   Register - Show Form   ###############
	$("#register-form").hide().prev().prev().hide();
	$("#sign-in-page #show-register").show().click(function() {
		$(this).hide().next().fadeIn("slow");
		$("#register-form").fadeIn("slow");
		$.scrollTo("#register-form", {
			duration:750,
			offset:{left:0,top:-150}
		});
	});
	//###############   Update Details   ###############
	$("#change-password").show();
	$("#change-password-group").hide().find("input").attr("disabled","true")





	//###############   Tooltips (Gallery)   ###############
	if ($("#gallery-page .text-block .image-container .entry-rating").length > 0) {
		$("#gallery-page .text-block .image-container .entry-rating").tooltip({
			effect: 'slide',
			bounce:true,
			predelay: 200,
			position: 'bottom, center',
			events: {def: 'click, mouseout' },
			offset:[22, 0]
		});
	}
});


