//SiteCatalyst code to track form conversion
function siteCatalystLead(){
	if (typeof(s) == "undefined") return;
	var scPage = "ContactUs-NeighborhoodInfo-ThankYou";
	var old = s.pageName;
	if(old.length > 0){
		if(old.indexOf(" - index") > 0){
			s.pageName = old.replace(" - index","");
		}
		s.pageName = s.pageName + " - " + scPage;
	}
	else{
		s.pageName = scPage;
	}
	s.events = "event2";
	s.eVar1 = "contact us";

	var sCG = sContentGroup;
	if(sCG.length > 0){
		if(sCG.indexOf("/index") > 0){
			sCG = sCG.replace("/index","");
		}
		else if(sCG.indexOf("/Find a Home") > 0){
			sCG = sCG.replace("/Find a Home","");
		}
	}
	s.channel = sCG + "/" + scPage;
	s.hier1 = sCG + "/" + scPage;
	var path = document.location.pathname.substr(1);
	s.state = (path.length > 0) ? path.split('/')[0] : '';
	
	s.t();
	sc_initPage();
}

function siteCatalystDirections(){
	if (typeof(s) == "undefined") return;
	s.events="event6";
	//s.events=s.linkTrackEvents;
	var sDG = sContentGroup;
	if (sDG.length > 0){
		if(sDG.indexOf("/index") > 0){
			sDG = sDG.replace("/index","");
		}
		else if(sDG.indexOf("/Find a Home") > 0){
			sDG = sDG.replace("/Find a Home","");
		}
	}
	s.eVar6 = sDG;
	s.tl("true","o","directionsTabClicked");
	s.events = "None";

	/*
	s.pageName = s.pageName + " - fast pass";
	s.channel = "";
	s.hier1 = "";
	s.state = "";

	s.prop1 = "";
	s.prop2 = "";
	s.prop3 = "";
	s.prop4 = "";
	s.prop5 = "";
	s.prop6 = "";
	s.prop7 = "";
	s.prop8 = "";
	s.prop9 = "";

	s.t();
	sc_initPage();
	*/
}

function recordLeadConversion(formId) {
	//Google Adwords Lead Form tracking tags
	if (typeof(_gaq) != "undefined"){

		var gTagBegin = '<div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/';
		var gTagMid = '/?label=';
		var gTagEnd = '&amp;guid=ON&amp;script=0"/></div>';

		var googleTag_0 = gTagBegin + googleConversionID_0 + gTagMid + googleConversionLabel_0 + gTagEnd;
		var googleTag_1 = gTagBegin + googleConversionID_1 + gTagMid + googleConversionLabel_1 + gTagEnd;
		var googleTag_2 = gTagBegin + googleConversionID_2 + gTagMid + googleConversionLabel_2 + gTagEnd;

		var sdpixsDiv = document.getElementById("sdpixs");
		sdpixsDiv.innerHTML = googleTag_0+googleTag_1+googleTag_2;

		//Yahoo lead form tracking tag
		if (typeof(window.ysm_customData) != 'object') window.ysm_customData = new Object();
		window.ysm_customData.segment_1111111 = "event=1,transId=,currency=,amount=";
		window.ysm_accountid = yahooLeadId;
		var ss = document.createElement('script');
		ss.src = "//srv1.wa.marketingsolutions.yahoo.com/script/ScriptServlet?aid=" + ysm_accountid;
		document.getElementsByTagName('head')[0].appendChild(ss);

		//Google Analytics virtual pageview - Lead Form Success
		_gaq.push(
				['C001._trackPageview','/lead_form/success.html'],
				['C000._trackPageview','/lead_form/success.html'],
				['C002._trackPageview','/lead_form/success.html'],
				['C_Rollup._setCustomVar', 2, 'FormPosition', (formId == 'primary_form' ? 'sidebar' : 'list'), 1],
				['C_Rollup._trackPageview','/lead_form/success.html']
		);
	}
   
	siteCatalystLead();
	// Yahoo retargeting pixel
	$(document.body).append('<img src="http://ads.bluelithium.com/pixel?id=' + yblIdLeadSubmit + '&t=2" width="1" height="1" />');
	// 24/7 Media retargeting pixel
	$(document.body).append('<img src="http://network.realmedia.com/' + tfmSuffixLeadSubmit + '" />');
	pointRoll(prIdLeadSubmit, prPrefix);
}

