function toggle_home_paragraph() {
	var self = this;
	self.init = function () {
		if($(".copy p").length > 0) {
			self.show_clicked(0);
		}
		if($("h2 a").length > 0) {
			$("h2 a").click(function() {
				var i = 0;
				var key = $(this).index();
				self.show_clicked($(this).index("h2 a"));
				self.resetLinkState();
				$(this).addClass("active");
				return false;
			});
		}
	}
	self.show_clicked = function(key) {
		var i = 0;
		$(".copy p").css({
			 'display':'none',
			 'opacity': 0
		 });
		$(".copy p").each(function() {
			if(i == key) {
				$(this).css({'display':'block'});
				$(this).animate({'opacity':1}, 750);
			}
			i++;
		});
	}
	self.resetLinkState = function() {
		$("h2 a").removeClass("active");
	}
	self.init();
}





/* SLIDESHOW FUNCTIONALITY
*************************************************************/
function slideshow() {
    var self = this;
    self.slideShowContainer = ".slideshow";//Used to contain the entire slideshow
    self.slideClass = ".slide";//Used to contain specific slide image and details
    self.activeSlideIndex = 0;//Defaults the slideshow to show the first slide on load
    self.interval = 5000;//Determines how frequent, on autoplay, the load slide function will fire. This is in milliseconds
    self.fadeSpeed = 2500;//Determines the timing of the transition between each slide fade
    self.autoPlay = true;//Used to determine whether or not the slideshow should play on load, or pause on the first slide.
    self.intervalFunction = "";//Defined within the build with the setinterval js function
    self.startingOpacity = 0;
    
    self.init = function() {
        if($(self.slideShowContainer).length > 0) {
            
            $(self.slideShowContainer).animate({opacity: self.startingOpacity}, 0);
            
            //Build the slideshow
			if($(self.slideShowContainer + " " + self.slideClass + " img").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;
				}
				
				//To allow for positioning of internal elements we need to apply the relative positioning to the overall slideshow
				$(self.slideShowContainer).css({
											   'position' : 'relative'
											   });
				
				//To provide clean transitions we need to position the slides absolute and on top of each other
				$(self.slideShowContainer + " " + self.slideClass).css({
									   'position' : 'absolute',
									   'top' : '0px',
									   'z-index' : '1'
									   });
									
				//Hide the slides and fire the first one to active
				$(self.slideShowContainer + " " + self.slideClass).hide();

				$(self.slideShowContainer + " " + self.slideClass).eq(self.activeSlideIndex).show();
				if(self.autoPlay) {
					self.intervalFunction = setInterval(function() { self.loadSlide("+"); }, self.interval);
				}
			}
        }
    }
    
    //Load a slide function
    self.loadSlide = function(action) {
        if(self.activeSlideIndex != action) {
            $(self.slideShowContainer + " " + self.slideClass).eq(self.activeSlideIndex).fadeOut(self.fadeSpeed);
            if(action == "+") {
                if(self.activeSlideIndex + 1 > $(self.slideShowContainer + " " + self.slideClass).length - 1) {
                    self.activeSlideIndex = 0;
                } else {
                    self.activeSlideIndex = self.activeSlideIndex + 1;
                }
            } else if(action == "-") {
                if(self.activeSlideIndex - 1 < 0) {
                    self.activeSlideIndex = $(self.slideShowContainer + " " + self.slideClass).length - 1;
                } else {
                    self.activeSlideIndex = self.activeSlideIndex - 1;
                }
            } else if(isFinite(String(action))) {
                self.activeSlideIndex = action;
            }            
            
            $(self.slideShowContainer + " " + self.slideClass).eq(self.activeSlideIndex).fadeIn(self.fadeSpeed);
            if($(self.slideShowContainer + " " + self.tabs + " a").length > 0) {
                $(self.slideShowContainer + " " + self.tabs + " a").each(function() {
                    $(this).removeClass("active");
                });
                var currentLink = $(self.slideShowContainer + " " + self.tabs + " a").eq(self.activeSlideIndex);
                currentLink.addClass("active");
            }
        }
    }
    
    //A function that can fade in the slideshow once the page has been loaded. I do this because there are some things I align in the front-end, and I don't want the user to see the slideshow until it is built out
    self.startIt = function() {
        $(self.slideShowContainer).css({'visibility' : 'visible'});
        $(self.slideShowContainer).animate({
                        opacity: 1
                        },self.fadeSpeed);
    }
    self.init();
}



