// jQuery plugin - Dolphin Top Menu
(function($){
	$.fn.dolTopMenu = function() {
		return this.each( function(){
			
			var show = function() {
            if($('div.active')[0] == this || $active[0] == this)
                    return true;

				var o = $(this).attr('showsub');
				$( o ? o : this ).attr( 'hover', 'true' ).show();
				
				//alert( this );
				if( typeof $activeSub != 'undefined' )
					$activeSub.hide();
			};
			
			var hide = function() {
                if($('div.active')[0] == this || $active[0] == this)
                    return true;



				var o = $(this).attr('showsub');
				var $o = $( o ? o : this );
				
				$o.attr( 'hover', 'false' );

				setTimeout( function() {
					if( $o.attr( 'hover' ) != 'true' ) {
						$o.hide();
						if( typeof $activeSub != 'undefined' && $inactiveSubs.filter('[hover=true]').length == 0 )
							$activeSub.show();
					}
				}, 100 );
			};
			
			var $inactive  = $( 'a', this );
			var $active    = $( 'a.active',this);
			var $activeDiv    = $( 'div.active');

			var $activeSub;
			var $inactiveSubs;

			if( $active.length && $active.attr('showsub') )
				$activeSub = $( $active.attr('showsub') );



			$inactive.hover( show, hide ).each( function() {
				if( !$inactiveSubs )
					$inactiveSubs = $( $(this).attr('showsub') );
				else
					$inactiveSubs = $inactiveSubs.add( $(this).attr('showsub') );
			} );

			$inactiveSubs.hover( show, hide ).each(function(){

            });
		} );
	};
})(jQuery);