jQuery(function() {
	jQuery('#nav > li').each (function() {
		this._overCount =  0;
		this._timer = null;
	}).mouseover(function(evt) {
		this._overCount = (this._overCount + 1);
		clearTimeout(this._timer);
		this._timer = null;
		if (!this._showing) {
			hideOtherMenus(this.id);
			var jThis = jQuery(this).children('ul');
			jQuery(this).addClass('sfhover');
			var offset = jQuery(this).hasClass('lastMenu') ? -25 : 0;
			jQuery('#menuBack').width(jThis.width()).height(jThis.height()+1).css({'top': jThis.position()['top'], 'left': jThis.position()['left'] + offset, 'display': 'block'});
			this._showing = true;
		}
	}).mouseout(function(evt) {
		this._overCount = this._overCount - 1;
		if (this._timer == null) {
			this._timer = setTimeout("hideMenu('" + this.id + "')", 250);
		}
	});
})
function hideMenu(id) {
	var node = jQuery('#' + id)[0];
	if (node._showing && node._overCount <= 0) {
		if (node._timer != null) {
			clearTimeout(node._timer);
			node._timer = null;
		}
		jQuery('#menuBack').css('display', 'none');
		jQuery('#' + id).removeClass('sfhover');
		node._showing = false;
		if (node._overCount < 0) {
			node._overCount = 0;
		}
	}
}
function hideOtherMenus(id) {
	jQuery('#nav > li').each(function() {
		if (this.id != id && this._showing) {
			hideMenu(this.id);
		}
	})
}