//Create a zcr object so everything is properly namespaced
var zcr = {
		//create an ajax object in zcr just for good measure
		ajax: {
			// create the options object
			options : function(form,url) {
				return {
					target: form.parent(),
					url: url,
					success: function(msg) { 
						// grab the current form id so we can grab the new form object return in the Ajax response 
						var newForm = $("#" + form.attr("id"));
						//Create an options object for the new form
						var options = zcr.ajax.options(newForm,url);
						//wire up the new form
						newForm.ajaxForm(options);
					},
					beforeSubmit: function() {
						form.find('input.zemSubmit').toggle()
						form.find('input.zemSubmit').parent().append('<img class="loadingImg" src="http://sanroccobenabbio.com/img/ajax-load.gif" alt="waiting" />');
					} // end beforeSubmit
				};
			} //end options
		} //end ajax
};



// prepare the forms when the DOM is ready
$(document).ready(function() {
	$('form.zemContactForm').each(function() {
		var options = zcr.ajax.options($(this), 'http://sanroccobenabbio.com/en/ajax/');
		$(this).ajaxForm(options);
	}); //end each
}); //end document.ready

