$.fn.fodelay = function(time, callback){
    jQuery.fx.step.fodelay = function(){};
    return this.animate({delay:1}, time, callback);
}

$.fn.flyouts = function(options) {
		
	options = $.extend({}, options || {});
	
	this.each(function() {
	
		var root = this, zIndex = 1000;
		var ie6 = ($.browser.msie && $.browser.version < 7);
		
		function getSubnav(ele) {
			if (ele.nodeName.toLowerCase() == 'li') {
				var subnav = $('> ul', ele);
				return subnav.length ? subnav[0] : null;
			} else {
				return ele;
			}
		}
		
		function hide() {
			var subnav = getSubnav(this);
			var iid;
			
			if (!subnav || !$(subnav).attr('foposition')) return;
			
			$.data(subnav, 'cancelHide', false);
			
			if (!ie6) {
				
				$(this).removeClass('hover');
				$('img:first', this).triggerHandler('mouseleave');
				$('a:first', this).removeClass('hover');
				
				$(subnav).css({display:'none'});
			} else {
				
				if (!$.data(subnav, 'cancelHide')) {
					$(this).fodelay(500, function(){
						$(this).removeClass('hover');
						$('img:first', this).triggerHandler('mouseleave');
						$('a:first', this).removeClass('hover');
						$(subnav).css({display:'none'});
					});
				}
				
			}
			
		}
		
		function show() {
			var subnav = getSubnav(this);
			
			if (!subnav || !$(subnav).attr('foposition')) return;
			
			var px = $(subnav).parent().position().left;
			var py = $(subnav).parent().position().top;
			var ox = $(subnav).attr('foposition').match(/-{0,1}[0-9]{1,}\,-{0,1}[0-9]{1,}/) ? Math.round($(subnav).attr('foposition').split(',')[0]) : 0;
			var oy = $(subnav).attr('foposition').match(/-{0,1}[0-9]{1,}\,-{0,1}[0-9]{1,}/) ? Math.round($(subnav).attr('foposition').split(',')[1]) : 0;

			$(this).addClass('hover');
			$('img:first', this).triggerHandler('mouseenter');
			$('a:first', this).addClass('hover');
			
			$.data(subnav, 'cancelHide', true);
			
			$(subnav).css({
				zIndex:zIndex++,
				display:'block',
				left:(px+ox)+'px',
				top:(py+oy)+'px'
			});
		
		}
		
		$('ul, li', this).bind('mouseover', show);
		$('ul, li', this).bind('mouseleave', hide);
	
	});

};