jQuery(function($) {

    $('#contactForm').ajaxForm( {
	target: '#contentPanel',
	beforeSubmit: function(fData, jq, o) {
	    var form = jq[0];
	    if (!form.author.value) {
		alert("Please enter a Name.");
		return false;
	    } else if (!form.email.value) {
		alert("Please enter an Email.");
		return false;
	    } else if (!form.text.value) {
		alert("Please enter a Message.");
		return false;
	    }
	    return true;
	}
    });
    
    $('a.lightbox').lightBox();

    $("label[for=author],label[for=email],label[for=text]")
      .append(" <span class=required>*</span>");

    // Check the other option by default
    $('#heard-other').attr('checked', 'checked');
    // input is disabled by default 
    var rb = $('#referBy');
    rb.attr("disabled", true);
    $('#heardOptions :radio').change(function() {
	rb.attr("disabled", true);
	if ($(':radio:checked').val() == "refer")
	    rb.removeAttr("disabled");
    });
	
    $('ul.gallery').galleria({
	history   : false, // deactivates the history object for bookmarking, back-button etc.
	clickNext : true, // helper for making the image clickable. Let's not have that in this example.
	insert    : "#mainImg",

	onImage   : function() { $('.nav').css('visibility','visible'); } // shows the nav when the image is showing
    });
    $('.nav').css('visibility','hidden'); // hides the nav initially
    window.setTimeout(fn2, 200);

    function fn2 () {
	$("ul.gallery li:first-child").find(".thumb").click();
    }

});