(function( $ ){
	$.fn.listForm = function() {
		//TODO: make this apply to the form element so it can be chained with the other initializers
		if (!this.length) {
			//if (window.console) { console.log( "list not found, can't initialize list form" ); }
			return;
		}
		//if (window.console) { console.log("initializing list form: " + $(this).attr('id')); }
		
		var listType = null;
		var uoLists = $('UL');
		var uoList, listUL;
		for (uoList in uoLists) {
			listUL = uoLists[uoList];
			var listULid = listUL.id;
			switch (listULid) {
				case 'markets'     : listType = 'market';    break;   
				case 'communities' : listType = 'community'; break;
				case 'plans'       : listType = 'plan';      break;
				case 'specs'       : listType = 'spec';      break;
			}
			if (listType !== null) {
				break;
			}
		}
		if (listType === null) {
			//if (window.console) console.log( "list type not found, can't initialize list form." );
			return;
		}
		
		var listFormDiv = this.clone();
		listFormDiv.attr('id','listFormDiv');
		listFormDiv.attr('class', 'more-info community');
		$('strong', listFormDiv).remove();
		var p = $('p', listFormDiv);
		if (p.length > 0) {
			p.detach();
			var holder = $('<div class="text-holder" />');
			holder.prepend(p);
			listFormDiv.prepend(holder);
		}
		var list_form = $('form', listFormDiv);
		list_form.attr('id', 'list_form');
		// TODO: fix stupid css names for sign-form and info-form
		//       be careful because this value triggers custom GA variables
		if (list_form.attr('class') == 'sign-form') {
			list_form.attr('class','info-form');
		}
		else {
			list_form.addClass('list');
		}
		$(':input', list_form).attr('id', function(index, attr){
			return $(this).attr('name') + '_' + listType;
		}).removeAttr('tabindex');
		$('label', list_form).attr('for', function(index, attr){
			return attr + '_' + listType;
		});
		$('button.btn-dark', listFormDiv).attr('class','btn-gray');
		var hidden = $('<input type="hidden" id="id_'+listType+'_num" name="'+listType+'_num" />');
		list_form.append(hidden);
		$('[href^=#'+listType+'-]', listUL).toggle(function(){
			var href = $(this).attr('href').substr(1);
			this.parentNode.className = 'active '+ this.parentNode.className;
			$('#id_'+listType+'_num', list_form).val(href.substr(listType.length+1));
			$('#'+href).append(listFormDiv);
			listFormDiv.css('display','');
			$('#email_'+listType).focus();
			return false;
		}, function(){
			this.parentNode.className = this.parentNode.className.substr(7);
			listFormDiv.detach();
			return false;
		}).first().each( function(){
			// add the list form to the DOM so it can be matched and initialized 
			var href = $(this).attr('href').substr(1);
			$('#id_'+listType+'_num', list_form).val(href.substr(listType.length+1));
			listFormDiv.css('display','none');
			$('#'+href).append(listFormDiv);
		});
		$("li.btn-mail span").show();
		//if (window.console) { console.log( "list form initialized" ); }

		/* Start featured community code */
		if ($("#communitiesFeatured").length)
		{
			listType = 'communityFeatured';
			$('[href^=#'+listType+'-]').toggle(function(){
				var href = $(this).attr('href').substr(1);
				this.parentNode.className = 'active '+ this.parentNode.className;
				$('#id_'+listType+'_num', list_form).val(href.substr(listType.length+1));
				$('#'+href).append(listFormDiv);
				listFormDiv.css('display','');
				$('#email_'+listType).focus();
				return false;
			}, function(){
				this.parentNode.className = this.parentNode.className.substr(7);
				listFormDiv.detach();
				return false;
			}).first().each( function(){
				// add the list form to the DOM so it can be matched and initialized 
				var href = $(this).attr('href').substr(1);
				$('#id_'+listType+'_num', list_form).val(href.substr(listType.length+1));
				listFormDiv.css('display','none');
				$('#'+href).append(listFormDiv);
			});
		}
		/* End featured community code */
		return this;
	};
})(jQuery);

