$(document).ready(function() {
    if($("div#cmsbody").length == 0) {
        $("body.homepage div.onecolumn img").css("display", "none");
        $("body.homepage div.onecolumn").cycle(/*{random: 1}*/);
    }

    $("body.full div.thumbnail_box:nth-child(3n+1)").css("margin-right", "0");
    $("body.homepage div.thumbnail_box:nth-child(3n)").css("margin-right", "0");


    var formOptions = {
        target: "#contact_form_warning",
        beforeSubmit: validate,
        clearForm: true,
        success: function() {
            $("#contact_submit").css("visibility", "hidden");
        }
    };

    $('#contact_form').ajaxForm(formOptions);





// TEMP
$("body.full div.thumbnail_box a img").each(function() {
    $(this).prependTo($(this).parents("div.thumbnail_box"));
});
$("body.full div.thumbnail_box a").css("display", "none");




    var curHeight = 0;
    var maxHeight = 0;
    $("div.thumbnail_box").each(function() {
        curHeight = $(this).height();
        if(curHeight > maxHeight) {
            maxHeight = curHeight;
        }
    });
    $("div.thumbnail_box").css("height", maxHeight + "px");

});


function validate(formData, jqForm, options) {
    var no_errors = true;
    if(!$("#name").val()) {
        no_errors = false;
        $("#contact_form_warning").text("Please enter your name.");
    }
    else if(!$("#email").val()) {
        no_errors = false;
        $("#contact_form_warning").text("Please enter your email address.");
    }
    else
    {
        var emailPattern = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
        if(!$("#email").val().match(emailPattern))
        {
            no_errors = false;
            $("#contact_form_warning").text("A valid email address is required.");
        }
    }

    return no_errors;
}
