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

	// assign input type to class
	assignClasses : function() {
		$.getScript("lib/ext/jquery.attrToClass.js", function(){		
			$("input").attrToClass("type");
		});			
	},
	
	// hightlight focus fields
	fieldHilite : function() {	
		$("#signup fieldset .single-field input").focus(function() {
			$(this).parent().addClass("curFocus")

			//$(this).parent().animate({marginLeft: "-40px"}, "slow");
				$(this).animate({width: "220px"}, "fast");

		});
		$("#signup fieldset .single-field input").blur(function() {
			$(this).parent().removeClass("curFocus")
		//	$(this).parent().animate({marginLeft: "0"}, "fast");
			$(this).animate({width: "200px"}, "fast");

		});		
		$("#signup fieldset textarea").focus(function() {
			$(this).parent().addClass("curFocus")

			//$(this).parent().animate({marginLeft: "-40px"}, "slow");
				$(this).animate({width: "220px"}, "fast");

		});
		$("#signup fieldset textarea").blur(function() {
			$(this).parent().removeClass("curFocus")
		//	$(this).parent().animate({marginLeft: "0"}, "fast");
			$(this).animate({width: "200px"}, "fast");

		});		
	},
	
	// Check all checkboxes
	checkBoxes : function() {
		$('a.all_link').click( function() {
			$('input:checkbox').each( function() {
			this.checked = !this.checked;
			$('.all_link').toggle();
			});
		return false;
		});			
	},
	
	// secure form (non-captcha) - SPAM Blocker
	secureForm : function() {	
		$.get("token.php",function(txt){
			$(".secure").append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
	},	
	
	// validate the form and submit it via AJAX
	submitForm : function() {
		$.getScript("lib/ext/jquery.validate.js", function(){		
			var validator = $("#signup").validate({
				submitHandler: function(form) {
					jQuery(form).ajaxSubmit({
						target: "#result"
					});
				}
			});
		});			
	}
	
}

$(document).ready(function(){
	$('head').append('<link rel="stylesheet" href="assets/css/forms.css" type="text/css" />');				   
	FormEngine.fieldHilite();
	FormEngine.assignClasses();
	FormEngine.loadFormjs();		
	FormEngine.secureForm();
	FormEngine.submitForm();
	$("input[type='text']:first", document.forms[1]).focus();
});
