jQuery.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=window;
        for (j=0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }
    return o;
};

$(document).ready(function() {
	$('#contact_submit').click(function(e) {
        e.preventDefault();

        $('#contact_error').fadeOut('fast', function() {
            $('#contact_error').html('');

            if ($('#cu_name').val() == '') {
                $('#contact_error').html('Please give your name. A first name is enough.');
                $('#cu_name').focus();
            }
            else if ($('#cu_email').val() == '') {
                $('#contact_error').html('You must provide your email address');
                $('#cu_email').focus();
            }
            else if ($('#cu_message').val() == '') {
                $('#contact_error').html('Your message is blank');
                $('#cu_message').focus();
            }

            if ($('#contact_error').html() != '') {
                $('#contact_error').fadeIn('fast')
            }
            else {
                $('#contact_form').submit();
            }
        })
    });

    $('.contact_input').focus(function(e) {
        $('#cu_message').height('220px');
    });

    // Display and (for non-errors) hide flash messages
    $('.flash_message').slideDown('slow').delay(4000).slideUp('slow');
    $('.flash_message_error').slideDown('slow');
});

