// 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');
				//if(o=='#subMenu_5') {
				//	$("#subMenu_5").css("z-index","2");
				//	$("#subMenu_96").css("z-index","1");
				//
				//	
				//} else {
				//	$("#subMenu_5").css("z-index","0");
				//	$("#subMenu_96").css("z-index","-1");
				//
				//	
				//}
				
				$( 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 );


				//var url=window.location.href;
				//
				//if (url.indexOf("www.travelujah.com/groups/entry")!=-1) {
				//	//if(o=='#subMenu_22') {
				//	if(o=='#subMenu_96') {
				//		
				//	} else {
				//		$o.attr( 'hover', 'false' );
				//	}
				//} else if (url.indexOf("www.travelujah.com/articles/entry")!=-1 || url.indexOf("www.travelujah.com/articles.php")!=-1) {
				//	if(o=='#subMenu_132') {
				//		
				//	} else {
				//		$o.attr( 'hover', 'false' );
				//	}
				//} else 
				//{
					$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);
