$(document).ready(function(){

	//show google calendar popup

	$(".check-availability").click(function(e){
		
		$("<div>").attr("id", "calendar").appendTo("#container").css({display: 'none'});
		$("#calendar").vCenter();
		
		$("#calendar").load("google-calendar.php", function(){
			$("#calendar").fadeIn();
		});
		
		return false;
		
	});
	
	//add blank targets on external links
	$("a[rel=external]").attr("target", "_blank");
	
	//default form text input stuff
	$("input[type=text]").focus(function(){
		this.value = "";
	});
	
	$("input[type=text]").blur(function(){
	
		if(this.value == ""){
			this.value = this.defaultValue;
		}
	
	});
	
	//default form textarea stuff
	$("textarea").focus(function(){
	
		if(this.value == this.defaultValue){
			this.value = "";
		}
		
	});
	
	$("textarea").blur(function(){
	
		if(this.value == ""){
			this.value = this.defaultValue;
		}
		
	});

	$(".popup").hide();


// Below can be deleted!!


	$(".thumbnail").mouseover(function(){
		
		//fade in the little popup
		var identification = this.id.replace("thumb-", "");
		
		$("#popup-"+identification).show();
		var popwidth = $("#popup-"+identification).width();
		var point = $("#popup-"+identification).find(".bottom");
		
		//now make it follow the mouse
		$(this).mousemove(function(e){
			// make sure to check for the left edge of the screen
			var offset = e.pageX - popwidth + 5;
			
			if (offset <= 1) {
				offset = 1;
				// lets make the point follow the cursor
				// if we're here.
				var halfway = (offset + popwidth)/2+27;
				if (e.pageX < halfway) {
					$(point).css({"background":"url(images/team/quote-bottom-left.gif)", "left":e.pageX});
				} else {
					$(point).css({"background":"url(images/team/quote-bottom.gif)", "left":e.pageX-27});
				}
			}
			
			var x = offset - 50;
			var y = e.pageY - 400;
			$("#popup-"+identification).css({'top' : y, 'left' : x});
			
		});
		
	});
	
	$(".thumbnail").mouseout(function(){
		var identification = this.id.replace("thumb-", "");
		$("#popup-"+identification).hide();
	});
	
	
//outdoor activity pop up 	

	$(".thumbnail-act").mouseover(function(){
		
		//fade in the little popup
		var identification = this.id.replace("thumb-", "");
		
		$("#popup-"+identification).show();
		var popwidth = $("#popup-"+identification).width();
		var point = $("#popup-"+identification).find(".bottom");
		
		//now make it follow the mouse
		$(this).mousemove(function(e){
			// make sure to check for the left edge of the screen
			var offset = e.pageX - popwidth + 5;
			
			if (offset <= 1) {
				offset = 1;
				// lets make the point follow the cursor
				// if we're here.
				var halfway = (offset + popwidth)/2+27;
				if (e.pageX < halfway) {
					$(point).css({"background":"url(images/team/quote-bottom-left.gif)", "left":e.pageX});
				} else {
					$(point).css({"background":"url(images/team/quote-bottom.gif)", "left":e.pageX-27});
				}
			}
			
			var x = offset - 50;
			var y = e.pageY - 400;
			$("#popup-"+identification).css({'top' : y, 'left' : x});
			
		});
		
	});
	
	$(".thumbnail-act").mouseout(function(){
		var identification = this.id.replace("thumb-", "");
		$("#popup-"+identification).hide();
	});

});



// vertical positioning in the viewport

(function($){
  $.fn.vCenter = function(options) {
    var pos = {
      sTop : function() {
        return window.pageYOffset || document.documentElement && document.documentElement.scrollTop ||	document.body.scrollTop;
      },
      wHeight : function() { 
        return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
      }
    };
    return this.each(function(index) {
      if (index == 0) {
        var $this = $(this);
        var elHeight = $this.height();
		    var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
        $this.css({
          position: 'absolute',
          marginTop: '0',
          top: elTop
        });


      }
    });
  };

})(jQuery);
