$(document).ready(function() {
	
	// BOOKMARK HOVER FUNCTION
	
	$("#bookmark").hover(function() {
		$("#social-networks").stop().fadeTo(500, 1.0);
	}, function() {
		$("#social-networks").stop().fadeTo(500, 0.0, function() {
			$("#social-networks").hide();
		});
	});
	
	$("#social-networks").hover(function() {
		$("#social-networks").stop().fadeTo(500, 1.0);
	}, function() {
		$("#social-networks").stop().fadeTo(300, 0.0, function() {
			$("#social-networks").hide();
		});		
	});
	
	// SHOW / HIDE BOOKING FORM
	
	$('#content-toggle').addClass('open');
	
	$("#content-toggle").click(function(){
		if($(this).hasClass('open')){
			$('.book-form').fadeOut(function(){
				$("#booking-form-container").animate({'top':'290px'},1000);
				$("#show-form").animate({'top':'290px'},1000);
				$('#show-form a').html('Show');
			});
			$(this).removeClass('open');
			
		} else {
			$('#show-form a').html('Hide');
			$("#show-form").animate({'top':'58px'},1000);
			$("#booking-form-container").animate({'top':'58px'},1000,function(){
				$('.book-form').fadeIn(500);
			});
			
			$(this).addClass('open');
		}
		return false;
	});
	
	// SHOW / HIDE ROOMS (EVENTS.PHP)
	
	$('.blue, .snug, .orangery').hide();
	
	$(".events-carousel a").click(function(e){
		e.preventDefault();								   
		var eventsarea = $(this).attr('id');
		$('.events-copy, .events-image').hide();
		$('.'+eventsarea).fadeIn(1000);
	});
	
	// CAROUSEL SCROLL
	
	function px2num(s) {
		return (s.substr(0, s.length - 2) * 1);
	}
	
	// resize #carousel-offers
	no_offers = $("#carousel-offers .carousel-offerbox").size();
	width_of_single_offer = px2num($(".carousel-offerbox").css("width")) + 
							px2num($(".carousel-offerbox").css("margin-left")) + 
							px2num($(".carousel-offerbox").css("margin-right"));
	
	$("#carousel-offers").css("width", (no_offers * width_of_single_offer)); 
	hide_show_arrows();

	function hide_show_arrows() {
		var current_left = px2num($("#carousel-offers").css("left"));
		var min_left = ( -1 * px2num($("#carousel-offers").css("width")) + 3 * width_of_single_offer );
		var max_left = 0;
		if (current_left >= max_left) {
			$("#arrow-left").hide();
		} else {
			$("#arrow-left").show();
		}
		
		if (current_left <= min_left) {
			$("#arrow-right").hide();
		} else {
			$("#arrow-right").show();
		}
	}
	
	$("#arrow-right").click(function() {
		var current_left = px2num($("#carousel-offers").css("left"));
		var min_left = ( -1 * px2num($("#carousel-offers").css("width")) + 3 * width_of_single_offer );
		if ( current_left >  min_left ) {
			var new_left = current_left - width_of_single_offer;
			new_left = Math.max(new_left, min_left);
			$("#carousel-offers").stop().animate({left: new_left}, 500, function() {hide_show_arrows();});
		} 
		
	});
	
	$("#arrow-left").click(function() {
		var current_left = px2num($("#carousel-offers").css("left"));
		if ( current_left < 0 ) {
			var new_left = px2num($("#carousel-offers").css("left")) + width_of_single_offer;
			new_left = Math.min(new_left, 0);
			$("#carousel-offers").stop().animate({left: new_left}, 500, function() {hide_show_arrows();});
		}
	});
	
	
	// DROPDOWN STYLING
	
/*	if (!$.browser.opera) {
		$('select.select, .gallery_selector select').each(function(){
			var title = $(this).attr('title');
			if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
			$(this)
				.css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
				.after('<span class="select">' + title + '</span>')
				.change(function(){
					val = $('option:selected',this).text();
					$(this).next().text(val);
					})
		});
	};
	
	$('select').each(function () {
		if($(this).hasClass('error')) {
			$(this).siblings('span.select').addClass('error-select');
		} 								   
	});*/
	 if ($('.gallery').size()>0) {
	  $('ul.gallery a').attr('rel','prettyPhoto[gallery]');
	  $("a[rel^='prettyPhoto']").prettyPhoto({
	      theme: 'facebook',
	      slideshow:5000,
	      autoplay_slideshow:true,
	      deeplinking: false
	  });
	};

});

// FIELD VALUE FOR ALL FORMS

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
