$(function() {
	//Documentation located in special.docs.js
	//Sifr
	$('div#subnav h3').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#361b0a', strWmode: 'transparent', strFlashVars: 'textalign=center&' },{ expressInstall: true });
	$('div#subnav-residences h3').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#361b0a', strWmode: 'transparent', strFlashVars: 'textalign=center&' },{ expressInstall: true });
	$('div#content h1').sifr({ strSWF: '/flash/hoefler-text.swf', strColor: '#fffaed', strWmode: 'transparent', strCase: 'upper', strFlashVars: 'letterSpacing=4&' },{ expressInstall: true });
	$('div.content-item h3').sifr({ strSWF: '/flash/hoefler-text.swf', strColor: '#fffaed', strWmode: 'transparent', strCase: 'upper', strFlashVars: 'letterSpacing=2&' },{ expressInstall: true });
	$('div#weather-wrapper h4').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#ab9886', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });
	$('div#weather-wrapper h5').sifr({ strSWF: '/flash/hoefler-text-italic.swf', strColor: '#fffaed', strWmode: 'transparent', strCase: 'upper' },{ expressInstall: true });

	//Residents page
	$("div#montage-development-photos").flash(
		{src:"/flash/deer_valley.swf",
		 width:1024,
		 height:615,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"9"}
	);

	//Home Masthead
	$("div#home-masthead").flash(
		{src:"/flash/masthead-xml.swf",
		 width:960,
		 height:370,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"9"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.imagesXML = "/flash/xml/home-masthead-2.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});

	$("div#residences-home-masthead").flash(
		{src:"/flash/residences-masthead.swf",
		 width:960,
		 height:370,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"9"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.xmlPath = "/flash/xml/residence-masthead.xml";
				$(this).html($.fn.flash.transform(htmlOptions));
		});


	var navid = $('ul#nav-primary').find('.current').attr("id");
	var secnavid = $('#'+navid).find('.current').attr("id");
	
	//alert(secnavid);
	
	if (navid != undefined)
		navid = navid.substring(8);
	else
		navid = 'destination';
		
	if (secnavid != undefined)
		secnavid = secnavid.substring(10);
	else
		secnavid = 'main';
	//alert(secnavid);

	//This part is ghetto- i know. dont hate
	var prisecnavid= navid+'-'+secnavid;

	//alert(prisecnavid);

	//Interior Masthead
	$("#interior-masthead").flash(
		{src:"/flash/interior-masthead.swf",
		 width:960,
		 height:267,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"9"},
			function(htmlOptions) { //Use this to specify a query string, take out if not needed.
				htmlOptions.flashvars.primary = navid;
				htmlOptions.flashvars.secondary = secnavid;
				htmlOptions.flashvars.assetsFolder = '/flash/assets/';
				$(this).html($.fn.flash.transform(htmlOptions));
		});
	
	//Interior Masthead
	$("#residences-interior-masthead").flash(
		{src:"/flash/res-interior-masthead.swf",
		 width:960,
		 height:267,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"9"},
			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.hasScrolls = true;					
				//}
				htmlOptions.flashvars.assetsFolder = '/flash/assets/';
				$(this).html($.fn.flash.transform(htmlOptions));
		});
	
	//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});
	};
	var openFn2=function(hash){
		hash.w.show();
		$('#dialog-residences').css({left:($(window).width()-$('#dialog-residences').width())/2,top:$(window).scrollTop()+10});
	};
	
	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){
		hash.w.hide()
		hash.o.remove();
	};
	/*$("#msnmap").each(function() {
		$('#map-jqmodal').jqm({trigger:'#msnmap', onShow: openFn, onHide: hideFn});
	});*/

	var openPic1=function(hash){
		hash.w.show();
		$('#apex').css({left:($(window).width()-$('#apex').width())/2,top:$(window).scrollTop()+10});
	};

	var openPic2=function(hash){
		hash.w.show();
		$('#coffeehouse').css({left:($(window).width()-$('#coffeehouse').width())/2,top:$(window).scrollTop()+10});
	};
	
	var openPic3=function(hash){
		hash.w.show();
		$('#daly').css({left:($(window).width()-$('#daly').width())/2,top:$(window).scrollTop()+10});
	};

	var openPic4=function(hash){
		hash.w.show();
		$('#vista').css({left:($(window).width()-$('#vista').width())/2,top:$(window).scrollTop()+10});
	};
	

	$('#dialog').jqm({ajax:'../includes/photo-gallery.php', onShow: openFn, onHide: hideFn, target:'div#photo-content'});
	$('#dialog-residences').jqm({ajax:'../includes/photo-gallery-residences.php', onShow: openFn2, onHide: hideFn, target:'div#photo-content'});


	$('#apex').jqm({trigger: 'a.apex-enlarge', onShow: openPic1, onHide: hideFn});
	$('#coffeehouse').jqm({trigger: 'a.coffeehouse-enlarge', onShow: openPic2, onHide: hideFn});
	$('#daly').jqm({trigger: 'a.daly-enlarge', onShow: openPic3, onHide: hideFn});
	$('#vista').jqm({trigger: 'a.vista-enlarge', onShow: openPic4, onHide: hideFn});	

	//$('#dialog').jqmAddTrigger('li#secondary-photos a'); 


	$('.exec-team-long').hide();
	$('.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);
		}
	});

	$('.dining-info-long').hide();
	$('.dining-info').each(function(){
		var pTag = $('h4',this).next();
		if (pTag.html() == '') { pTag.hide(); }
		if ($('.dining-info-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('.dining-info-long').slideDown('slow');
					return false;								   
				},function() { 
					var el = $(this);
					el.html('Read More');
					$('.dining-info-long').slideUp('slow');
					return false;								   
				});
			$('.dining-content',this).append(toggleLink);
		}
	});


	$('.development-partners-long').hide();
	$('.development-partners').each(function(){
		var pTag = $('h4',this).next();
		if (pTag.html() == '') { pTag.hide(); }
		if ($('.development-partners-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('.development-partners-long').slideDown('slow');
					return false;								   
				},function() { 
					var el = $(this);
					el.html('Read More');
					$('.development-partners-long').slideUp('slow');
					return false;								   
				});
			$('.development-partners-content',this).append(toggleLink);
		}
	});	
	
	$('.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;								   
	});


	$('.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#adults').toggle();
		if ($('#group-code').val() || $('#promo-code').val() || $('#iata-number').val()) {
			$('#complete-promo').show();
		}
		else {
			$('#complete-promo').hide();
		}
	});

// Ride the carousel...
	$('#homecarousel').after('<div id="control-links">').cycle({ 
		fx:     'fade', 
		speed:  800, 
		timeout: 0, 
		next: '.next-link',
		pager:  '#control-links' 
	});
});

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;
    });
	
};
