$(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:"9"}
	);
	
	$(".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 openFnV=function(hash){
		hash.w.show();
		$("#video-content").html('<embed width="640" height="480" align="middle" type="application/x-shockwave-flash" salign="" allowscriptaccess="sameDomain" allowfullscreen="false" menu="true" name="videos-02"  devicefont="false" wmode="window" scale="showall" loop="true" play="true" pluginspage="http://www.adobe.com/go/getflashplayer" quality="high" bgcolor="#7a4516" src="/flash/videos-02.swf">');	
		$('#video-modal').css({left:($(window).width()-$('#video-modal').width())/2,top:$(window).scrollTop()+10});		
	};
	
	var hideFn=function(hash){
		$("div#ellen-v-day").html('');
		$("div#ellen-giveaways").html('');
		$("div#ellen-game-show").html('');
		$("div#ellen-game-show").html('');
		$('#video-content').empty();
		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});
	$('#video-modal').jqm({trigger: '#push-video', onShow: openFnV, onHide: hideFn});

	//Interior push marketing rotation with jcycle
	$("div#special-offers-outer").each(function(){
		var randomPush = Math.floor(Math.random()*10);
		$('div#special-offers-outer div.rotation-wrapper').cycle({ 
			fx:     'scrollHorz', 
			speed:  1000, 
			timeout: 0, 
			startingSlide: randomPush,
			next:   '.rotation-next',
			prev:   '.rotation-prev' 
		});
	});
	
	$('div.extra-content').hide();
	$('a.spring-view-details').toggle(function (e){
			e.preventDefault();
			$(this).html('<a href="#" class="spring-view-details">Hide Details</a>').parents().next('.extra-content').slideDown('fast');
		},function(e) { 
			e.preventDefault();
			$(this).html('<a href="#" class="spring-view-details">View Details</a>').parents().next('.extra-content').slideUp('fast');
	});
	
	$('p a.month').each(function (e){
		$(this).parent().next('ul').hide();
		$(this).click(function(e) {
			e.preventDefault();
			$(this).parent().next('ul').slideToggle('fast');
		});
	});

});

$(function() {
	$('body.landing-recipes').find('div#copy').append("<div id='more'><a href='#'  class='next-link'><img src='/images/layout/next.png' class='png' alt='Next Recipe' /></a></div>");
	$('#recipes').after('<div id="control-links">').cycle({ 
		fx:     'fade', 
		speed:  3000, 
		timeout: 5000, 
		next: '.next-link',
		pager:  '#control-links' 
	});
	
	$('div#copy', 'body.landing-recipes').mouseover(function() {
		$('#recipes').cycle('pause'); 
	}).mouseout(function() {
		$('#recipes').cycle('resume'); 
	});

});

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 ));
		$(this).after("HEY<img />")
		$("#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;
    });
	
};
