$(function() {

	window.resizeSwf = function( size ) {
		if ( size == 46 ) {
			$("#flash-email-signup").css("height","46px").css('overflow','hidden');
		} else {
			$("#flash-email-signup").css("height","327px");
		}
	}

	$("#flash-email-signup").each(function(){
		var cookieval = $.cookie("flashcheck");
		var flashopen = true;
		if ( cookieval == "flashopened" ) {
			flashopen = false;
		}
		$(this).flash(
			{src:"/flash/email-form.swf",
			 width:228,
			 height:327,
			 name:"homeMasthead",
			 id:"homeMasthead",
			 wmode:"transparent",
			 quality:"high"},
			 {version:"9"},
				function(htmlOptions) { //Use this to specify a query string, take out if not needed.
					htmlOptions.flashvars.openOnLoad = flashopen;
					$(this).html($.fn.flash.transform(htmlOptions));
			});
		$.cookie("flashcheck", "flashopened", { expires: 7 });
	});
		   
	//Sifr
	$('div#subnav h3').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#926628', strWmode: 'transparent', strFlashVars: 'textalign=center&' },{ expressInstall: true });
	$('div#content h1').sifr({ strSWF: '/flash/hoefler-text.swf', strColor: '#4d2913', strWmode: 'transparent', strCase: 'upper', strFlashVars: 'letterSpacing=4&', fontSize:'54px' },{ expressInstall: true });
	$('div.content-item h3').sifr({ strSWF: '/flash/hoefler-text.swf', strColor: '#926426', strWmode: 'transparent', strCase: 'upper', strFlashVars: 'letterSpacing=2&' },{ expressInstall: true });
	$('div#weather-wrapper h4').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-home h4').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper h5').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-home h5').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-residence h4').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-residence h5').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-interior h4').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-interior h5').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-residence-interior h4').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper-residence-interior h5').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#4f2912', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });


	//Home Masthead
	$("#home-masthead").flash({src:"/flash/home-masthead.swf",width:1500,height:480,wmode:"transparent",quality:"high"},{version:"8"}, function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "/flash/xml/main-home-masthead.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});
	
	function ieResize() {
		if(BROWSER=='msie6') {
			var bwidth = document.documentElement.clientWidth;
			var bheight = parseInt(document.documentElement.clientHeight)-91;
			//alert (bheight + ' ' + bwidth);
			$('#home-masthead').css({height:bheight,width:bwidth});
		}
	}
	
	ieResize();
	window.onresize=function() {
		ieResize();				  
	}
	
	$("#residences-home-masthead").flash({src:"/flash/residences-home-masthead.swf",width:1286,height:481,wmode:"transparent",quality:"high"},{version:"8"}, function(htmlOptions) { 
			htmlOptions.flashvars.xmlPath = "/flash/xml/home-masthead.xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});
	
	var navid = $('ul#nav-primary').find('.current').attr("id");
	var secnavid = $('#'+navid).find('.current').attr("id");
	var ternavid = $('#subnav').find('li.current a').html();
	
	//console.log(ternavid);
	
	if (navid != undefined)
		navid = navid.substring(8);
	else
		navid = 'overview';
		
	if (secnavid != undefined)
		secnavid = secnavid.substring(10);
	else
		secnavid = 'main';
	if (ternavid != undefined)
	{
		ternavid = ternavid.split(" ");
		ternavid = ternavid[0].toLowerCase();
	} else {
		ternavid = '';
	}
	
	//console.log('ternavid: ' + ternavid);
	
	//This part is ghetto- i know. dont hate
	var prisecnavid= navid+'-'+secnavid;
	
	switch (prisecnavid) {
		//case 'aboutresidences-main':
		case 'aboutresidences-features':
		case 'aboutresidences-amenities':
			prisecnavid ='settagline';
		break;
		default:
		}
	if ((prisecnavid == 'accommodations-guestrooms' && ternavid != '') || (prisecnavid == 'accommodations-suites' && ternavid != '') )
	{
		navid = secnavid;
		secnavid = ternavid;
	}
	//if (prisecnavid == 'accommodations-suites' && ternavid != '')
	//{
		//navid = secnavid;
		//secnavid = ternavid;
	//}
	//alert(secnavid);
	//Interior Masthead
	
	$("#meeting-rooms-flash").flash(
		{src:"/flash/meetingmap.swf",
		 width:644,
		 height:453,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = '/flash/xml/meeting-map.xml';
				$(this).html($.fn.flash.transform(htmlOptions));
		});
	
	/*
	
#  the swf takes two flashVars: primary={} and secondary={}. these two variables need to be set to a string matching the filenames in the flash/assets/ folder (example below).
# flashvars example:
primary=overview&secondary=dome
*/
	
	
	//Submit button
	$('button#btn-submit').mouseover(function(){ $(this).css("background-position","-152px 0"); }
	).mouseout(function(){ $(this).css("background-position","0 0px"); });
	
	//Dropdown Nav
	if(BROWSER=='msie6') {
		$('#nav-primary li').hover(
			function() { $(this).addClass('over'); },
			function() { $(this).removeClass('over'); }
		)
	}
	
	// JQModal 
	
var openFn=function(hash){
		hash.w.show();
		$('#dialog').css({left:($(window).width()-$('#dialog').width())/2,top:$(window).scrollTop()+10});
		$('#home-masthead embed, #home-masthead object').hide();
		$('#homecarousel').cycle('pause')
	};
var openFn2=function(hash){
		hash.w.show();
		$('#dialog-residences').css({left:($(window).width()-$('#dialog-residences').width())/2,top:$(window).scrollTop()+10});
	};
var openFloorplan=function(hash){
		hash.w.show();
		$("#floorplan-content img").attr('src',hash.t.href);
		$('#floorplan-modal').css({left:($(window).width()-$('#floorplan-modal').width())/2,top:$(window).scrollTop()+100});
	};
	
var openFnMap=function(hash){

		hash.w.show();

		$('#map-modal').css({left:($(window).width()-$('#map-modal').width())/2,top:$(window).scrollTop()+10});
	};
	
var hideFn=function(hash){
		$("div#photo-gallery embed").remove();
		$('#home-masthead embed, #home-masthead object').show();
		$('#homecarousel').cycle('resume')
		hash.w.hide();
		hash.o.remove();
	};
	/*$("#msnmap").each(function() {
		$('#map-jqmodal').jqm({trigger:'#msnmap', onShow: openFn, onHide: hideFn});
	});*/
	
	$('#dialog-residences').jqm({ajax:'/includes/photo-gallery-residences.php', onShow: openFn2, onHide: hideFn, target:'div#photo-content'});

	
	$('#dialog').jqm({ajax:'../includes/photo-gallery.php', onShow: openFn, onHide: hideFn, target:'div#photo-content'});
	$('#dialog').jqmAddTrigger('li#secondary-photos a'); 
	$("#floorplan-modal").jqm({trigger:'a.floorplan', onShow: openFloorplan});
	
	$('#map-modal').jqm({ajax:'../includes/map.php', trigger: 'a#map-link', onShow: openFnMap, onHide: hideFn, target:'div#map-content'});
	$('#mbh-leed-info').hide();	
	 $('#mbh-leed').each(function() {
		$('#mbh-leed').toggle(function(){
			$('#mbh-leed-info').show();
		}, function() {$('#mbh-leed-info').hide(); });
		
	});
	
	// Close Button Highlighting. IE doesn't support :hover. Surprise?
	if($.browser.msie) {
		$('div.jqmAlert .jqmClose')
		.hover(
		function(){ $(this).addClass('jqmCloseHover'); }, 
		function(){ $(this).removeClass('jqmCloseHover'); });
	}
	
	/*
	$('.exec-team-long').hide();
	$('.exec-team').each(function() {
		
	
	
	});
	$('.exec-team').each(function(){
		var pTag = $('h4',this).next();
		if (pTag.html() == '') { pTag.hide(); }
		if ($('.exec-team-long',this).html() != '') {
			var toggleLink = $('<a/>').attr('href','#').text('Read More').toggle(function() {
					var el = $(this);
					el.html('Hide Details').parent().addClass('active').parent().find('.exec-team-long').slideDown('slow');
					return false;								   
				},function() { 
					var el = $(this);
					el.html('Read More');
					$('.exec-team-long').slideUp('slow');
					return false;								   
				});
			$('.exec-content',this).append(toggleLink);
		}
	});
	
	*/
	
	
	
	//executive team expand-collapse
	$('.exec-content').expand({openText: 'Read More', closeText: 'Hide Details', longClass: '.exec-team-long'});
	
		
	
	$('.person-extra').hide();
	$('a.person-toggle').toggle(function() {
		var el = $(this);
		el.html('Hide Details').parent().addClass('active').parent().find('.person-extra').slideDown('slow');
		return false;								   
	},function() { 
		var el = $(this);
		el.html('Read More');
		$('.person-extra').hide();
		return false;								   
	});

	$(".awards-div").each(function(){
      var x = $(this);
      $(".articles").hide();
      $(".awards-toggle-div",x).toggle(function(){
           $(".articles",x).slideDown();
           $(this).addClass("active").html("<em class='alt'>Hide Awards</em>");
      }, function() {
           $(".articles",x).slideUp().hide();
           $(this).removeClass("active").html("<em class='alt'>Show Awards</em>");
      });
	});
	
	// Ride the carousel...
    /*jQuery("#homecarousel").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });*/
	
	
	$('#homecarousel').after('<div id="control-links">').cycle({ 
		fx:     'fade', 
		speed:  800, 
		timeout: 5000, 
		next: '.next-link',
		pager:  '#control-links' 
	});
	
	$("#interior-masthead").flash(
		{src:"/flash/interior-masthead.swf",
		 width:1050,
		 height:338,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.primary = navid;
				htmlOptions.flashvars.secondary = secnavid;
				if (prisecnavid=='settagline') //if the tagline is specific for a page set this flashVars to true
					htmlOptions.flashvars.special = true;
				htmlOptions.flashvars.assetsFolder = '/flash/assets/';
				$(this).html($.fn.flash.transform(htmlOptions));
		});
	
	$(" body.residences #interior-masthead").flash(
		{src:"/flash/residence-interior_masthead.swf",
		 width:960,
		 height:331,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.primary = navid;
				htmlOptions.flashvars.secondary = secnavid;
				if (prisecnavid=='settagline') //if the tagline is specific for a page set this flashVars to true
					htmlOptions.flashvars.special = true;
				htmlOptions.flashvars.assetsFolder = '/flash/assets/';
				$(this).html($.fn.flash.transform(htmlOptions));
		});
		
	$(".press-release-div").each(function(){
        
      var x = $(this);
	  $(".articles-row:odd",x).addClass("press-odd");
      $(".articles").hide();
      $(".releases-toggle-div",x).toggle(function(){
           $(".articles",x).slideDown();
           $(this).addClass("active").html("<em class='alt'>Hide Articles</em>");
      }, function() {
           $(".articles",x).slideUp().hide();
           $(this).removeClass("active").html("<em class='alt'>Show Articles</em>");
      });
	  $(".releases-toggle-div",x).click();
	});

	
	$(".view-more-div").each(function(){
      var x = $(this);
      $(".articles").hide();
      $(".view-more-toggle-div",x).toggle(function(){
           $(".articles",x).slideDown();
           $(this).addClass("active").html("<em class='alt'>View More</em>");
      }, function() {
           $(".articles",x).slideUp().hide();
           $(this).removeClass("active").html("<em class='alt'>View Less</em>");
      });
	});

	if ( !$('#calendar-wrap').length ) {
	
				//booking console
		$('.toggle-promo').click(function(e){
			e.preventDefault();
			$('#promo-console').toggle(0,function(){
				if($(this).is(':visible')) {
					$('#group-code').focus();
				}
				else {
					$('.submit').focus();
				}
			});
			if (BROWSER=='msie6') $('select#child').toggle();
			if (BROWSER=='msie6') $('select#adult').toggle();
			if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
				$('#complete-promo').show();
			}
			else {
				$('#complete-promo').hide();
			}
		});
	}


	
});
function mycarousel_initCallback(carousel) {
	var jcsize = parseInt($("#control-links li").size());
	//$('ul.jcarousel-list li:eq('+jcsize+')').find('.next').hide();
	//alert(jcsize);
	jQuery('#control-links a').bind('click', function() {
		var cindex = $(this).parent().attr("id");
		cindex = cindex.substring(1);
        carousel.scroll(jQuery.jcarousel.intval( cindex ));
		$("#control-links a img").attr("src","/images/layout/control1.png");
		$(this).children("img").attr("src","/images/layout/control2.png");
        return false;
    });
	
	jQuery('.next-link').bind('click', function() {
		var cindex = $(this).parent().parent().parent().attr('jcarouselindex');
		//cindex = cindex.substring(5);
		cindex = parseInt(cindex) + 1;
		$("#control-links a img").attr("src","/images/layout/control1.png");
		$("#control-links").find("li#c"+cindex+" a").children("img").attr("src","/images/layout/control2.png");
		//alert(cindex +"+"+ jcsize);
		if (cindex == (jcsize+1)) {
			carousel.scroll(1);
			$("#control-links").find("li#c1 a").children("img").attr("src","/images/layout/control2.png");
		} else {
        	carousel.next();
		}
        return false;
    });
	
};

