/**
*	Handles the form submitting stuff
*
**/

(function($)
{
	$(document).ready( function($)
	{
		$.fn.email = function()
		{
			return this.each(function()
			{
				var form = $(this);
				var email = $('#hdr_email');
				
				email.val('your email').css({color:'#666666'}).focus(function()
				{
					if (email.val() == 'your email' || email.val() == 'thank you') email.val(''); 
					email.css({color:'#000000'});
				}).blur(function()
				{
					if (email.val() == '') 
					{
						email.val('your email'); 
						email.css({color:'#666666'});
					}
				});
				
				form.submit(function()
				{
					if (!validate(email.val()) )
					{
						email.css({'background-color':'#FF0000'});
						window.setTimeout(function(){ jQuery('#hdr_email').css({'background-color':'#FFFFFF'}) }, 1000);
						return false;
					}
					
					form.slideUp('fast', function()
					{
						$.post(form.attr('action'), form.serialize());
						email.val('thank you');	
						email.css({color:'#666666'});
					}).delay(1000).slideDown('fast');
					
					return false;
				});
				
				
			});
		};
		
		$('#emailsignup').email();
	});
})(jQuery);

function validate(s)
{
	try
	{
		var regex = new RegExp('^(("[\\w-\\s]+")|([\\w-]+(?:\\.[\\w-]+)*)|("[\\w-\\s]+")([\\w-]+(?:\\.[\\w-]+)*))(@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(?:\\.[a-z]{2})?)$)|(@\\[?((25[0-5]\\.|2[0-4][0-9]\\.|1[0-9]{2}\\.|[0-9]{1,2}\\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\]?$)','i');
		return regex.test(s);
	}
	catch(e){ return false;}
}


/**
* HoverIntent.min.js
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}
if(p==this){return false;}
var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}
if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

