/**
 * 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);



/**
 * Funktion: suckerfish
 * Erzeugt IE6 kompatible Suckerfish-Menüs speziell für das IHK-Menü
 * @params  void
 * @return  bool  erfolg
 */

(function($) { 
    $.fn.extend({  
        suckerfishIHK: function(options) {
        
            var bypass        = false;
            var bypassTimeout = null;
            var hideLocked    = false;
            var hideTimeout   = null;
            var opened        = null; 
            var showLocked    = false;
            var showTimeout   = null;
            
            /* Funktion zum Ausblenden der Navigation */
            var hide = function() {
            
                /* den geklickten punkt zuruecksetzen */
                if(opened != null) {
                    $(opened).removeClass('clicked');
                    $(opened).removeClass(opened.activeClass);
                    opened = null;
                }
                
                /* 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();
            
                /* das item ist das elternelement von dem mit dem event */
                var el = el.parentNode;
                
                /* css-klassennamen fuer aktiv ermitteln */
                var stdClass = $(el).attr('class');
                
                /* ebenen-klasse und anfangs-bzw. end-klassen entfernen */
                stdClass = stdClass.replace(/\s*lvl1\s*/, '');
                if($(el).hasClass('first') || $(el).hasClass('last')) {
                    stdClass = stdClass.replace(/\s*(first|last)\s*/, '');
                }
                
                el.activeClass = stdClass + '-active';
                
                /* item als aktiv markieren und merken */
                $(el).addClass('clicked');
                $(el).addClass(el.activeClass);
                opened = el;
                
                clearTimeout(hideTimeout);
                hideLocked = true;
        		
            		/* anzeige-verzoegerung aktivieren */
                clearTimeout(bypassTimeout);
                bypass = true;
            }
            
            return this.each(function() {
                $(this).find('ul > li:has(ul ul) > a').hover(function(e) {
                    var el = this;
                    clearTimeout(hideTimeout);
                    
                    showTimeout = setTimeout(function() { show(el); }, bypass ? 0 : options.showDelay);
                }, function() {
                    var el = this;
                    clearTimeout(showTimeout);
                    
                    if(hideLocked == false) {
                      hideTimeout = setTimeout(function() { hide(el); }, options.hideDelay);
                    }
                });
                
                $(this).find('ul > li:has(ul ul)').hover(function() {
		            clearTimeout(hideTimeout);
                    hideLocked = true;
                }, function() {
                    hideLocked = false;
                    hideTimeout = setTimeout(function() { hide(); }, options.hideDelay);
                });
            });
        }
    });
})(jQuery);
