/**
 * Funktion: suckerfish
 * Erzeugt IE6 kompatible Suckerfish-Menüs
 * @params  void
 * @return  bool  erfolg
 */
 
(function($) { 
    $.fn.extend({  
        suckerfish: function(options) {
        
            var bypass          = false;
            var bypassTimeout   = null;
            var opened          = null;
            var hideTimeout     = null;
            var showTimeout     = null;
            
            var hide = function(el) {
            
                /* bei mouseout klasse sfHover entfernen */
                $(el).removeClass('sfHover sfHoverColor');
                
                /* nach 200 ms die sperre der anzeige-verzoegerung aufheben */
                bypassTimeout = setTimeout(function() { bypass = false; }, 200);
            }
        
            var show = function(el) {
                
                /* aktuell angezeigtes menu sofort verstecken */
                clearTimeout(hideTimeout);
                hide(opened);
                
                /* bei mouseover klasse sfHover hinzufuegen und menu merken */
                $(el).addClass('sfHover sfHoverColor');
                opened = el;
                
                /* anzeige-verzoegerung aktivieren */
                clearTimeout(bypassTimeout);
                bypass = true;
            }
            
            return this.each(function() { 
                $(this).find('li:has(ul)').each(function() {
                    $(this).hover(function() {
                        var el = this;
                        showTimeout = setTimeout(function() { show(el); }, bypass ? 0 : options.showDelay); 
                    }, function() {
                        var el = this;
                        clearTimeout(showTimeout);
                        hideTimeout = setTimeout(function() { hide(el); }, options.hideDelay);
                    });
                });
                
                $('#' + this.id + ' > ul > li').each(function() {
                    $(this).hover(function() {
                        $(this).addClass('sfHoverColor');
                    }, function() {
                        if($(this).find('ul').length == 0 || $(this).find('ul').css('left') == '-999px') {
                            $(this).removeClass('sfHoverColor');
                        }
                    });
                });
            });
        }
    }); 
})(jQuery);