/*
	This file is intended as a storage location for common site functions,
	features, possibly setting, and overall basic site functionality. Please 
	make an effort to keep it clean of rift-raft, development code, or code 
	that does not pertain to the base functionality of the site.
	
	Use jQuery when possible. It's easy, simple, cross-browser, and efficient!
	
	Remember to comment!
*/


/**
* 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);








// Run when DOM is ready for manipulation, better than onload
$(document).ready(function() {

	//	Initiate menus
	// 	Creates the popup effect for main menu hovering in browsers that suck (eg IE6)
	//	Good browsers work without this code (just plain CSS), but its here for older browsers
	// Hide all submenus
	$('div#mainmenu ul li ul').hide();
	
	// Show submenu on mouseover and hide on mouseout
	$('div#mainmenu ul li').hoverIntent({sensitivity: 7, over: function(e) {	
		if ($(this).children('ul').length > 0) {
			// Set submenu min-width 20% larger than parent menu's width -- looks better
			$(this).children('ul').css('min-width', this.offsetWidth * 1.2).slideDown(200);
		}
	},
	out: function() {
		// Hide all submenus
		$('ul', this).fadeOut(200);
	}});
		
		
		
	//	Unobstructive method for new window popup
	//	Just give a <a> tag the class 'new-window' and jquery will do the rest
	//	Should work for any elements dynamically added
	//	Example: <a href="http://www.google.com" rel="new-window">
	$('a[rel*="new-window"]').live('click', function() {
		window.open(this.href,'_blank') 
		return false;
	});
	
	//	Unobstructive method for recaptcha email cloaker
	$('a[rel*="recaptcha-email"]').live('click', function() {
		window.open(this.href,'_blank','width=500,height=300') 
		return false;
	});
	
});