triggerArray = [], rollovers = [];

$( document ).ready ( function () {
    readyRollovers();
} ) ;

initRollovers = function ( elements ) {
    for ( var i = 0 ; i < elements.length ; i++ ) {
        if ( elements[ i ] != '' ){
            element = $( "#" + elements[ i ]);
            debugalert($(element));
            $( element ).addClass( 'active' ).find("> a").addClass( 'active' ).end().parents( 'li' ).each(function(){
                $( this ).addClass( 'open' ).find("> a").addClass( 'open' );
            });
        }
    }
};

readyRollovers = function(){
    imagesExp= /((\.jpg)|(\.png)|(\.gif))/;
    
    //remove IE background flickering
    try {
        document.execCommand('BackgroundImageCache', false, true);
    } catch(e) {}
    
    for ( var i = 0 ; i < triggerArray.length ; i++ ) {
        eval ( triggerArray [ i ] ) ;
    }
    
    // Alle Bilder mit der Klasse active sollen mit dem _f2 versehen werden.
    $("img.active").each( function (){
         this.src = this.src.replace(imagesExp,'_f2$1');
    });
    
    // Alle Bilder mit Klasse "rollover" aber nicht "active" sollen vorgeladen werden und einen hover bekommen.
    $("img.rollover:not(.active)").each( function (){
        $.preloadImages(this.src.replace(imagesExp,'_f2$1'));
    })
    .hover(
        function(){
            this.src = this.src.replace(imagesExp,'_f2$1');
        },
        function(){
            this.src = this.src.replace(/_f2/,'');
        }
    );
};

resetRollovers = function(){
    $('.active').each(function(){$(this).removeClass('active')})
    $('.open').each(function(){$(this).removeClass('open')})
};

jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

collectTriggers = function ( objects ) {
    triggerArray.push ( objects ) ;
} ;

/**
 * display custom error messages in the firebug extension (http://www.getfirebug.com)
 * @param string    outputtext
 * @return void
 */
function debugalert(outputtext){
    if (window.console != null) window.console.log(outputtext);
};
