triggerArray = [], rollovers = [];

$( document ).ready ( function () {
    readyRollovers();
} ) ;

initRollovers = function ( elements ) {
    for ( var i = 0 ; i < elements.length ; i++ ) {
        if ( elements[ i ] != '' ){
            element = $( "#" + elements[ i ].toLowerCase());
            $( element ).addClass( 'active' ).find("> a").addClass( 'active' ).find("> img").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 || !console.firebug)
    {
        var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
        "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

        window.console = {};
        for (var i = 0; i < names.length; ++i)
            window.console[names[i]] = function() {}
            return;
    }
    else window.console.log(outputtext);
//     if (debug && debug != "false" && typeof debug!== 'function') alert(outputtext);
};