(function( $ ){
	$.fn.madForm = function() {
		if (!this.length) {
			//if (window.console) { console.log( "mad form not found, can't initialize mad form" ); }
			return;
		}
		//if (window.console) { console.log("initializing mad form: " + $(this).attr('id')); }
		
		var options = {
			target : null,
			replaceTarget : false,
			cache : false,
			success : function(responseText, statusText, xhr, $form) {
				//TODO: parameterize this to work with other brands/domains
				//TODO: use target and replaceTarget
				//if (document.location.host.indexOf('centexhomes.com') != -1) {
					recordLeadConversion($form.attr('id'));
				//}
				if (statusText == 'success') {
					$form.replaceWith("<div class='success'>"+responseText+"</div>");
				}
				else {
					$form.replaceWith("<div class='error'>"+responseText+"</div>");
				}
			},
			type: 'post'
		};
		
		//$('<a href="javascript:void(0)" class="more">Personalize message</a>').insertBefore('div.more-option', this).one("click", function(event) {
		$('div.more-option', this).before('<a href="javascript:void(0)" class="more">Personalize message</a>');
		$('a.more', this).one("click", function(event) {
			$(this).css("display", "none");
			$('#list_form.mad-form div.opening').css('padding-bottom','140px');
			$('div.more-option', $(this).parent()).css("display", "block");
			$('textarea', $(this).parent()).focus().select();
			return false;
		});
	
		$('textarea, :text',this).focus( function(e) {
			$(this).select();
		});
		$('textarea, :text',this).mouseup( function(e) {
			// this allows the input to keep selection from a click that delivers focus (above event)
			// webkit doesn't work like FF and IE, so it doesn't keep selection
			if (document.activeElement !== this) {
				return false;
			}
		});
	
		jQuery.validator.addMethod("defaultInvalid", function(value, element) {
			return value != element.defaultValue && $.trim(value) != '';
		}, "");
				
		jQuery.validator.messages.required = "";
		this.validate({
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = (errors == 1)
						? 'There is a problem with 1 required field. It has been highlighted below.'
						: 'There is a problem with ' + errors + ' required fields. They have been highlighted below.';
					$("div.error span", this).html(message);
					$("div.error", this).show();
				}
				else {
					//despite docs, i'm pretty sure this never gets called
					$("div.error", this).hide();
				}
			},
			ignoreTitle: true,
			ignore: "input[name=phone]",
			onkeyup: false,
			submitHandler: function() {
				$("div.error", this).hide();
				$(this.currentForm).ajaxSubmit(options);
			},
			rules: {
				email: {
					required : true,
					email    : true,
					defaultInvalid : true
				},
				phone: {
					required: false,
					maxlength: false
				}
			},
			messages: {
				first_name : null,
				last_name: null,
				email: {
					required : null,
					email    : "Please enter a valid email address (you@example.com)",
					defaultInvalid : null
				}
			},
			debug:true,
			onfocusout: function(element) {
				if ($.trim(element.value) == '') {
					element.value = element.defaultValue;
				}
				if (!this.checkable(element) && (element.name in this.submitted || !this.optional(element))) {
					this.element(element);
				}
				if ($("div.error", this.currentForm).css("display") != "none") {
					this.form();
					if (this.numberOfInvalids() < 1) {
						$("div.error", this.currentForm).hide();
					}
				}
				
			}
		});
		//if (window.console) { console.log( "mad form initialized" ); }
		return this;
	};
})(jQuery);