/* INPUT WATERMARKS
*************************************************************/
function InputWatermark(obj_ref,text){
	var self = this;
	
	self.input_text = (text != null) ? text : 'Enter text here...';
	self.obj_ref = obj_ref;
	
	self.init = function(){
		if(self.obj_ref == null){ return false; }
		
		$(self.obj_ref).attr("value", self.input_text);  
		
		$(self.obj_ref).focus(function () {
		    if($(this).attr("value") == self.input_text)
		        $(this).attr("value", "");
		});
		$(self.obj_ref).blur(function () {
		    if ($(this).attr("value") == "") 
		        $(this).attr("value", self.input_text);  
		});
		return true;
	};
	
	self.init();
}

/* ANCHOR FOOTER
*************************************************************/
function AnchorFooter(obj_ref) {
	var self = this;
	self.obj = obj_ref;
	
	self.init = function(){
		self.position_footer(); // call it once to initialize
		
		//set it to re-check every time the window is resized.
		$(window).resize(function() {
			self.position_footer();
		});
		return true;
	};
	
	self.position_footer = function(){
		// if the document body is shorter than the window, set the position of the footer to fixed
		if(parseInt($('body').height(), 10) < parseInt($(window).height(),10)){
			$(self.obj).css('position','fixed');
			$(self.obj).css('bottom','0');
		} else { // otherwise set it to static
			$(self.obj).css('position','static');
		}
	};
	
	self.init();
};







function addRequired() {
	var self = this;
	self.init = function () {
		if($(".vf__required").length > 0) {
			$(".vf__required label").append("*");
		}
	}
	self.init();
}

/* CHANGE ANCHOR BEHAVIOUR TO DO A SLOW SCROLL INSTEAD OF 
*  INSTANT JUMP
*************************************************************/
	$("a[rel='jump-link']").live("click", function(){
		var target = $(this).attr("href");
		var distance = $(target).offset().top;
		var origin = $(this).offset().top;
		if (distance > origin) {
			$('html,body').animate({scrollTop: distance-24 }, (distance-origin) * 0.8);
		}
		if (distance < origin) {
			$('html,body').animate({scrollTop: distance+24 }, (origin-distance) * 0.8);
		}
		return false;
	});










/* FIRE RIGHT AWAY
*************************************************************/
//var search_input = new InputWatermark("#utility_nav form input.criteria", "Search");
//var anchor_footer = new AnchorFooter("#footer");

/* DOCUMENT READY FUNCTION
*************************************************************/
$(document).ready(function(){
	$( ".calendar" ).datepicker();
	$( ".floorplan" ).dialog({
		draggable:false,
		modal:true,
		resizable: false,
		autoOpen: false
	});
	$("a#floorplan_button").click(function() {
		var dialog_width = $(".floorplan img").width() + 33;
		$(".floorplan").dialog({width: dialog_width});
		$(".floorplan").dialog("open");
		return false;
	});
	if($(".media").length > 0){
		$(".media").media();
	}
	$('.email_form').validate();
	if($("#home").length > 0) {
		var home_paragraph = new toggle_home_paragraph();
	}
	if($(".slideshow").length > 0) {
		var slideshow_obj = new slideshow();
		slideshow_obj.startIt();
	}
	if($("form").length > 0) {
		var addRequiredGo = new addRequired();
	}
});
