$(function() {

	/*$('body.corporate-home #home-flash').flash({
	    swf:'/flash/home-masthead.swf',
	    wmode:'transparent',
	    xmlPath: '/flash/xml/home-masthead.xml',
	    width:'100%',
	    height:'662',
		src: '../flash/assets/photo-01.jpg'
	});*/

	// sIFRs
	$('div#content h1, .home-rotation-item h3, #blog-top h3, .amenity-item h3').sifr(
		{ strSWF: '/flash/avenir.swf', strColor: '#ffffff', strLinkColor: '#ffffff', strHoverColor: '#ffffff', strWmode: 'transparent', strCase: 'upper' },
		{ expressInstall: true }
	);
	/*$('div#sec-nav-heading h3').sifr(
		{ strSWF: '/flash/avenir.swf', strColor: '#ffffff', strLinkColor: '#ffffff', strHoverColor: '#ffffff', strWmode: 'transparent', strCase: 'upper', strFlashVars: 'textalign=center&letterSpacing=2&' },
		{ expressInstall: true }
	);*/
	$('.post h3').sifr(
		{ strSWF: '/flash/avenir.swf', strColor: '#efe89d', strLinkColor: '#efe89d', strHoverColor: '#efe89d', strWmode: 'transparent'},
		{ expressInstall: true }
	);
	$('#content h3.event-title').sifr(
		{ strSWF: '/flash/avenir.swf', strColor: '#006585', strLinkColor: '#006585', strHoverColor: '#006585', strWmode: 'transparent', intPadding: [9, 0, 0, 15] },
		{ expressInstall: true }
	);
	$('.sunset-styles #content h3.event-title').sifr(
		{ strSWF: '/flash/avenir.swf', strColor: '#331b0a', strLinkColor: '#331b0a', strHoverColor: '#331b0a', strWmode: 'transparent', intPadding: [9, 0, 0, 15] },
		{ expressInstall: true }
	);
	$('.sailport-styles #content h3.event-title').sifr(
		{ strSWF: '/flash/avenir.swf', strColor: '#091b32', strLinkColor: '#091b32', strHoverColor: '#091b32', strWmode: 'transparent', intPadding: [9, 0, 0, 15] },
		{ expressInstall: true }
	);
	$('.mutiny-styles #content h3.event-title').sifr(
		{ strSWF: '/flash/avenir.swf', strColor: '#ba642a', strLinkColor: '#ba642a', strHoverColor: '#ba642a', strWmode: 'transparent', intPadding: [9, 0, 0, 15] },
		{ expressInstall: true }
	);

	//Homepage push marketing
	$("#home-push-rotation").each(function(){
		var tOut;
		if ( $('body').hasClass('mutiny-home') || $('body').hasClass('sunset-home') || $('body').hasClass('sailport-home') || $('body').hasClass('ocean-pointe-home') ) {
			tOut = 10000;
		} else {
			tOut = 0;
		}
		$('#home-push-rotation').after('<div id="home-push-rotation-nav">').cycle({ 
			fx:     'scrollLeft', 
			speed:  800, 
			timeout: tOut, 
			pager:  '#home-push-rotation-nav',
			cleartype: true,
			cleartypeNoBg: true
		});
	});
	
	//Sign up form - remove "email address" from input once user clicks
	$("#signup-form").each(function(){
		$("input#email").click(function(){
			var emailVal = $(this).val();
			//alert(emailVal);
			if ( emailVal == 'email address' ) {
				$(this).attr('value','');
			}
		}).focusout(function(){
			var emailVal = $(this).val();
			//alert(emailVal);
			if ( emailVal == '' ) {
				$(this).attr('value','email address');
			}
		});
	});

	$('#msnmap-wrapper').each(function() {
	    //MSN Map

	    var propertyMap = {
		'mutiny-styles': 'map-mutiny',
		'ocean-pointe-styles' : 'map-ocean',
		'sailport-styles': 'map-sailport',
		'sunset-styles' : 'map-sunset'
	    },
	    colorMap = {
		'mutiny-styles': '#336462',
		'ocean-pointe-styles' : '#336462',
		'sailport-styles': '#000000',
		'sunset-styles' : '#55331e'
	    },
	    current = $('body').attr('class'),
	    color = colorMap[current];

	    if ( current.length && /^.+-styles/.test( current ) ) {
		var openFn=function(hash){
		    $('#console-signup-bar-wrapper').css('z-index', '-1');
		    hash.w.show();
		    var h2 = $(hash.w).find('h2');
		    if ( !h2.data('sifred') ) {
			$(h2).sifr(
				{ strSWF: '/flash/avenir.swf', strColor: color, strLinkColor: '#ffffff', strHoverColor: '#ffffff', strWmode: 'transparent', strCase: 'upper' },
				{ expressInstall: true }
			);
			$(h2).data('sifred', 1);
		    }
		    var difference = $(window).width() - $('#msnmap-wrapper').width();
		    difference = difference / 2;
		    $('#msnmap-wrapper').css({left:difference+275,top:$(window).scrollTop()+10});
		    if( true || !$('#map').data('mapped')){
			$('#map').msnMap({
			    listView:true,
			    xml: '/en/xml/' + propertyMap[current] + '.xml'
			});
			$('#map').data('mapped', 1);
		    }
		};
		var hideFn=function(hash){
		    hash.w.hide()
		    hash.o.remove();
		    $('.places').remove();
		    $('#console-signup-bar-wrapper').css('z-index', 'auto');
		};
		$("#map-trigger").each(function() {
		    $('body').append($('.jqmWindow'));
		    $('#msnmap-wrapper').jqm({trigger:'#map-trigger', onShow: openFn, onHide: hideFn});
		});
	    }
	});
	


	$('#sailport-photo-gallery').flash({
	    swf:"/flash/photo-gallery.swf",
	    width:642,
	    height:435,
	    wmode:"transparent",
	    flashvars: {
		xmlPath:'/flash/xml/sailport-images.xml',
		primaryColor:'0xffffff',
		secondaryColor:'0xbccfe6',
		buttonColor:'0xd1800b'
		}
	});

	$('#mutiny-photo-gallery').flash({
	    swf:"/flash/photo-gallery.swf",
	    width:642,
	    height:435,
	    wmode:"transparent",
	    flashvars: {
		xmlPath:'/flash/xml/mutiny-images.xml',
		primaryColor:'0xf3fcfc',
		secondaryColor:"0x91cac8",
		buttonColor:"0xb45413"
		}
	});

	$('#sunset-photo-gallery').flash({
	    swf:"/flash/photo-gallery.swf",
	    width:642,
	    height:435,
	    wmode:"transparent",
	    flashvars: {
		xmlPath:'/flash/xml/sunset-vistas-images.xml',
		primaryColor:'0xfcad72',
		secondaryColor:'0xffffff',
		buttonColor:'0x6e4523'
		}
	});

	$('#ocean-pointe-photo-gallery').flash({
	    swf:"/flash/photo-gallery.swf",
	    width:642,
	    height:435,
	    wmode:"transparent",
	    flashvars: {
		xmlPath:'/flash/xml/ocean-pointe-images.xml',
		primaryColor:'0xf8d6b0',
		secondaryColor:'0xfaeee1',
		buttonColor:'0x03546e'
		}
	});
	
	// Resize mastehad div in case the browser width is less than 1400px
	$("#masthead").each(function(){
		sizeMasthead();
	});
	$(window).resize(function () { sizeMasthead(); });
	function sizeMasthead(){
		var bWidth = window.innerWidth || document.body.clientWidth;
		if ( bWidth < 1400 ) {
			$("#masthead").css('width',bWidth-17);
		} else {
			$("#masthead").css('width','1400px');
		}
	}
});