(function( $ ){
	$.fn.standardForm = function() {
		if (!this.length) {
			//if (window.console) { console.log( "standard form not found, can't initialize standard form" ); }
			return;
		}
		//if (window.console) { console.log( "initializing standard form: " + $(this).attr('id')); }
		
		var options = {
			target : null,
			replaceTarget : false,
			cache : false,
			success : function(responseText, statusText, xhr, $form) {
				//TODO: parameterize this to work with other brands/domains
				//TODO: use target and replaceTarget
				//if (document.location.host.indexOf('centexhomes.com') != -1) {
					recordLeadConversion($form.attr('id'));
				//}
				if (statusText == 'success') {
					$form.replaceWith("<div class='success'>"+responseText+"</div>");
					// Create a test and target call upon successful submission of the form.
					if (tAtSuccess != "DivostaHome_Verisign_Success")
					{
						mboxDefine('dynamicElement', tAtSuccess);
						mboxUpdate(tAtSuccess);
					}
				}
				else {
					$form.replaceWith("<div class='error'>"+responseText+"</div>");
				}
			},
			type: 'post'
		};
		
		this.validate({
			debug : false,
			onkeyup: false,
			submitHandler:  function() {
				$(this.currentForm).ajaxSubmit(options);
				$('button[type=submit]', this.currentForm).attr('disabled', 'disabled');
			},
			rules : {
				first_name : 'required',
				last_name  : 'required',
				email      : {
					required: true,
					email   : true
				}
			},
			errorElement: "span",
			highlight: function(element, errorClass, validClass) {
				$(element).addClass(errorClass);
				$(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
			},
			unhighlight: function(element, errorClass, validClass) {
				$(element).removeClass(errorClass);
				$(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
			}
		});
		//if (window.console) { console.log( "standard form initialized" ); }
		return this;
	};
})( jQuery );

function geoQuery(regionName, stateSlug, regionSlug, map, bounds, markers) {
	var geocoder = new google.maps.Geocoder();
	geocoder.geocode( {'address': regionName+', '+stateSlug.toUpperCase()}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			/*for (var i in results) {
				console.log(regionName + " : " + regionName + " -> " + results[i].address_components[0].short_name);
			}*/
			var marker = new google.maps.Marker({
				map: map, 
				position: results[0].geometry.location,
				clickable: true,
				icon: google.maps.MarkerImage('/Content/brands/' + brandSlug + '/images/marker_sprite.png'),
				title: regionName
			});
			marker.url = '/'+stateSlug+'/'+regionSlug; // monkeypatch for the event handler
			markers['region_'+regionSlug] = marker;
			bounds.extend(marker.getPosition());
			map.fitBounds(bounds);
			map.panToBounds(bounds);
			google.maps.event.addListener(marker, 'click', function(event) {
				//TODO: redraw page with AJAX
				document.location = this.url;
			});
		}
	});
}

function maxHeight($e0,$e1) {
	var h = Math.max($e0.height(), $e1.height());
	$e0.height(h);
	$e1.height(h);
	return h;
}

