/*
 * SuperfishMod v1.0 
 * by Thor Asmund 2008
 *
 * Based on Superfish v1.4.1 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

//11:05 deru

(function($){
	$.superfishMod = {};
	$.superfishMod.o = [];
	$.superfishMod.op = {};
	$.superfishMod.defaults = {
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		oldJquery	: false, /* set to true if using jQuery version below 1.2 */
		disableHI	: false, /* set to true to disable hoverIntent usage */
	};
	$.fn.superfishMod = function(op){
		var 
      out = function() {},
      over = function(){
				var $$ = $(this), menu = getMenu($$);
				getOpts(menu,true);
				$$.showSuperfishModUl().siblings().hideSuperfishModUl();
			},
			getMenu = function($el){ return $el.parents('ul.superfishMod:first')[0]; },
			getOpts = function(el,menuFound){ el = menuFound ? el : getMenu(el); return $.superfishMod.op = $.superfishMod.o[el.serial]; }

		return this.each(function() {
			var s = this.serial = $.superfishMod.o.length;
			var o = $.extend({},$.superfishMod.defaults,op);
			$.superfishMod.o[s] = $.superfishMod.op = o;
			
      
			$('li:has(ul)',this)['hover'](over,out)
        .not('.first')
				.hideSuperfishModUl();
		
      /*
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
      */
		}).addClass('superfishMod');
	};
	
	$.fn.extend({
		hideSuperfishModUl : function(){
    	var o = $.superfishMod.op;
      this.removeClass('selected');
		  $('li',this).add(this).find('>ul').hide().css('visibility','hidden');
			return this;
		},
		showSuperfishModUl : function(){
    	var o = $.superfishMod.op;
		  var $ul = this.find('>ul:hidden').css('visibility','visible');
      this.addClass('selected');
			$ul.animate(o.animation,o.speed,function(){ });
			return this;
		}
	});
	
	$(window).unload(function(){
		$('ul.superfishMod').each(function(){
			$('li',this).unbind('mouseover','mouseout','mouseenter','mouseleave');
		});
	});
})(jQuery);