function prepareDocument(){
	// initialize scrollable
    $(".scrollable").scrollable();
	
	$(".items img").click(function() {
	    // see if same thumb is being clicked
	    if ($(this).hasClass("active")) { return; }
		
	    // calculate large image's URL based on the thumbnail URL (flickr specific)
	    var url = $(this).attr("src").replace("_thumbnail", "_medium");
	    // get handle to element that wraps the image and make it semi-transparent
	    var wrap = $("#image_wrap").fadeTo("medium", 0.5);
	    // the large image from www.flickr.com
	    var img = new Image();
	    // call this function after it's loaded
	    img.onload = function() {
	        // make wrapper fully visible
	        wrap.fadeTo("fast", 1);
	        // change the image
	        wrap.find("img").attr("src", url);
	    };
	    // begin loading the image from www.flickr.com
	    img.src = url;
	    // activate item
	    $(".items img").removeClass("active");
	    $(this).addClass("active");

        // when page loads simulate a "click" on the first image
    }).filter(":first").click();

    // Fill the date input field on date click
	$(".cal-day").live('click', function(){
		setto = $(this).attr("title");
		$("#id_date").val(setto)
	});
	
	// Clear the input fields on click and restore if needed
	//$("input[type='text']").clearInput();
	
	//Switch calendar contents with AJAX
	$(".cal_switch").live('click', function(){
		url = $(this).attr("title");
		$.get(url, function(data){
			$("#booking-calendar").html(data)
		})
	});
	
	//Validate the booking form
	/*$("form.booking").validate({
		rules: {
			id_name: {
				required: true,
				rangelength: [4, 30]
			},
			id_tel: {
                required: true,
                rangelength: [6, 20]
            },
			id_email: {
				required: true,
				email: true,
				rangelength: [4, 30]
			},
			id_date: {
				required: true,
				date: true
			}
		}
	});*/
}

$(document).ready(prepareDocument);
