Object.extend(Prototype,
        {
                scriptPath:
                        $$('script').find(
                                        function (s) {
                                                return (s.src && /prototype.*js$/i.test(s.src))
                                        }
                                ).src.replace(/prototype.*js$/i,''),
                includeJS: function (file) {
                        var elScript = Element.create('script',{
                                type:'text/javascript',
                                src:file
                        });
                        var myPromise = (function () {$$('head')[0].appendChild(this);}).bind(elScript);
                        Prototype.Promise(
                                '$$("head").length>=1',
                                (function () {
                                        $$('head')[0].appendChild(this);
                                }).bind(elScript)
                        );
                },
                includeCSS: function (file) {
                        var elLink = Element.create('link',{
                                type:'text/css',
                                rel:'stylesheet',
                                href:file
                        });
                        Prototype.Promise(
                                '$$("head").length>=1',
                                (function () {
                                        $$('head')[0].appendChild(this);
                                }).bind(elLink)
                        );
                },
                Promise: function (condition,action,interval) {
                        if (typeof interval=='undefined') interval=1;
                        //Promise to do this now, or whenever (condition) is met
                        if (eval(condition))
                                action();
                        else
                                new PeriodicalExecuter(
                                        function (pe) {
                                                Prototype.Promise.bind(pe,condition,action,interval)();
                                        },
                                        2
                                );
                        if (this.stop) this.stop();
                }
        }
);