$(function() {
	//Documentation located in special.docs.js
	
	$('#content h1').sifr(
		{ strSWF: '/flash/avenir-45.swf', strColor: '#ffffff', strLinkColor: '#ffffff', strHoverColor: '#ffffff', strWmode: 'transparent', intPadding: [0, 0, 0, 0], strFlashVars: 'textalign=left&', strCase: 'upper' },
		{ expressInstall: true }
	);
	
	// Flash
	$('#home-masthead').each(function(){
		var xmlfile = $(this).attr("title");
		$(this).html('').flash({
			swf:"/flash/homepage.swf",
			width:"2000",
			height:"696",
			params:{
				allowscriptaccess:"always",
				wmode:"transparent",
				flashvars:{
					xmlPath:'/flash/xml/'+ xmlfile + '.xml'
				}
			}
		});
	});
	
	$('#photo-gallery').each(function(){
		var albumid = $(this).attr("title");
		$(this).html('').flash({
			swf:"/flash/gallery.swf",
			width:"884",
			height:"526",
			params:{
				allowscriptaccess:"always",
				wmode:"transparent",
				flashvars:{
					xmlPath:'/flash/xml/images.xml',
					curAlbum:albumid
				}
			}
		});
	});
	
	/* Blog JS */
	// Archives month select for the blog page
	
	$("form#select-month").each(function(){
		var x = $(this);
		var selectedMonth = $("select#month").val();
        selectedMonth = selectedMonth.split('|',2);
		$('input[name="month"]',x).attr("value",selectedMonth[0]);
        $('input[name="year"]',x).attr("value",selectedMonth[1]);
		$("select",x).change(function(){
            var selectedMonth2 = $("select#month").val();
            selectedMonth2 = selectedMonth2.split('|',2);
            $('input[name="month"]',x).attr("value",selectedMonth2[0]);
            $('input[name="year"]',x).attr("value",selectedMonth2[1]);
		});
	});
	
	$(".form-help").each(function(){
		$(this).hide();
		$(".help-link").toggle(function(){
			$('.form-help',$(this).parents('.field')).show();
		}, function() {
			$('.form-help',$(this).parents('.field')).hide();
		});
	});
	
	
	$('#special-offers-signup #email').each(function(){
		var defaulttxt = "enter email address here";
		$('#special-offers-signup #email').each(function(){
			$(this).val(defaulttxt);
			$(this).focus(function(){
				if($(this).val() == defaulttxt ){
					$(this).val("");
				}
			});
			$(this).blur(function(){
				if ($(this).val() == ""){
					$(this).val(defaulttxt);
				}
			});
		});
	});
	
	/* Home page push marketing cycle */
	/* expand and collapse the offer */
	$("#home-push .toggle").toggle(function(){
		$(this).addClass("active");
		$(this).parents('#home-push').find('.hp-content-more').show();
		
	}, function() {
		$(this).removeClass("active");
		$(this).parents('#home-push').find('.hp-content-more').hide();
	});

	
	/* show the first item on load */
	$('#home-push ul li:first').show();
	
	/* move to the next offer */
	$('#next-offer').click(function(event){
		event.preventDefault();
		var active = $(this).parent().find('ul li:visible');
		active.hide();
		if($(active).next().length){
			$(active).next().show();
			
		} else {
			$(active).parent().find('li:first').show();
		}
	});
	
	//Toggle reservations promot
	$('#promo-toggle').toggle(function(){
		$('#promo-fields').show();
	}, function(){
		$('#promo-fields').hide();
	});
	
	//Hide extended press images and append link
	$('ul#press-photos li:gt(5)').hide();
	$('#photo-gallery-toggle').toggle(function(){
		$('ul#press-photos li:gt(5)').show();
		$(this).html('View Less Photos');
	}, function(){
		$('ul#press-photos li:gt(5)').hide();
		$(this).html('View All Photos');
	});
	
	$('.default').each(function(){
		var defaulttxt = $(this).val();
		$(this).focus(function(){
			$(this).val('');
		});
		$(this).blur(function(){
			if($(this).val() == ""){
				$(this).val(defaulttxt);
			}
		});
	});
	
	//Calculating width for tabs
	$('.tab-navigation').each(function(){
		var listwidth = $(this).outerWidth();
		var tabcount = $('li',this).length;
		// minus and plus ones are to accomodate for border in a very not-flexible way
		var tabwidth = ((listwidth - (listwidth % tabcount)) / tabcount)-1; 
		$('li',this).css('width',tabwidth);
		$('li:last',this).css('width',(tabwidth+(listwidth % tabcount)+1));
		
	});
	
	//Simple tabbing
	$('.tab-wrapper').hide();
	if($('.tab-navigation').length){
		if(window.location.hash) {
			var tabid = window.location.hash.split('#')[1];
			$('#'+tabid).show();
			$('a[href="#'+tabid+'"]').addClass("current");
		} else {
			$('.tab-navigation li a:first').addClass("current");
			$('.tab-wrapper:first').show();	
		}
	}
	$('.tab-navigation li a').click(function(event){
		event.preventDefault();
		$('.tab-wrapper:visible').hide();
		$('.tab-navigation li a').removeClass("current");
		var tabid = $(this).attr('href').split('#')[1];
		$('#'+tabid).show();
		$('a[href="#'+tabid+'"]').addClass("current");
	});

	$('a.video-launch').click(function(e){
		e.preventDefault();
		var albumid = $(this).attr("id");
		$('#video-embed').html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="320" id="'+ albumid +'" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="/flash/'+ albumid +'.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="/flash/'+ albumid +'.swf" quality="high" bgcolor="#ffffff" width="480" height="320" name="'+ albumid +'" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /></object>');
	});
	
	var videoopenFn=function(hash){
		hash.w.show();
	};

	var videohideFn=function(hash){
		$("div#video-embed").html('');
		$("div#video-embed embed").remove();
		$("div#video-embed object").remove();
		hash.w.hide();
		hash.o.remove();
	};

	$('#press-video').jqm({trigger: 'a.video-launch', onShow: videoopenFn, onHide: videohideFn});


	
});
