$(function() {
		
	if(($.browser.msie) && ($.browser.version == '6.0')) {
		$('ul#nav-primary > li, ul.nav-residences > li').hover(function() {
			$(this).addClass('over').css("background-image", "url(/images/nav/nav-li-bg.png)");
		}, function() {
			$(this).removeClass('over')
			if(!$(this).hasClass('current'))
				$(this).css("background-image", "url(none)");
		});
	}
	
	$('#nav-utility ul').each(function() { 
		var loc = window.location.pathname;
		loc = '#util-'+loc.substr(1, loc.lastIndexOf('/')-1);
		$(this).children(':not('+loc+', #utility-residence)').remove().end().width($(this).width()).css({margin: '0 auto', float: 'none'});
	});
	
	$('#special-offers .promo h2').sifr(
		{ strSWF: '/fonts/sabon.swf', strColor: '#ceb08c', strWmode: 'transparent', strFlashVars: 'textalign=center&', strCase: 'upper' },
		{ expressInstall: true }
	);
	
	$('body:not(#mini-residences) #content h1').sifr(
		{ strSWF: '/fonts/hoefler-text-italic.swf', strColor: '#fad299', strWmode: 'transparent', strFlashVars: 'textalign=center&' },
		{ expressInstall: true }
	);
	
	$('body#mini-residences.mlb-residences #content h1').sifr(
		{ strSWF: '/fonts/sabon-bold-italics.swf', strColor: '#a0886b', strWmode: 'transparent', strFlashVars: 'textalign=center&' },
		{ expressInstall: true }
	);
	
	$('body#mini-residences.mbh-residences #content h1').sifr(
		{ strSWF: '/fonts/sabon-bold-italics.swf', strColor: '#ecc58f', strWmode: 'transparent', strFlashVars: 'textalign=center&' },
		{ expressInstall: true }
	);

	$('body.media-room #content h2').sifr(
		{ strSWF: '/fonts/hoefler-text-italic.swf', strColor: '#d3a464', strWmode: 'transparent' },
		{ expressInstall: true }
	);

	$('#disclaimer-socalmeetings').each(function() {
		$(".disclaimer-body").hide();
		$(".disclaimer-toggle").click(function()
		{
			$(".disclaimer-body").slideToggle(600);
			return false;
		});	
	});	

	$('.offers').each(function() {
		var obj = $(this);
		var count = $(this).children().length;
		if(count>1) {
			//var rand = Math.floor(Math.random()*count)
			//$(this).children().hide().siblings(':eq('+rand+')').show().addClass('current');
			$(this).children().eq(0).addClass('current').siblings().hide();
			
			$('<div/>').attr('class', 'push-next')
			.html('<img src="images/buttons/push-next.gif" alt="Next Featured Offer" />')
			.bind("click", function() {
				$(this).hide();
				if($('.current', obj).is(':last-child'))
					$('.current', obj).css({position: 'absolute', left: 0, top: 0}).fadeOut("slow", function() {
						$(this).removeClass('current');
					}).siblings('.offer:eq(0)').fadeIn(2500, function() { 
						$(this).addClass('current');
						$('.push-next', obj).fadeIn("fast");
					});
				else
					$('.current', obj).css('position', 'absolute').fadeOut("slow", function() {
						$(this).removeClass('current');
					}).next('.offer').fadeIn(2500, function() { 
						$(this).addClass('current');
						$('.push-next', obj).fadeIn("fast");
					});
				return false;
			}).prependTo(obj);	
		}
	});

	$("div.gallery").flash(
		{src:"flash/photo_gallery.swf",
		width:466,
		height:370,
		wmode:"transparent",
		quality:"high"},
		{version:"8"},
		function(htmlOptions) { //Use this to specify a query string, take out if not needed.
			//htmlOptions.flashvars.configFile = "flash/xml/gallery_config.xml";
			htmlOptions.flashvars.xmlFile = "flash/xml/"+$(this).attr("id")+".xml";
			$(this).html($.fn.flash.transform(htmlOptions));
	});
	
	$("body.index div#masthead").flash(
		{src:"flash/home.swf",
		 width:955,
		 height:311,
		 wmode:"transparent",
		 quality:"high"},
		 {version:"8"}
	);
	
	$(".mbh-residences #res-home-content").flash(
		{src:"/flash/MBH-masthead-slideshow.swf",
		width:525,
		height:400,
		wmode:"transparent",
		quality:"high"},
		{version:"8"}
	);
	
	$(".mlb-residences #res-home-content").flash(
		{src:"/flash/MLB-masthead-slideshow.swf",
		width:525,
		height:400,
		wmode:"transparent",
		quality:"high"},
		{version:"8"}
	);
	
	$('.bio').each(function() {
		var obj = this;
		var more = $('<a />')
					.attr('href', '#')
					.html('Read More')
					.click(function() {
						$('.bio-details', obj).jqmShow();
						return false;			
					});
		var  p = $('<p />').html(more);
		p.addClass('read-more');
		
		var cl = $('<div class="jqmClose">Close <span>X</span></div>');
		var intro = $('.bio-intro', obj).clone();
		$('.bio-details', obj).addClass('jqmWindow').prepend(intro).prepend(cl).before(p).jqm({toTop: true});
	});
	
	$('form.res-contact input#contact-address').click(function(){
		var addfield = $(this).parent().parent().parent().parent().parent('form.res-contact').children().children('div#address-field');
	
		if ( $(this).attr('checked') ) {
			$(addfield).children('label').addClass('required');
			$(addfield).children('input').addClass('required');
		} else {
			$(addfield).children('label').removeClass('required');
			$(addfield).children('input').removeClass('required');
			if ( $(addfield).find("img.validation-error") )
				$(addfield).find("img.validation-error").remove();
		}
															   
	});
	
	/*$('.disclaimer-wrapper').each(function() {
		var obj = this;
		$('.disclaimer').click(function() {
			$('.disclaimer-details', obj).jqmShow();
				return false;			
		});	
		var cl = $('<div class="jqmClose">Close <span>X</span></div>');
		$('.disclaimer-details', obj).addClass('jqmWindow').prepend(cl).jqm({toTop: true});
	});*/
	
	
	$('.disclaimer-details').prepend('<div class="jqmClose">Close<span>X</span></div>');
	$('.disclaimer-wrapper').addClass('jqmWindow').jqm({toTop: true});
	
	$('.disclaimer').click(function() {
		$('.disclaimer-wrapper').jqmShow();	
		return false;
	});
	
	$('#mbh-leed').click(function(){
		if( $('#mbh-leed-info').css('display') == 'none' ) {
			$('#mbh-leed-info').show();
		}
		else {
			$('#mbh-leed-info').hide();
		}
		return false;
	});
	


	var openFn=function(hash){
		hash.w.show();
		$("div#ellen-giveaways").flash(
			{src:"/flash/ellen-12days.swf",
			width:640,
			height:480,
			wmode:"transparent",
			quality:"high"},
			{version:"8"}
		);
		$('#ellen-1').css({left:($(window).width()-$('#ellen-1').width())/2,top:$(window).scrollTop()+10});
	};

	var openFn2=function(hash){
		hash.w.show();
		$("div#ellen-v-day").flash(
			{src:"/flash/ellen-vday.swf",
			width:640,
			height:480,
			wmode:"transparent",
			quality:"high"},
			{version:"8"}
		);		
		$('#ellen-2').css({left:($(window).width()-$('#ellen-2').width())/2,top:$(window).scrollTop()+10});
	};
	
	var openFn3=function(hash){
		hash.w.show();
		$("div#ellen-game-show").flash(
			{src:"/flash/ellen-gameweek.swf",
			width:640,
			height:480,
			wmode:"transparent",
			quality:"high"},
			{version:"8"}
		);		
		$('#ellen-3').css({left:($(window).width()-$('#ellen-3').width())/2,top:$(window).scrollTop()+10});		
	};
	
	var hideFn=function(hash){
		$("div#ellen-v-day").html('');
		$("div#ellen-giveaways").html('');
		$("div#ellen-game-show").html('');
		hash.w.hide()
		hash.o.remove();
	};

	$('#ellen-1').jqm({trigger: 'a.launch-giveaway-video', onShow: openFn, onHide: hideFn});	
	$('#ellen-2').jqm({trigger: 'a.launch-vday-video', onShow: openFn2, onHide: hideFn});	
	$('#ellen-3').jqm({trigger: 'a.launch-gameshow-video', onShow: openFn3, onHide: hideFn});

	
});
