/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(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);
(function($){var cache=[];$.preLoadImages=function(){var args_len=arguments.length;for (var i=args_len;i--;){var cacheImage=document.createElement('img');cacheImage.src=arguments[i];cache.push(cacheImage);}}})(jQuery);

$(document).ready(function()
{
	if ($.fn.prettyPopin)
	{
		$("a[rel^='register']").prettyPopin({
			modal: false, /* true/false */
			width: 500, /* true/false */
			height: false, /* true/false */
			opacity: 0.1, /* value from 0 to 1 */
			animationSpeed: 'fast', /* slow/medium/fast */
			followScroll: true, /* true/false */
			loader_path: '/images/prettyPopin/preloader-white.gif', /* path to your loading image */
			callback: function(){} /* callback called when closing the popin */
		});
	}
	
	$('a.contactus').click(function() {
	   $('html, body').animate({
		scrollTop: $("#contactus").offset().top
		}, 800);
	   return false;
	});
	 
	$('div.content img').each(function()
	{
		var _this = $(this);
		switch (_this.attr('align'))
		{
			case 'left':
				_this.addClass('imageLeft');
			break;
			
			case 'right':
				_this.addClass('imageRight');
			break;
			
			default:
				_this.addClass('image');
			break;
		}
	});
	
	$('ul#navigation a.sub').parent().hoverIntent({
		over: function() {$(this).addClass('hover');},
     	timeout: 500, 
     	out: function() {$(this).removeClass('hover');}
	});


	/*$('#navigation > li:not(.divider)').hover(function()
	{
		var _this = $(this);
		_this.addClass('hover');
		var _id = _this.attr('id').replace('nav','sub');
		$('#'+_id).show();
		
	},
	function()
	{
		var _this = $(this);
		_this.removeClass('hover');
		var _id = _this.attr('id').replace('nav','sub');
		$('#'+_id).hide();
	});*/
	
	$('.GenericFormFull').submit(function()
	{
		var _parameters = $(this).serialize();
		var _this = this;
		
		// Remove default values
		_parameters = _parameters.replace('tbxFirstName=First+Name&','');
		_parameters = _parameters.replace('tbxLastName=Last+Name&','');
		_parameters = _parameters.replace('tbxEmail=Email+Address&','');
		_parameters = _parameters.replace('tbxPhone=Phone+Number&','');
		_parameters = _parameters.replace('tbxComments=other+comments&','');
		_parameters += '&ajax=1';
		
		$.ajax({type: 'POST', url: _this.action, data: _parameters, dataType: 'json', success: function(_data) 
		{
			if (_data.ok == 1)
			{
				$(_this).hide();
				$('.error_content',$(_this).closest('div')).fadeOut(0).html('<div class="info-notice">'+_data.response+'</div>').fadeIn('slow');
			}
			else
			{
				$('.error_content',$(_this).closest('div')).fadeOut(0).html('<div class="info-error">'+_data.response+'</div>').fadeIn('slow');
			}
		}
		});
		return false;
	});	
});
