$(document).ready(function(){
						   
	//book link
	$('#booknow').click(function(){
		$('#mask')
		.css({opacity: 0})
		.show()
		.animate({opacity: .5},function(){
			w=340; h=390; wh=$(window).height(); ww=$(window).width();
			leftPos=(ww-w)/2; topPos=(wh-h)/2;
			$('#booking').css({left: leftPos+"px", top: topPos+"px"}).show();
			$('#booking, #mask').click(function(){
				$('#booking').hide();
				$('#mask').animate({opacity: 0},function(){
					$(this).hide();
				});
			});
		});
	});
	
	
	//voucher form
	if($('form#voucherform').length>0) {
		
		$('form#voucherform').submit(function(){
			$.ajax({
				type: "post",
				url: "media/scripts/php/voucher.php",
				data: "name="+$('#vf_name').val()+"&email="+$('#vf_email').val()+"&telephone="+$('#vf_tel').val(),
				success: function(html){
					if(html.substr(0,5)!="error") {
						$('form#voucherform').parent().html("<p class='formreturn'>"+html+"</p>");
					} else {
						if($('.formreturn').length>0) {
							$('.formreturn').html(html);
						} else {
							$('form#voucherform').append("<p class='formreturn'>"+html+"</p>");
						}
					}
				}			
			});
			
			return false;
		});
	}
	

	//front Video
	if($('#video').length>0){
		$('#video')
			.flash({
			src: 'media/flash/video.swf',
			width: 540,
			height: 420,
			wmode: "transparent"
		}); 
	}
	
	//accordion
	if($('.accordion').length>0){
		$('.accordion').accordion();
	}
						   
	$('#container').centersite({type: "normal"});
	
	$(window).bind("resize", function(){
		$('#container').centersite({type: "normal"});
		backgroundPos();
	});

	//position lamp post
	backgroundPos();
	
	//navigation shadows
	$('#nav li a')
	.prepend('<span class=\"l\"></span>')
	.append('<span class=\"r\"></span>');
	
	//thumbnails
	if($('#images').length>0){
			var images = $('#images img');
			var thumbs = $('#thumbs');
			
			//make thumbs
			images.each(function(){
				thumbs
				.append("<a href=\"#\"><span></span><img src=\"" + $(this).attr('src') + "\" alt=\"\"/></a>")
				.animate({top: "-50px"});
			});
			
			//thumb events
			thumbs.children('a').click(function(){
				i=$(this).index();
				images
				.animate({opacity: 0},{queue:false})
				.eq(i)
				.animate({opacity: 1},{queue:false});
				clearInterval(imageFade);
			});
			
			images.animate({opacity: 0},{duration: 50}).eq(0).animate({opacity: 1},{duration: 50});
			//auto cycle images
			c=0;
			imageFade=setInterval(function(){
				if(c<images.length-1) c++; else c=0;
				images.animate({opacity: 0},{queue:false}).eq(c).animate({opacity: 1},{queue:false});
			}, 5000);
	}
	
	function backgroundPos(){
		ww=parseInt($(window).width()); wh=parseInt($(window).height()); cw=parseInt($('#container').width()); ch=parseInt($('#container').height());
		if(ww<cw) lp=-160; else lp=((ww-cw)/2)-160;
		if(wh<ch) tp=-160; else tp=((wh-ch)/2)-160;
		$('body').css("backgroundPosition", lp + "px " + tp + "px");
	}

});
