var FormEngine = {
	
	loadFormjs : function() {
		$.getScript("wp-content/themes/nutrapay/lib/ext/jquery.form.js");					
		$.getScript("wp-content/themes/nutrapay/lib/ext/jquery.metadata.js");	
	},

	// assign input type to class
	assignClasses : function() {
		$.getScript("wp-content/themes/nutrapay/lib/ext/jquery.attrToClass.js", function(){		
			$("input").attrToClass("type");
		});			
	},
	
	// hightlight focus fields
	fieldHilite : function() {	
		$("form fieldset input.text").focus(function() {
			$(this).parent().addClass("curFocus")

			//$(this).parent().animate({marginLeft: "-40px"}, "slow");
				$(this).animate({width: "200px"}, "fast");
	
			
		});
		$("form fieldset input.text").blur(function() {
			$(this).parent().removeClass("curFocus")
		//	$(this).parent().animate({marginLeft: "0"}, "fast");
			$(this).animate({width: "150px"}, "fast");

		});		

	},
	
	// Check all checkboxes
	checkBoxes : function() {
		$('a.all_link').click( function() {
			$('input:checkbox').each( function() {
			this.checked = !this.checked;
			$('.all_link').toggle();
			});
		return false;
		});			
	},
	
	// validate the form and submit it via AJAX
	validateForm : function() {
		$.getScript("wp-content/themes/nutrapay/lib/ext/jquery.validate.js", function(){		
			var validator = $("#signup").validate();
		});			
	}
	
}

$(document).ready(function(){
	$('head').append('<link rel="stylesheet" href="wp-content/themes/nutrapay/assets/css/forms.css" type="text/css" />');				   
	FormEngine.assignClasses();
	FormEngine.loadFormjs();		
	FormEngine.validateForm();
	$("input[type='text']:first", document.forms[1]).focus();
});
// functions to run after page is fully loaded
$(window).load(function() {
	FormEngine.fieldHilite();	
});
