$(document).ready(function(){
	
	// clear/restore effect for inputs
  // from comments on http://www.chapterthree.com/blog/josh_koenig/howto_automatically_clearrestore_form_defaults_wjquery

  $("input:text").focus(function(){
		var element = $(this);
		if(element.hasClass('.password1')) {
			
			$("#password1").css("display","none");
			$("#realPassword").css("display","block").focus();
			
		}
		else {
			element.attr("rel",element.val());
			element.val('');
		}

	});
	
	$("input:text").blur(function(){
		var element = $(this);
		if (element.val() == '') {
			element.val(element.attr("rel"));
		}
	});
	
	$("#realPassword").blur(function(){
		var element = $(this);
		if (element.val() == '') {
			$("#realPassword").css("display","none").val("");
			$("#password1").css("display","block");
		}
	});	
	
	$("form").submit(function(){
			
			setTimeout(function(){ 
	
				$("input:text").each(function(){
					var thisInput = $(this);
					thisInput.val(thisInput.attr("rel"));	
				});
				
				if ($("#realPassword").length > 0) {
					$("#realPassword").css("display","none").val("");
					$("#password1").css("display","block");
				}
								
		  }, 2000 ); 

	});

});


// use the title attribute to create the title for the modal
// can swap for some other method in live site 
	
$(function() { // function for the dynamic overlay + click function for header - this overlay pulls the html page in

	// Grab the title from the clicked link
	
	$("a[rel]").click(function() {
	
		var thisTitle = $(this).attr('title');
		$("div#overlay h1").html(thisTitle);
	
	});

	// if the function argument is given to overlay,
	// it is assumed to be the onBeforeLoad event listener
	
	$("a[rel]").overlay({

		expose: { 
      color: '#fff', 
      loadSpeed: 200, 
      opacity: 0.33 
    },
		effect: 'apple',
		opacity: 1,
		closeOnClick: true,

		onBeforeLoad: function() {

			// grab wrapper element inside content
			var wrap = this.getContent().find(".contentWrap");

			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"));
			
		}

	});
	
});
