function applyCalendar() {
	var self = this;
	self.init = function() {
		if($(".date-pick").length > 0) {
			$.datepicker.setDefaults({
			   showOn: 'both',
			   buttonImageOnly: true,
			   buttonImage: '/t/images/calendar.gif',
			   buttonText: 'Calendar',
			   prevText: '<',
			   nextText: '>'
			});
			$(".date-pick").datepicker();
		}
	};
	self.init();
}
function applyRequired() {
	var self = this;
	self.init = function() {
		if($(".vf__required label").length > 0) {
			//$(".vf__required label").append('*');
		}
	};
	self.init();
}
function applyRadio() {
	var self = this;
	self.init = function() {
		if($("input").length > 0) {
			$("input").each(function() {
				if($(this).is(":checked")) {
					$(this).parent("label").addClass("checked");
				}
			});
		}
		if($(".radio .vf__list").length>0) {
			$(".radio .vf__list label").click(function() {
				$(this).siblings(".checked").removeClass("checked");
				$(this).addClass("checked");
 			});
		}
	};
	self.init();
}

/*
//Keep the overlay the same width and height as the browser
function setDimensions(){
	var w = parseInt($(window).width())+'px';
	var h = ($(document).height() > $(window).height()) ? parseInt($(document).height())+'px' : $(window).height() + 'px';
	$(".ui-widget-overlay")
		.css("width", w)
		.css("height", h);
}
$(window).resize(function(){setDimensions();});
*/
function applyDialog() {
	//In order to use the dialog you need to create a link containing a rel attribute that is identical to the class attribute on the dialog block
	var self = this;
	self.linkRelAttr = "";
	self.width = 500;//Default width for the dialog
	self.title = "";//Default title for the dialog
	
	
	//This function will convert any items with the class attribute beginning with dialog to a dialog modal window
	self.init = function() {
		if($('[class^=dialog]').length > 0) {
			
			$('[class^=dialog]').each(function() {
				if($(this).attr("width") != null) {
					self.width = parseInt($(this).attr("width"),10);
				}
				if($(this).attr("title") != null) {
					self.title = $(this).attr("title");
				}
				$(this).dialog({
					autoOpen: false,
					modal: true,
					resizable: false,
					draggable: false,
					position: 'top',
					closeText: 'X',
					width: self.width,
					title: self.title
				});
			});
		}
		self.applyDialogLink();
	};
	
	//This will apply the dialog click functionality to any links containing the rel attribute beginning with dialog
	self.applyDialogLink = function() {
		if($('[rel^=dialog]').length > 0) {
			$('[rel^=dialog]').unbind('click').click(function() {
				self.linkRelAttr = $(this).attr("rel");
				if($("." + self.linkRelAttr).length > 0) {
					jQuery('html, body').animate({scrollTop: 0}, 250);
					$("." + self.linkRelAttr).dialog("open");
					$(".ui-widget-overlay").show();
						//
						$(".ui-widget-overlay").click(function(){
							$(this).remove();
							$("." + self.linkRelAttr).dialog("close");
							$(".ui-widget-overlay").hide();
						});
					return false;
				}
			});
		}
	};
	self.init();
}
function imageArrowOverlay() {
	var self = this;
	self.overlayCode = "<span class='overlay'>></span>";
	self.init = function() {
		/*
		if($("#posts .post img").length > 0) {
			$("#posts .post img").each(function() {
				$(this).parent().append(self.overlayCode);
			});
		}*/
		if($("#home .slide-details").length > 0) {
			$("#home .slide-details").append(self.overlayCode);
		}
		if($("#badges div a").length > 0) {
			$("#badges div a").append(self.overlayCode);
		}
		/*
		if($("#gallery #thumbnails img").length > 0) {
			$("#gallery #thumbnails img").each(function() {
				$(this).parent().append(self.overlayCode);
			});
		}*/
		if($(".sold_out").length > 0) {
			$(".sold_out").each(function() {
				$(this).append("<span class='overlay'>SOLD<br />OUT</span>");
			});
		}
	};
	self.init();
}
function addRightArrow() {
	var self = this;
	self.ra = "&nbsp;>";//Internal linking right arrows
	self.era = "&nbsp;>>";//External linking right arrows
	self.init = function() {
		if($("#global-navigation a").length > 0) {
			$("#global-navigation a").append(self.ra);
		}
		if($("#promo-pattern a").length > 0) {
			$("#promo-pattern a").append(self.ra);
		}
		if($("#standard .left-col a").length > 0) {
			$("#standard .left-col a").append(self.ra);
		}
		if($("#testimonials .left-col a").length > 0) {
			$("#testimonials .left-col a").append(self.ra);
		}
		if($("#standard .middle-col a").length > 0) {
			//$("#standard .middle-col a").append(self.ra);
		}
		if($("#contact-banner a").length > 0) {
			$("#contact-banner a").append(self.ra);
		}
		if($("#blog .right-col ul a").length > 0) {
			$("#blog .right-col ul a").append(self.ra);
		}
		if($(".cta").length > 0) {	
			$(".cta").append(self.ra);
		}
		if($(".floorplan-navigation a").length > 0) {
			$(".floorplan-navigation a").append(self.ra);
		}
		$('a[rel="external"]').each(function(){
  			$(this).append(self.era);
		});

	};
	self.init();
}
function coverflow() {
	
	//Pagination
	var totalEntries = $(".cover").length;
	var totalPages = Math.ceil(totalEntries / 4);
	
	//Test's and switches the active state on the pages
	function activeTest(){
		var pos = $(".entryContainer").position().left;
		if ($('.links a[rel|="'+pos+'"]').length == 1){
			
			$(".links a").removeClass("active");
			$('.links a[rel|="'+pos+'"]').addClass("active");
		}else{}
	}
	
	//Hide controls if they are not needed
	if(totalEntries <= 4){
		$(".coverflow_controllers").hide();
	}
	
	//Set width of coverflow to accomodate all entries
	$(".coverflow").width(244 * totalEntries);
	$(".coverTabs .links").width(36 * totalPages);
	
	//Render page links
	var i = 0;
	while(i < totalPages){
		var pos = -976 * i;
		$(".coverTabs .links").append('<a rel="'+pos+'">'+parseInt(i+1)+'</a>');
		i++;
	}
	
	//Sets the first link as active
	$(".links a:eq(0)").addClass("active");
	
	//Next Button
	$(".coverflow_controllers a.nextCover").click(function(){

		if( $(".entryContainer").position().left ==  $(".links a:last").attr("rel")){
			return false;
		}
		
		var slideDistance = $(".entryContainer").position().left - 244; //current position minus 244
		$(".blocker").show(); //block the buttons from being clicked
		$(".entryContainer").animate({ left: slideDistance+'px' }, 400, function(){
			$(".blocker").hide();
			activeTest();
		});
		return false;
	});
	
	//Previous Button
	$(".coverflow_controllers a.prevCover").click(function(){
		if($(".entryContainer").position().left == 0){
			return false; //disable the button if the view is at the start.
		} else {
			var slideDistance = Number($(".entryContainer").position().left) + Number(244);		
			$(".blocker").show();
			$(".entryContainer").animate({ left: slideDistance+'px' }, 400, function(){
				$(".blocker").hide();
				activeTest();
			});
			return false;
		}
	});
		
	//Page Buttons
	$(".links a").click(function(){
		$(".blocker").show(); 
		$(".links a").removeClass("active");
		$(this).addClass("active");
		var slideDistance = $(this).attr("rel"); 
		$(".entryContainer").animate({ left: slideDistance+'px' }, 400, function(){$(".blocker").hide();});
		return false;
	});

}

