
function sb_auto_popup(sAutoPopUpLinkSelector, callbackWhenOpened) {

    // kl. Debug.func
    var debug =  function(val) {
        typeof(console) != 'undefined' ?
        console.info(val) : null;
    }


    // Anzeigeverzoegerung des Popups
    var timeout = 3000; //2 sec

    // Links fuer Auto-Popups
    var popupLinks = $(sAutoPopUpLinkSelector);

    // Ueberprueft, ob gerade ein Popup-Fenster geoeffnet ist
    var popupOpened = function() {
        return $('#fancy_outer').css("display") == "block";
    }

    // checkt, ob das popupfenster angezeigt werden soll
    var showAutoPopup = function() {

        var bShow = false;

        // nicht im linktool ausfuehren
        bShow = window.name != 'minibrowseriframe';

        // nicht in der printansicht ausfuehren
        bShow = bShow & (window.location.search.search(/print_style=yes/)==-1);

        return bShow;
    }


    // func fuers aufpoppen
    var displayPopup = function(jLink) {
        if(!popupOpened()) {

            // Fancybox oeffnen
            jLink.click();

            // optionale Callback
            if(typeof(callbackWhenOpened) == 'function') {
                callbackWhenOpened();
            }

        }else {
            // bei bereits geoeffnteter Fancybox,
            // wird setTimeOut einfach nochmals gestartet
            // (wenn eine Seite mehrere AutoPopups haben sollte)
            setCountDown(jLink);
        }
    }


    // Warteschleife fuers Popup
    var setCountDown = function (jLink) {
        window.setTimeout(function() {
            displayPopup(jLink);
        },timeout);
    }



    // run
    if(popupLinks.length >0 ) {

        popupLinks.each(function() {

            if(showAutoPopup()) {
                setCountDown($(this));
            }
        });
    }
}


/*
// so starten:
$(function() {
  sb_auto_popup('<sAutoPopUpLinkSelector>',function(){ alert('ich bin eine function oder false'); return false;});
});
*/
