function closePrettyPhoto() {
	jQuery.prettyPhoto.close();
}

$(function() {

	$("a[href*='popup_']").click(function(){
		var $href = $(this).attr('href');
		var $new_href = $href.replace('popup_','/layout/set/blank/');
		window.open($new_href,'newwin','menubar=0,status=0,toolbar=0,location=0,resizable=1,scrollbars=1,width=600', 'alwaysRaised');
		return false;
	});

	$("a.photos").click(function() {
		var $e = $(this);
		if (!$e.data("running")) {
			$e.data("running", true).closest(".gallery_controls").find(".thumbnails").slideToggle(300, function() {
				$e.removeData("running");
			});
		}
		return false;
	});

	$("form.quick_reservations :text").each(function() {
		var $e = $(this), p = "placeholder";
		$e.data("default", $e.attr(p)).val($e.attr(p)).removeAttr(p);
	}).focus(function() {
		var $e = $(this);
		if ($e.val() === $e.data("default")) { $e.val(""); }
	}).blur(function() {
		var $e = $(this);
		if (!$e.val()) { $e.val($e.data("default")); }
	});

	var setup = {
		slideshow: function() {
			$(".gallery .slides").cycle({
				fx: "fade",
				speed: 2000,
				timeout: 5000,
				pause: 1,
				pauseOnPagerHover: 1,
				pager: ".gallery_controls ul",
				pagerEvent: 'mouseover',
				pagerAnchorBuilder: function(i, slide) {
					return ".gallery_controls li:eq(" + i + ") a";
				}
			});
			return this;
		},
		body: function() {
			var $body = $("body#index");
			$body.css({ overflow: ($body.css("overflow") === "hidden") ? "visible" : "hidden" });
			return this;
		},
		nav: function() {
			$("nav#primary").toggle();
			return this;
		}
 	};
	setup.beforeModal = function() { setup.body().nav(); };
	setup.afterModal = function() { setup.body().slideshow().nav(); }

	if( $.cookie( 'visitortype') ) {
		$("#modal,#modal_layer").remove();
		setup.slideshow();
	}

	$("#modal").each(setup.beforeModal);
	$("#modal a.btn_leisure").click(function() {
		$("#modal, #modal_layer").fadeOut(500);
		$.cookie('visitortype','leisure');
		//setup.afterModal();
		//return false;
	});
	$("#modal a.btn_business").click(function() {
		// wrap fadeOut in callback function when Ajax call written in
		$("#modal, #modal_layer").fadeOut(500);
		$.cookie('visitortype','business');
		setup.afterModal();
		return false;
	});

	//$("body#index").each(setup.beforeModal).each(setup.afterModal);  

	$("#modal span").hide().delay(3000).fadeIn().animate({
		left: '+=500'
	}, 5000, function() {
	});

	//$(".slideshow figure:nth-child(2)").css("height",160);
	var slideShow = (function($ss) {
		$ss.cycle({
			fx: "fade",
			speed: 1200,
			timeout: 3000,
			pager: $ss.closest(".slideshow").find("ul"),
			pagerEvent: 'mouseover',
			pagerAnchorBuilder: function(i) {
				return '<li><a href="'+ $ss.closest(".slideshow").find(".slides").children(":eq("+i+")").children("a").attr("href") +'">' + i + '</a></li>';
			}
		});
	})($(".slideshow .slides"));

	$(".more_content").hide();
	$("p.more a, a.more").click(function() {
		var $e = $(this);
		$e.text((/more/.test($e.text())) ? $e.text().replace("more", "less") : $e.text().replace("less", "more"));
		$e.closest("p").prev(".more_content").slideToggle(300).end().closest("p").next(".more_content").slideToggle(300);
		return false;
	});

	$("#main figure").height( $("#main figure img").height() );  
	//$("#main figure").css("clear" : "both", "display" : "block", "line-height" : "0" ); 
	//Cufon.replace('header nav#secondary li a', { fontFamily: 'Lucida Grande' });
	Cufon.replace('header nav#primary > ul > li > a', { hover: true });
	Cufon.replace('header nav#primary > ul > li > ul li', { fontFamily: 'Lucida Grande' });
	Cufon.replace('a.button', { fontFamily: 'Century Gothic', textShadow: '1px 1px 1px rgba(0, 0, 0, 0.2)' });
	Cufon.replace('#subscribe input.button', { fontFamily: 'Century Gothic', textShadow: '1px 1px 1px rgba(0, 0, 0, 0.2)' });
	Cufon.replace('header nav#primary > ul > li > a', { fontFamily: 'Century Gothic' });
	Cufon.replace('form.quick_reservations h3', { fontFamily: 'Century Gothic', textShadow: '1px 1px 1px rgba(0, 0, 0, 0.5)' });
	Cufon.replace('form.quick_reservations p.lead_rate', { fontFamily: 'Century Gothic', textShadow: '1px 1px 1px rgba(0, 0, 0, 0.5)' });
	Cufon.replace('#content section.copy h1', { fontFamily: 'Century Gothic' });
	Cufon.replace('#content section.promos article figcaption', { fontFamily: 'Century Gothic', textShadow: '1px 1px 1px rgba(0, 0, 0, 0.5)' });
	Cufon.replace('.slideshow figure figcaption', { fontFamily: 'Century Gothic', textShadown: '1px 1px 1px rgba(0, 0, 0, 0.5)' });
	Cufon.replace('footer article .social_media p', { fontFamily: 'Century Gothic' });
	Cufon.replace('#main .heading h1', { fontFamily: 'Century Gothic' });
	Cufon.replace('#sidebar .special.lead_rate', { fontFamily: 'Century Gothic' });
	Cufon.replace('#main section.specials article .details .heading', { fontFamily: 'Century Gothic' });

	$('.promos article:not(.slideshow) figure').css({background: 'transparent'});
});