function slideShow(autoPlay) {
	autoPlay = (autoPlay == null) ? autoPlay : "";
	var self = this;
	self.slideShowContainer = "slideshow";
	self.slideClass = "slide";
	self.slideMaskContainer = "slide-mask-container";
	self.activeSlideIndex = 0;
	self.nextButtonClass = "next";
	self.prevButtonClass = "prev";
	self.tabs = "tabs";
	self.tabsContainer = "tabs_container";
	self.tabsContainerWidth = "";
	self.tabsContainerPadding = "";
	self.interval = 7000;
	self.fadeSpeed = 700;
	self.intervalFunction = "";
	self.autoPlay = true;
	self.imageHeight = "";
	self.imageHeight = "";
	
	if(autoPlay == false) {
		self.autoPlay = false;
	} else if(autoPlay == "") {
		self.autoPlay = true;
	}
	
	self.init = function() {
		if($("." + self.slideShowContainer).length > 0) {
			
			//Build the slideshow
			if($("." + self.slideMaskContainer).length > 0) {
				if($("." + self.slideClass).length > 0) {
					
					//If there is only one slide be sure to stop autoplay and disable the controls
					if($("." + self.slideShowContainer + " ." + self.slideClass).length <= 1) {
						self.autoPlay = false;
						$("." + self.slideShowContainer + " ." + self.tabsContainer).css({
																				 "display" : "none"
																				 });
					}
					//Retrieve the image dimensions to size the slideshow accordingly.
					//This means that using the build_image_tag function we can specify the width and height of the slideshow.
					self.imageHeight = ($("." + self.slideShowContainer + " img").height()) + "px";
					self.imageWidth = ($("." + self.slideShowContainer + " img").width()) + "px";
					
					//Size the tabs area dynamically based on the image dimensions
					if($("." + self.tabsContainer).length > 0) {
						self.tabsContainerWidth = $("." + self.tabsContainer).css("width");
						self.tabsContainerWidth = parseInt(self.imageWidth) - parseInt(self.tabsContainerWidth);
						self.tabsContainerPadding = self.tabsContainerWidth / 2 + "px";
						$("." + self.tabsContainer).css("paddingLeft",self.tabsContainerPadding);
						self.tabsContainerWidth = parseInt(self.imageWidth) - parseInt(self.tabsContainerPadding) + "px";
						$("." + self.tabsContainer).css("width",self.tabsContainerWidth);
					}
					
					//Size the actual slide area and its outer container dynamically based on the image dimensions
					$("." + self.slideClass).css('height', self.imageHeight);
					$("." + self.slideClass).css('width', self.imageWidth);
					$("." + self.slideMaskContainer).css('height', self.imageHeight);
					$("." + self.slideMaskContainer).css('width', self.imageWidth);	
					
					//Hide the slides and fire the first one to active
					$("." + self.slideClass).hide();
					$("." + self.slideClass).eq(self.activeSlideIndex).show();
					$("." + self.slideMaskContainer).fadeIn(self.fadeSpeed, function() {
						if(self.autoPlay == true) {
							self.intervalFunction = setInterval(function() { self.loadSlide("+"); }, self.interval);
						} else {
						}
					});
				}
			}	
						
			//Setup the next and previous button functionality
			if($("." + self.nextButtonClass).length > 0) {
				$("." + self.nextButtonClass).click(function() {
					clearInterval(self.intervalFunction);
					self.loadSlide("+");
					return false;
				});
			}
			if($("." + self.prevButtonClass).length > 0) {
				$("." + self.prevButtonClass).click(function() {
					clearInterval(self.intervalFunction);
					self.loadSlide("-");
					return false;
				});
			}
			
			//Setup the tabs button functionality
			if($("." + self.tabs + " a").length > 0) {
				$("." + self.tabs + " a").click(function() {
					clearInterval(self.intervalFunction);
					self.loadSlide($(this).index());
					return false;
				});
			}
		}
	}
	
	self.loadSlide = function(action) {
		if(self.activeSlideIndex != action) {
			$("." + self.slideClass).eq(self.activeSlideIndex).fadeOut(self.fadeSpeed);
			
			if(action == "+") {
				if(self.activeSlideIndex + 1 > $("." + self.slideClass).length - 1) {
					self.activeSlideIndex = 0;
				} else {
					self.activeSlideIndex = self.activeSlideIndex + 1;
				}
			} else if(action == "-") {
				if(self.activeSlideIndex - 1 < 0) {
					self.activeSlideIndex = $("." + self.slideClass).length - 1;
				} else {
					self.activeSlideIndex = self.activeSlideIndex - 1;
				}
			} else if(isFinite(String(action))) {
				self.activeSlideIndex = action;
			}
			
			$("." + self.slideClass).eq(self.activeSlideIndex).fadeIn(self.fadeSpeed);
			if($("." + self.tabs + " a").length > 0) {
				$("." + self.tabs + " a").each(function() {
					$(this).removeClass("active");
				});
				$("." + self.tabs + " a").eq(self.activeSlideIndex).addClass("active");
			}
		}
	}	
	self.init();
}
function gallerySlideShow() {
	var self = this;
	self.slideShowDialogContainer = "ui-dialog";
	self.slideShowContainer = "slideshow";
	self.slideMaskContainer = "slide-mask-container";
	self.slideMaskContainerWidth = 800;
	self.slideMaskContainerHeight = 532;
	self.slideClass = "slide";
	self.slideDetailsClass = "slide-details"
	self.slideDetailsBlurb = "";
	self.slideDetailsClassTarget = "slide-meta";
	self.slideCountContainer = "slide-count";
	self.currentSlideClass = "currentSlide";
	self.totalSlidesClass = "totalSlides";
	self.totalSlidesCount = 0;
	self.nextButtonClass = "next";
	self.prevButtonClass = "prev";
	self.activeSlideHeight = 0;
	self.activeSlideIndex = 0;
	self.thumbnailsContainer = "thumbnails";
	self.thumbnailIndex = 0;
	self.fadeSpeed = 200;
	self.browserWidth = $(window).width();
	self.leftPosition = 0;
	self.tooltipClass = "tooltip";
	self.current_path = window.location.hash;
	self.dialogGalleryClass = "dialog-gallery";
	self.hitIndex = false;
	self.sharePath = "";
	self.shareContainerClass = "social-search";
	self.activateButtonClass = "activate-gallery";
	
	self.init = function() {
		if($("." + self.slideShowContainer).length > 0) {
						
			//If including a general Start or Activate button
			if($("." + self.activateButtonClass).length > 0) {
				$("." + self.activateButtonClass).click(function() {
					self.loadSlide(self.activeSlideIndex);
					return false;
				});
			}

			//Fire up the gallery if #permalink is defined within the url
			if(self.current_path != "") {
				self.current_path = self.current_path.replace("#", "");
				self.activeSlideIndex = $("." + self.slideClass + " img[src$='" + self.current_path + "']").parent($("." + self.slideClass)).index();
				if(self.activeSlideIndex >= 0) {
					$("." + self.dialogGalleryClass).dialog("open");
					self.loadSlide(self.activeSlideIndex);
				}
			}
			
			//Setup the thumbnail buttons
			if($("#" + self.thumbnailsContainer + ' a[rel="dialog-gallery"]').length > 0) {
				$("#" + self.thumbnailsContainer + ' a[rel="dialog-gallery"]').click(function() {
					self.thumbnailIndex = $("#" + self.thumbnailsContainer + ' a[rel="dialog-gallery"]').index($(this));
					self.loadSlide(self.thumbnailIndex);
					return false;
				});
			}
						
			//Setup the button functionality
			if($("." + self.nextButtonClass).length > 0) {
				$("." + self.nextButtonClass).click(function() {
					self.slideForward();
					return false;
				});
			}
			
			if($("." + self.prevButtonClass).length > 0) {
				$("." + self.prevButtonClass).click(function() {
					self.slideBackward();
					return false;
				});
			}
		}
	}
	
	self.updateShareIcons = function(filename) {
		var fbLikeClass = "fb_like";
		var fbShareClass = "st_facebook";
		var twitterShareClass = "st_twitter";
		var shareThisClass = "st_sharethis";
		
		var shareThisURL = $("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + shareThisClass).attr("st_url"); //We can use this as the base to rebuild the others
		shareThisURL = shareThisURL.split("#");
		shareThisURL = shareThisURL[0] + "#" + filename;

		var newFBLikeURL = "http://www.facebook.com/plugins/like.php?href=" + shareThisURL + "&layout=standard&show_faces=false&width=450&action=like&colorscheme=light&height=35";
		var newFBShareURL = "http://wd.sharethis.com/api/sharer.php?destination=facebook&url=" + shareThisURL + "&publisher=ad31c817-a75f-4b0c-b927-fb69bc30bfa9";
		var newTwitterShareURL = "http://wd.sharethis.com/api/sharer.php?destination=twitter&url=" + shareThisURL + "&publisher=ad31c817-a75f-4b0c-b927-fb69bc30bfa9";
		var newShareThisURL = shareThisURL;


		if($("." + self.slideShowContainer + " ." + self.shareContainerClass).length > 0) {
			
			if($("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + fbLikeClass).length > 0) {
				$("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + fbLikeClass).attr("src", newFBLikeURL);
			}
			if($("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + fbShareClass).length > 0) {
				$("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + fbShareClass).attr("st_url", newFBShareURL);
			}
			if($("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + twitterShareClass).length > 0) {
				$("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + twitterShareClass).attr("st_url", newTwitterShareURL);
			}
			if($("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + shareThisClass).length > 0) {
				$("." + self.slideShowContainer + " ." + self.shareContainerClass + " ." + shareThisClass).attr("st_url", newShareThisURL);
			}
		}
	}
	
	self.loadSlide = function(action) {
			var currentSlide = $("." + self.slideClass).eq(self.activeSlideIndex);
			if(action == "+") {
				self.activeSlideIndex = self.activeSlideIndex + 1;	
			} else if(action == "-") {
				self.activeSlideIndex = self.activeSlideIndex - 1;	
			} else if(isFinite(String(action))) {
				self.activeSlideIndex = action;
				self.hitIndex = true;
			} else {
				self.activeSlideIndex = self.activeSlideIndex;
			}
			
			//Retrieve the filename of the current slide for use in the share options
			if($("." + self.slideClass).find('.st_sharethis').length > 0){
				self.sharePath = $("." + self.slideClass).eq(self.activeSlideIndex).children("img").attr("src");
				var filename = (self.sharePath.indexOf("?") == -1) ? self.sharePath.length : self.sharePath.indexOf("?");
				filename = self.sharePath.substring(self.sharePath.lastIndexOf("/")+1, filename);
				self.updateShareIcons(filename);
			}
			var src = $("." + self.slideClass).eq(self.activeSlideIndex).find("img").attr('src');
			var activeSlideHeight = $("." + self.slideClass).eq(self.activeSlideIndex).find("img").attr('height');
			var activeSlideWidth = $("." + self.slideClass).eq(self.activeSlideIndex).find("img").attr('width');
			var nextPrevPosition = activeSlideHeight/2 - ($("." + self.nextButtonClass).height())/2;
			
			self.leftPosition = (self.browserWidth - activeSlideWidth) / 2;
			
			
			//Setup the tooltips functionality
			if($("." + self.slideClass).eq(self.activeSlideIndex).find("a.tooltip-fire").length > 0) {
				$("." + self.slideClass).eq(self.activeSlideIndex).find("a.tooltip-fire").click(function(){
					return false;
				});
				$("." + self.slideClass).eq(self.activeSlideIndex).find(".tooltip-fire").tooltip({
					effect: 'fade',
					delay: self.fadeSpeed
				});	
			}
			
			if(self.hitIndex) {
				self.fadeSpeed = 0;
			}
			$("." + self.slideShowContainer).parent("." + self.slideShowDialogContainer).fadeOut(self.fadeSpeed, function() {
				currentSlide.css('zIndex', 0);
				$("." + self.slideClass).eq(self.activeSlideIndex).css('zIndex', 1);
				self.fadeSpeed = 200;
				self.countSlides();
				self.describeSlide();
				$("." + self.prevButtonClass).css('top', nextPrevPosition);
				$("." + self.nextButtonClass).css('top', nextPrevPosition);
				$("." + self.slideMaskContainer).css({'width' : activeSlideWidth, 'height' : activeSlideHeight});
				$("." + self.slideShowContainer).parent("." + self.slideShowDialogContainer).css({'width' : activeSlideWidth, 'position':'absolute','top':'0px', 'height' : 'auto', 'left' : self.leftPosition});
				$("." + self.slideShowContainer).parent("." + self.slideShowDialogContainer).fadeIn(self.fadeSpeed);
				
			});	
			self.hitIndex = false;
	}
	self.slideForward = function() {
		if((self.activeSlideIndex + 1) > $("." + self.slideClass).length - 1) {
			self.activeSlideIndex = $("." + self.slideClass).length - 1;
		} else {
			self.loadSlide("+");
		}	
	}
	
	self.slideBackward = function() {
		if((self.activeSlideIndex - 1) >= 0) {
			self.loadSlide("-");
		} else {
			self.activeSlideIndex = 0;
		}
	}
	
	self.describeSlide = function() {
		if($("." + self.slideDetailsClass).length > 0) {
			$("." + self.slideDetailsClass).hide();
			self.slideDetailsBlurb = $("." + self.slideDetailsClass).eq(self.activeSlideIndex).text();
			$("." + self.slideDetailsClassTarget).text(self.slideDetailsBlurb);
			$("." + self.slideDetailsClassTarget).show();
		}
	}

	self.countSlides = function() {
		self.totalSlidesCount = $("." + self.slideClass).length;
		if($("." + self.slideCountContainer).length > 0) {
			if($("." + self.currentSlideClass).length > 0) {
				$("." + self.currentSlideClass).html(self.activeSlideIndex + 1);
			}
			if($("." + self.totalSlidesClass).length > 0) {
				$("." + self.totalSlidesClass).html(self.totalSlidesCount);
			}
		}
	}

	self.init();
}
function toggleViews() {
	var self = this;
	self.hideShowClass = "hide-show-";
	

	self.init = function() {
		if($("a[class*=" + self.hideShowClass + "]").length > 0) {
		
			self.hideAll();	
			
			//Add the click functionality to hide and show divs
			$("a[class*=" + self.hideShowClass + "]").click(function() {
				self.hideAll();
				
				var rel = $(this).attr("class");
				$("div").each(function() {
					if( $(this).attr("class") == rel ) {
						$(this).show();
					}
				});
				return false;
			});
			
			
		}
	}
	
	self.hideAll = function() {
		//Hide divs containing this class
		if($("div[class*=" + self.hideShowClass + "]").length > 0) {
			$("div[class*=" + self.hideShowClass + "]").hide();
		}
	}
	
	self.init();
}
function SetupFloorPlans(){
	var self = this;
	self.container = ".slideshow";
	self.current_slide = 0;
	self.total_slides = 0;
	self.next_slide = 0;
	self.init = function(){
		$('.floorplan a[rel="floorplan"]').unbind('click').click(function(){
			plan_id = $(this).parent().parent().parent().attr('id').replace('floorplan_','').replace(/_/g,"-");
			classname = $(this).attr("class");
			self.get_floorplan(plan_id, classname);
			return false;
		});
		$('.floorplan a[rel="floorplan_thumbnail"]').unbind('click').click(function(){
			plan_id = $(this).parent().attr('id').replace('floorplan_','').replace(/_/g,"-");
			classname = $(this).attr("class");
			self.get_floorplan(plan_id, classname);
			return false;
		});
	}
	self.get_floorplan = function(plan_id,classname){
		$.post('/t/get_floorplan.php',{ id: plan_id }, function(data){
			$('#selected_floorplan').remove();
			$('body').append(data);
			self.setup_floorplan(classname);
		});
		
		return true;
	}
	self.setup_floorplan = function(classname){
		$("#selected_floorplan").dialog({
			modal: true,
			resizable: false,
			draggable: false,
			position: 'top',
			closeText: 'X',
			width: 900
		});
		$('.ui-widget').css('margin-top', '50px');
		$('.ui-widget-overlay').show();
		$('html,body').animate({scrollTop: $('.ui-widget').offset().top - 100 }, 1000);
				
		self.hideAll();		
		var rel = "hide-show-" + classname;
		$("#selected_floorplan div").each(function() {
			if( $(this).attr("class") == rel ) {
				$(this).show();
			}
		});
			
		//Add the click functionality to hide and show divs
		$("#selected_floorplan a[rel^='floorplan']").click(function() {
			self.hideAll();
			
			var rel = "hide-show-" + $(this).attr("class");
			$("div").each(function() {
				if( $(this).attr("class") == rel ) {
					$(this).show();
				}
			});
			return false;
		});
		self.setup_gallery();
		
	}
	self.setup_gallery = function(){
		self.total_slides = $('#selected_floorplan div.slide').length - 1;
		$('#selected_floorplan div.slide:gt(0)').hide();
		$('#selected_floorplan div.slide:eq(0)').addClass('active');
		$('#selected_floorplan a.prev').addClass('disabled');
		
		$('.tabs a').unbind('click').click(function(){
			$('.tabs a.active').removeClass('active');
			$(this).addClass('active');			
			self.loadSlide($(this).index());			
			return false;
		});
		
		$('#selected_floorplan a.prev').unbind('click').click(function(){
			if($(this).hasClass('disabled')) return false;
			self.goto_slide(-1);
			return false;
		});
		$('#selected_floorplan a.next').unbind('click').click(function(){
			if($(this).hasClass('disabled')) return false;
			self.goto_slide(1);
			return false;
		});
	}
	self.goto_slide = function(direction){
		if(self.current_slide + direction > self.total_slides || self.current_slide + direction < 0) return false;
		self.current_slide += direction;
		self.loadSlide(self.current_slide);
		return true
	}
	self.loadSlide = function(index){
		if(index == 0) {
			$('#selected_floorplan a.next').removeClass('disabled');
			$('#selected_floorplan a.prev').addClass('disabled');
		} else if(index == self.total_slides) {
			$('#selected_floorplan a.prev').removeClass('disabled');
			$('#selected_floorplan a.next').addClass('disabled');
		}
		if(index == 0 && index == self.total_slides) {
			$('#selected_floorplan a.prev').addClass('disabled');
			$('#selected_floorplan a.next').addClass('disabled');
		}
		
		$('.tabs a.active').removeClass('active');
		$('.tabs a:eq('+index+')').addClass('active');
			
		$('#selected_floorplan .slide.active').fadeOut('slow',function(){
			$(this).removeClass('active');
		});
		$('#selected_floorplan .slide:eq(' + index + ')').fadeIn('slow', function(){
			$(this).addClass('active');
		});
		
	}
	self.hideAll = function() {
		//Hide divs containing this class
		if($("#selected_floorplan div[class*='hide-show-']").length > 0) {
			$("#selected_floorplan div[class*='hide-show-']").hide();
		}
	}
	
	self.init();
}
function floorplansSold() {
	
	var self = this;
	self.soldClass = "sold";
	
	self.init = function() {
		if($("." + self.soldClass).length > 0) {
			var height = $("." + self.soldClass).height();
			var width = $("." + self.soldClass).width();
			$("." + self.soldClass).append("<span class='overlay'>Sold out</span>");
			$("." + self.soldClass).append("<div class='sold-out' style='width:" + width + "px; height:" + height + "px;'></div>");
		}
	}
	
	self.init();
}
function printPage() {
	var self = this;
	self.init = function() {
		if($(".print-this-page").length > 0) {
			$(".print-this-page").click(function() {
				window.print();
				return false;
			});
		}
	}
	
	self.init();
}




/* DOCUMENT READY FUNCTION
*************************************************************/
	
	//View all funtionality
	var list = $(".right-col .top_five ul");
	var h = list.height();

	list.each(function(){
				
		if($(this).find("li").length > 5){
			if($(this).attr("class") == 'latest_articles'){
				$(".la_va").show();
			} else {
				$(".lt_va").show();
			}
		} else{
			//Don't show links
		}
	});
	
	//If an article is accessed by the latest articles link, it will auto expand the list.
	if(location.search == '?la=true'){
		$(".right-col .top_five ul.latest_articles").animate({height: h});
		$(".la_va").hide();
		$(".la_vl").show();
	} else {
		list.css("height",'83px');
	}
	
	$(".la_va").click(function(){
		$(".right-col .top_five ul.latest_articles").animate({height: h});
		$(this).hide();
		$(".la_vl").show();
		return false;
	});
	$(".la_vl").click(function(){
		$(".right-col .top_five ul.latest_articles").animate({height: '84px'});
		$(this).hide();
		$(".la_va").show();
		return false;
	});
/*
	$(".lt_va").click(function(){
		$(".right-col .top_five ul.latest_tags").animate({height: h});
		$(this).hide();
		$(".lt_vl").show();
		return false;
	});
	$(".lt_vl").click(function(){
		$(".right-col .top_five ul.latest_tags").animate({height: '84px'});
		$(this).hide();
		$(".lt_va").show();
		return false;
	});
*/	
	
	
	//Show news posts based on tag's
	/*
	$(".meta a").each(function(){	
		var tag = $(this).html();
		var page = location.href.split("/");
		
		// Select the correct page url
		if(page[4]){
			page = page[4];
		} else{
			page = page[3];
		}
		
		//Show appropriate posts		
		if(page.search(tag) != -1){
			$(this).parent().parent().show();
		}
		
		//Show all posts if no posts are tag based
		if($(".post:visible").length == 0){
			$(".post").show();
		}
	});*/
	
	//
	
	$(".left-col a").each(function(){
		if($(this).html() == 'Register&nbsp;&gt;'){
			$(this).attr("rel", "dialog-register-form");
			$(this).click(function(){
				self.linkRelAttr = $(this).attr("rel");
				if($("." + self.linkRelAttr).length > 0) {
					$("." + self.linkRelAttr).dialog("open");
						//
						$(".ui-widget-overlay").show();
						$(".ui-widget-overlay").click(function(){
							$(this).remove();
							$("." + self.linkRelAttr).dialog("close");
						});
					return false;
				}
			});
		}
	});
	
	$("a[rel='dialog-register-form']").each(function(){
		$(this).click(function(){
			self.linkRelAttr = $(this).attr("rel");
			if($("." + self.linkRelAttr).length > 0) {
				$("." + self.linkRelAttr).dialog("open");
					//
					$(".ui-widget-overlay").show();
					$(".ui-widget-overlay").click(function(){
						$(this).remove();
						$("." + self.linkRelAttr).dialog("close");
					});
				return false;
			}
		});
	});
	
	$(".st_sharethis").click(function(){
		return false;
	});
	
$(document).ready(function(){
	if($(".act_slide .slide-mask-container").length > 0) {
		var slideShowGo = new slideShow();
	}
});
	
	
	
	
	
	
//Custom select menu	
function ddownProperties(passThis) {
	var self = this;
	self.ddownContainer = passThis;
	self.optionsContainer = "ul";
	self.optionsTrigger ="#ddown_activate";
	self.init = function() {
		if($(self.ddownContainer + " " + self.optionsContainer).length > 0) {
			if($(self.ddownContainer + " " + self.optionsContainer + " li a").length > 0) {
				self.showOptions();
			}
			$(self.ddownContainer + " " + self.optionsContainer).hide();
		}
	}
		
	self.showOptions = function() {
		$(self.ddownContainer).mouseout(function() {
			$(self.ddownContainer + " " + self.optionsContainer).hide();
		});
		$(self.ddownContainer).mouseover(function() {
			$(self.ddownContainer + " " + self.optionsContainer).show();
		});
	}
	self.init();
}
var ddownMen = new ddownProperties("#ddown_properties");

