$(function() {
		   
	//Sifr
	$('div#subnav 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 });
	
	//Home Masthead
	$("#home-masthead").flash({src:"/flash/home-masthead-3.swf",width:960,height:370,wmode:"transparent",quality:"high"},{version:"8"});
	
	$("#residences-home-masthead").flash({src:"/flash/residences-home-masthead.swf",width:960,height:370,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");
	
	//alert(secnavid);
	
	if (navid != undefined)
		navid = navid.substring(8);
	else
		navid = 'overview';
		
	if (secnavid != undefined)
		secnavid = secnavid.substring(10);
	else
		secnavid = 'main';
	//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:
		}

	//alert(secnavid);
	//Interior Masthead
	$("#interior-masthead").flash(
		{src:"/flash/interior-masthead.swf",
		 width:960,
		 height:267,
		 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));
		});
	$("#meeting-rooms-flash").flash(
		{src:"/flash/meeting-map.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});
	};
	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});
	});*/
	
	$('#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'); 
	
	$('#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(){
		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);
		}
	});
	
	$('.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;								   
	});
	
	// 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: 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;
    });
	
};
