$(function() {
    $("#contact-form").click(function() {
        $(".contact").slideToggle();
        return false;
    });

    // clear & store default text
    $("input:text").focus(function() {     

        // cache jquery obj
        var $this = $(this);     

        // clear only defaults
        if ($this.val() == 'Your Name' || $this.val() == 'Your Email Address') {
            
            // store default text in datastore & clear the box
            $this.data('default', $this.val())
                .val('');   
        }
    });   

    // restore default text if blank
    $("input:text").blur(function() {     

        var $this = $(this);     

        if ($this.val() == '') {
            $this.val($this.data('default'));
        }
    }); 

    // next two binds mirror the last two for the textarea, this can be refactored w/ more thought
    $("textarea").focus(function() {     
        var $this = $(this);     

        if ($this.val() == 'Message') {
            $this.data('default', $this.val())
                .val('');   
        }
    });   

    $("textarea").blur(function() {     
        var $this = $(this);     
        if ($this.val() == '') {
            $this.val($this.data('default'));
        }
    }); 

    $("#commentForm").validate();
    var loader = $('<div id="loader"><img src="public/img/loading.gif" alt="loading..." /></div>')
	.css({position: "relative", top: "1em", left: "25em"})
	.appendTo("body")
	.hide();
    $().ajaxStart(function() {
	loader.show();
    }).ajaxStop(function() {
	loader.hide();
    }).ajaxError(function(a, b, e) {
	throw e;
    });
		
    $("#contactForm").validate({
	submitHandler: function(form) {
	    $(form).ajaxSubmit({
		target: "#result"
	    });
	}
    });
		
});
