/**
 * BabelsbergScript is a way to describe constraints in a convenient syntax.
 * @name BabelsbergScript
 * @tutorial babelsbergscript-tutorial
 */
(function() {
    var Http = {
        request: function(method, url, callback) {
            var xhr = new (window.ActiveXObject || XMLHttpRequest)(
                        'Microsoft.XMLHTTP');
            xhr.open(method.toUpperCase(), url, true);
            if ('overrideMimeType' in xhr)
                xhr.overrideMimeType('text/plain');
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4) {
                    var status = xhr.status;
                    if (status === 0 || status === 200) {
                        callback.call(xhr, xhr.responseText);
                    } else {
                        throw new Error(
                            'Could not load ' + url + ' (Error ' +
                                status + ')'
                        );
                    }
                }
            };
            return xhr.send(null);
        }
    };

    /**
     * Transforms the given {@link BabelsbergScript} source code as regular JavaScript.
     * @function Babelsberg.compile
     * @public
     * @param {string} code The source code that should be transformed.
     * @return {string} A transformed version of the given source code.
     */
    Babelsberg.compile = function(code) {
        var t = new BabelsbergSrcTransform();
        return t.transform(code);
    };

    /**
     * Transforms and executes the given {@link BabelsbergScript} source code.
     * @function Babelsberg.execute
     * @public
     * @param {string} code The source code that should be executed.
     * @param {Object} scope The scope in which the given code is executed.
     */
    Babelsberg.execute = function(code, scope) {
        var params = [],
            args = [],
            func;
        code = Babelsberg.compile(code);
        var firefox = window.InstallTrigger;
        if (firefox || window.chrome) {
            var script = document.createElement('script'),
                head = document.head;
            if (firefox)
                code = '\n' + code;
            script.appendChild(document.createTextNode(
                'bbb._execute = function(' + params + ') {' + code + '\n}'
            ));
            head.appendChild(script);
            func = bbb._execute;
            delete bbb._execute;
            head.removeChild(script);
        } else {
            func = Function(params, code);
        }
        var res = func.apply(scope, args) || {};
    };

    function load() {
        function checkScript(script) {
            if (/^text\/(?:x-|)babelsbergscript$/.test(script.type) &&
                    !script.getAttribute('babelsberg-ignore')) {
                var src = script.src;
                if (src) {
                    Http.request('get', src, function(code) {
                        Babelsberg.execute(code);
                    });
                } else {
                    Babelsberg.execute(script.innerHTML);
                }
                script.setAttribute('babelsberg-ignore', true);
            }
        };

        var scripts = document.getElementsByTagName('script');
        for (var i = 0; i < scripts.length; i++)
            checkScript(scripts[i]);
    }

    if (document.readyState === 'complete') {
        setTimeout(load);
    } else {
        contentLoaded(window, load);
    }
})();

@@ -2618,24 +2618,664 @@
 on load() %7B%0A
+        var numScripts = 0,%0A            fired = false;%0A%0A        function checkForFinish() %7B%0A            if (numScripts === 0 && !fired) %7B%0A                var event = new CustomEvent(%0A                    %22babelsbergready%22,%0A                    %7B%0A                        detail: %7B%0A                            message: %22Babelsberg Scripts loaded%22,%0A                            time: new Date(),%0A                        %7D,%0A                        bubbles: true,%0A                        cancelable: true%0A                    %7D%0A                );%0A                fired = true;%0A                document.dispatchEvent(event);%0A            %7D%0A        %7D%0A%0A
         func
@@ -3297,24 +3297,24 @@
 t(script) %7B%0A
-
             
@@ -3498,24 +3498,61 @@
  if (src) %7B%0A
+                    numScripts += 1;%0A
             
@@ -3643,32 +3643,115 @@
 .execute(code);%0A
+                        numScripts -= 1;%0A                        checkForFinish();%0A
                 
@@ -4061,16 +4061,16 @@
 h; i++)%0A
-
         
@@ -4098,16 +4098,42 @@
 ts%5Bi%5D);%0A
+        checkForFinish();%0A
     %7D%0A%0A 

add an event to listen to when all babelsbergscripts were compiled