$(function() {
	// Main navigation.
	var nav = new Jmenu('nav');
	$('#nav ul').css({ 'position': 'absolute', 'z-index': 99, 'display': 'none' });
});


/*
    JMenu by Roderic Henry, TGP Associates
    A simple fly-down menu that uses jQuery.
    3/9/2009
*/

function Jmenu(id, config){
	this.selector = '#' + id + ' > li';
	this.menuItem = null;
	this.timer = null;
	var opts = { delay:1000 };
	this.opts = $.extend(opts, config);
	this.init();
}
Jmenu.prototype.init = function(){
	var self = this;
	$(this.selector).bind('mouseover', function(e){ self.show.call(self, $(this).find('ul').eq(0), e); });
	$(this.selector).bind('mouseout', function(e){ self.doHide.call(self, e); });
	$(document).bind('click', function(){ self.hide(); });
}
Jmenu.prototype.hide = function(){
	if(this.timer){
		clearTimeout(this.timer);
		this.timer = null;
	}
	if(this.menuItem) this.menuItem.css('display', 'none');
}
Jmenu.prototype.doHide = function(e){
	var self = this;
	this.timer = setTimeout(function(){ self.hide(); }, this.opts.delay);
}
Jmenu.prototype.show = function(mi, e){
	this.hide();
	this.menuItem = mi;
	this.menuItem.css('display', 'block');
}
/****************    END OF JMenu */

