

jQuery(document).ready(function() {
	
	addEventHandlers();
	
	function GetInTouchFormHandler(e){
		
		e.preventDefault();
		jQuery("#GetInTouchForm").fadeIn("slow");
		jQuery("#blanket").show().fadeTo('slow',0.4);
		
	}
	
	jQuery("#GetInTouch a").click(GetInTouchFormHandler);
	
	var GetInTouchHTML = jQuery("#GetInTouchForm").html();
	
	function GetInTouchActionHandler(e){
		
		e.preventDefault();
		jQuery.post('ContactFormController',jQuery("#Form_ContactForm").serialize(),function(res){
			
			if(res.message){
				jQuery("#Form_ContactForm").hide();
				jQuery("#SentMessage").html(res.message).addClass("MailSent").css('color','#cccccc').show();
				
				jQuery("#SentMessage a").bind("click",{},removePopup);
			}
			
			if(res.error){
				jQuery("#SentMessage").html(res.error).css('color','red').show();
			}
				
			
		},"json");
	}
	
	function addEventHandlers() {
	
		jQuery("#Form_ContactForm_action_dummyAction").click(GetInTouchActionHandler,"json");
		jQuery("#closeBtn").click(removePopup);
		jQuery("#Form_ContactForm_email").focus(function(){
			if(jQuery(this).val()=='Email')
				jQuery(this).val('');
		
		});
		jQuery("#Form_ContactForm_message").focus(function(){
			if(jQuery(this).val()=='Message')
				jQuery(this).val('');
		
		});
	
	}
	
	function removePopup(e) {
		e.preventDefault();
		jQuery("#GetInTouchForm").hide().html(GetInTouchHTML);
		jQuery("#blanket").fadeOut('slow');
		addEventHandlers();
	}
	
	
});