var HContact = {
	
	solution : undefined,
	refreshEle : undefined,
	questionEle : undefined,
	formEle : undefined,
	formAction : undefined,
	
	init : function(params) {
		HContact.formAction = params.formAction ? params.formAction : '/hcontact.php';
		HContact.formEle = params.formEle ? jQuery('#'+params.formEle) : jQuery('#contact_form');
		HContact.refreshEle = params.refreshEle ? jQuery('#'+params.refreshEle) : jQuery('#cptaRefresh');
		HContact.questionEle = params.questionEle ? jQuery('#'+params.questionEle) : jQuery('#cptaTxt');
		HContact.captchaInp = params.captchaInp ? jQuery('#'+params.captchaInp) : jQuery('#cpta');
		HContact.refresh();
		
		jQuery(HContact.refreshEle).live('click', HContact.refresh);
		jQuery('#form_submit').live('click', HContact.submit);
	},
	
	refresh : function() {
		var n1 = Math.ceil(Math.random()*10);
		var n2 = Math.ceil(Math.random()*10);
		var opNum = Math.floor(Math.random()*3);
		var mAlpha = ['plus','minus','times'];
		var mOp = ['+','-','*'];
		var opAlpha = mAlpha[opNum];
		var operator = mOp[opNum];
		HContact.solution = eval(n1+operator+n2);
		//HContact.questionEle.html('What is '+n1+' '+opAlpha+' '+n2+'?');
		HContact.questionEle.firstChild.nodeValue = 'What is '+n1+' '+opAlpha+' '+n2+'?';
	},
	
	submit : function(e) {
		alert('dang');
		// VALIDATION
		if (jQuery(HContact.captchaInp).val() != HContact.solution)
		{
			alert('Your answer to the security question was incorrect');
			HContact.refresh();
			return false;
		}
		var data = {};
		jQuery(HContact.formEle).children('input[type="text"],textarea').each(function(i) {
			eval('data.'+this.getAttribute('id')+' = '+this.value);
		});
		alert(data);
		return false;
		jQuery.post(HContact.formAction, {
			name : jQuery('#name_inp').val(),
			email : jQuery('#email_inp').val(),
			phone : jQuery('#phone_inp').val(),
			message : jQuery('#message_inp').text()
		}, function(response) {
			alert('goo');
		});
		return true;
	}
	
};




/*jQuery(document).ready(function(){
		var arr = createQuestion();
		var solution = arr.sol;
		jQuery('#cptaTxt').html(arr.disp);
		jQuery('#cptaRefresh').click(function() {
			arr = createQuestion();
			solution = arr.sol;
			jQuery('#cptaTxt').html(arr.disp);
		});
	});
	function contactSubmit(form) {
		
		if (jQuery('#cpta').val() != solution)
		{
			alert('Your answer to the security question was incorrect');
			createQuestion();
			return false;
		}
		
		jQuery.post('/contact_popup.php', {
			name : jQuery('#name_inp').val(),
			email : jQuery('#email_inp').val(),
			phone : jQuery('#phone_inp').val(),
			message : jQuery('#message_inp').text()
		}, function(response) {
			alert('goo');
		});
	}
	function createQuestion() {
		var n1 = Math.ceil(Math.random()*10);
		var n2 = Math.ceil(Math.random()*10);
		var opNum = Math.floor(Math.random()*3);
		var mAlpha = ['plus','minus','times'];
		var mOp = ['+','-','*'];
		var opAlpha = mAlpha[opNum];
		var operator = mOp[opNum];
		//
		var disp = 'What is '+n1+' '+opAlpha+' '+n2+'?';
		return {sol : eval(n1+operator+n2), disp : disp};
	}*/