(function( $ ){
	$.fn.stateMap = function() {
		if (!this.length) {
			//if (window.console) { console.log( "state map not found, can't initialize state map." ); }
			return;
		}
		//if (window.console) { console.log( "initializing state map: " +  $(this).attr('id')); }
		
		var $content = $('#content');
		var h = maxHeight($content,$('#sidebar'));
		var $titleBar = $('div.content-title', $content);
		var th = $titleBar.height() + parseInt($titleBar.css('padding-top')) + parseInt($titleBar.css('padding-bottom')) + parseInt($titleBar.css('border-bottom-width'))
		$('#state_map_canvas').height(h - th);
		
		var mapDiv = this[0];
		$(mapDiv).height()
		
		var gMaps = google.maps,
			gLatLng = gMaps.LatLng,
			gMark = gMaps.Marker,
			gMarkImg = gMaps.MarkerImage,
			gAddListener = gMaps.event.addListener,
			gSz = gMaps.Size,
			gPt = gMaps.Point;
			
		var stateMapOptions = {
			disableDefaultUI: false,
			streetViewControl: false,
			scrollwheel: true,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(mapDiv, stateMapOptions); //this, stateMapOptions);
		var markers = {};
		var bounds = new google.maps.LatLngBounds();
		var stateSlug = window.location.pathname.substr(1,2);
		var icon = new gMarkImg('/Content/brands/' + brandSlug + '/images/marker_sprite.png',
			new gSz(20, 34),
			new gPt(0,0), // origin
			new gPt(10, 33)); // anchor
		var shadow = new gMarkImg('/Content/brands/' + brandSlug + '/images/marker_sprite.png',
			new gSz(29, 22),
			new gPt(0,0), // origin
			//new gPt(29,12), // origin
			new gPt(0, 21)); // anchor
		var shape = {
			coord: [5,0, 14,0, 19,5, 19,13, 13,33, 6,33, 0,13, 0,5, 5,0],
			type: 'poly'
		};
		var regionName;
		for (regionName in builder_regions)	{
			var region = builder_regions[regionName];
				var regionSlug = region.slug;
			if (region.pt !== null){
				var marker = new gMark({
					map: map,
					position: new gLatLng(region.pt[0],region.pt[1]),
					clickable: true,
					title: regionName,
					icon: icon,
					//shadow: shadow,
					shape: shape
				});
				marker.url = '/'+stateSlug+'/'+regionSlug; // monkeypatch for the event handler
				markers['region_'+regionSlug] = marker;
				bounds.extend(marker.getPosition());
				gAddListener(marker, 'click', function(event) {
					//TODO: redraw page with AJAX
					document.location = this.url;
				});
			}
			else if (window.console) {
				console.warn(region.name + ' does not have LatLng coordinates. Attempting to geocode.');
				geoQuery(regionName, stateSlug, regionSlug, map, bounds, markers);
			}
		}
		map.fitBounds(bounds);
		if (map.zoom > 11){
			map.setZoom(11);
		}
		map.panToBounds(bounds);
		
		$('ul#regions li').each(function(){
			$li = $(this);
			$li.bind('click', function(){
				window.location.href = $('a', this).attr('href');
			});
		});
		//if (window.console) { console.log( "state map initialized" ); }
		return this;
	};
})( jQuery );
(function( $ ){
	$.fn.regionMap = function() {
		if (!this.length) {
			//if (window.console) { console.log( "Region map not found, can't initialize region map." ); }
			return;
		}
		//if (window.console) { console.log( "initializing region map: " +  $(this).attr('id')); }

		var mapDiv = this[0];
		var gMaps = google.maps,
			gLatLng = gMaps.LatLng,
			gMark = gMaps.Marker,
			gMarkImg = gMaps.MarkerImage,
			gAddListener = gMaps.event.addListener,
			gSz = gMaps.Size,
			gPt = gMaps.Point;

		var latitude = $("#latitude").html();
		var longitude = $("#longitude").html();
		var center = new google.maps.LatLng(latitude, longitude);
		var marketMapOptions = {
			disableDefaultUI: false,
			streetViewControl: false,
			scrollwheel: true,
			zoom:14,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			center:center
		};
		var map = new google.maps.Map(mapDiv, marketMapOptions);
		var markers = {};
		var bounds = new google.maps.LatLngBounds();
		var stateSlug = window.location.pathname.substr(1,2);
		var icon = new gMarkImg('/Content/brands/' + brandSlug + '/images/marker_sprite.png',
			new gSz(20, 34),
			new gPt(0,0), // origin
			new gPt(10, 33)); // anchor
		var shadow = new gMarkImg('/Content/brands/' + brandSlug + '/images/marker_sprite.png',
			new gSz(29, 22),
			new gPt(0,0), // origin
			//new gPt(29,12), // origin
			new gPt(0, 21)); // anchor
		var shape = {
			coord: [5,0, 14,0, 19,5, 19,13, 13,33, 6,33, 0,13, 0,5, 5,0],
			type: 'poly'
		};
		var region, regionName, regionSlug;
		for (regionName in builder_regions)	{
			region = builder_regions[regionName];
			regionSlug = region.slug;
			if (region.pt !== null){
				regionSlug = region.slug;
				var marker = new gMark({
					map: map,
					position: new gLatLng(region.pt[0],region.pt[1]),
					clickable: true,
					title: regionName,
					icon: icon,
					//shadow: shadow,
					shape: shape
				});
				marker.url = region.url; // monkeypatch for the event handler
				markers['community_'+regionSlug] = marker;
				bounds.extend(marker.getPosition());
				gAddListener(marker, 'click', function(event) {
					//TODO: redraw page with AJAX
					document.location = this.url;
				});
			}
			else if (window.console) {
				console.warn(region.name + ' does not have LatLng coordinates. Attempting to geocode.');
				geoQuery(regionName, stateSlug, regionSlug, map, bounds, markers);
			}
		}
		if (bounds.isEmpty() !== true){
			map.fitBounds(bounds);
		}
		var listener = google.maps.event.addListener(map, "idle", function() { 
			if (map.getZoom() > 14) {
				map.setZoom(14);
			}
			map.setCenter(bounds.getCenter());
			google.maps.event.removeListener(listener); 
		});
		
		/*$('ul#communities li').each(function(){
			$li = $(this)
			$li.bind('click', function(){
				window.location.href = $('a', this).attr('href');
			});
		});*/
		//if (window.console) { console.log( "region map initialized" ); }
		return this;
	};

})( jQuery );
$.fn.communityMap = function() {
	if (!this.length) {
		//if (window.console) console.log( "nothing selected, can't initialize community map." );
		return;
	}
	//if (window.console) console.log( "initializing community map." );

	var mapDiv = this[0];

	var directionsDisplay = new google.maps.DirectionsRenderer();
	var latitude = $("#latitude").html();
	var longitude = $("#longitude").html();
	var center = new google.maps.LatLng(latitude, longitude);
	var myOptions = {
		zoom:14,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		center: center
	};
	var map = new google.maps.Map(mapDiv, myOptions);
	var marker = new google.maps.Marker({position:center, map:map});
	directionsDisplay.setMap(map);
	
	$('#directions_button').click(function(e){
		e.preventDefault();
		var start = document.getElementById("from").value;
		var end = document.getElementById("to").value;
		var request = {
			origin:start,
			destination:end,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};
		var directionsService = new google.maps.DirectionsService();
		directionsService.route(request, function(result, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				directionsDisplay.setDirections(result);
			}
		});
		/*
		//Google Adwords Driving Directions tracking tags
		var googleDrivingConversionID_0 = "1029207100";
		var googleDrivingConversionLabel_0 = "SvR6CIz85QEQvOjh6gM";
		var googleDrivingConversionID_1 = "1017034488";
		var googleDrivingConversionLabel_1 = "fXcACNjv2wEQ-O365AM";
		var googleDrivingConversionID_2 = "1018521298";
		var googleDrivingConversionLabel_2 = "g01WCN7d3QEQ0s3V5QM";
		
		var gTagBegin = '<div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/';
		var gTagMid = '/?label=';
		var gTagEnd = '&amp;guid=ON&amp;script=0"/></div>';
		
		var googleDrivingTag_0 = gTagBegin + googleDrivingConversionID_0 + gTagMid + googleDrivingConversionLabel_0 + gTagEnd;
		var googleDrivingTag_1 = gTagBegin + googleDrivingConversionID_1 + gTagMid + googleDrivingConversionLabel_1 + gTagEnd;
		var googleDrivingTag_2 = gTagBegin + googleDrivingConversionID_2 + gTagMid + googleDrivingConversionLabel_2 + gTagEnd;

		var sdpixsDiv = document.getElementById("sd_driving_pixs");
		sdpixsDiv.innerHTML = googleDrivingTag_0+googleDrivingTag_1+googleDrivingTag_2;
		 
		//Google Analytics virtual pageview - Driving Direction Success
		_gaq.push(
			['C001._trackPageview','/driving_direction/success.html'],
			['C000._trackPageview','/driving_direction/success.html'],
			['C002._trackPageview','/driving_direction/success.html'],
			['C_Rollup._trackPageview','/driving_direction/success.html']
		);
		*/
		siteCatalystDirections();
		// Yahoo retargeting pixel
		$(document.body).append('<img src="http://ads.bluelithium.com/pixel?id=' + yblIdLeadDirections + '&t=2" width="1" height="1" />');
		pointRoll(prIdDirections, prPrefix);
	});
	//if (window.console) console.log( "end initializing community map." );
	return this;
};
pointRoll = function(id,prefix){
	var prd=new Date(),pru=Date.UTC(prd.getUTCFullYear(),prd.getUTCMonth(),prd.getUTCDay(),prd.getUTCHours(),prd.getUTCMinutes(),prd.getUTCSeconds(),prd.getUTCMilliseconds());
	var pr_eid=pru+Math.random();
	var pr_href="http://container.pointroll.com/event/?ctid="+id+"&av=6553&eid="+pr_eid+"&ev=&item=&q=&val=&r="+Math.random();
	$(document.body).append('<iframe width="0" height="0" frameborder="0" src="'+pr_href+'" id="'+(!prefix ? '' : prefix+id)+'"></iframe>');
};
$(document).ready(function () {
	// Yahoo retargeting pixel
	$(document.body).append('<img src="http://ads.bluelithium.com/pixel?id=' + yblIdHomepage + '&t=2" width="1" height="1" />');
	pointRoll(prIdHomepage);
	// 24/7 Media retargeting pixel
	$(document.body).append('<img src="http://network.realmedia.com/' + tfmSuffixHomepage + '" />');
	$('#state_map_canvas').stateMap();

	$('#community_map_canvas').communityMap();
	$('#gallery').galleryView({
		panel_width: 374,
		panel_height: 242,
		border: 0,
		transition_speed: 1500,
		transition_interval: 0,
		pause_on_hover: false,
		nav_theme: 'dark',
		img_path: window.staticPath + 'brands/' + brandSlug + '/images/themes/'
	});

	$('#region_map_canvas').regionMap();

	$('#primary_form_div').listForm();

	$('#primary_form.mad-form').madForm();
	$('#list_form.mad-form').madForm();

	$('#primary_form.sign-form').standardForm();
	$('#list_form.info-form').standardForm();

	// Fancybox settings
	$("a#communityVideo").fancybox({
		frameWidth: 480,
		frameHeight: 295,
		overlayShow: true,
		overlayOpacity: 0.85,
		overlayColor: '#000'
	});

	$(".btn-floorplan").bind('click', function () {
		var id = $(this).attr("id");
		id = id.replace("#planId-", "");
		$.ajax({
			url: "/floorplans/" + id,
			success: function (data) {
				$.fancybox(data,
				{
					frameWidth: 900,
					frameHeight: 350,
					overlayShow: true,
					overlayOpacity: 0.85,
					overlayColor: '#000'
				});
				$.fancybox.resize();
			}
		});
		return false;
	});

});

