/**
 * This javascript class is used to load scripts.
 *
 * Example:
 * bbLoader.load('prototype', '/resources/js', 'core');
 *
 * $Revision: 354 $
 * $Date: 2008-02-07 11:57:29 +0100 (jeu., 07 févr. 2008) $
 * $Author: fhelly $
 *
 * Copyright 2007 Francois Helly <fhelly@bebop-design.net>
 *
 * See the enclosed file COPYING for license information (LGPL). If you did not
 * receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @version $Revision: 354 $
 * @package bbUI
 */

var bbLoader = {
    _loaded:[],
    _require: function(l) {
        document.write('<script type="text/javascript" src="'+l+'"></script>');
    },
    load: function(s, m, p) {
        if (typeof Array.prototype.push == 'undefined') {
            return;
        }
        var _0, _1, _2;
        _0 = (typeof(p) == 'undefined') ? '/resources/js/' : p;
        _1 = (typeof(m) == 'undefined') ? '' : m+='/';
        for(var i=0;i<s.length;i++) {
            _2 = _0+_1+s[i]+'.js';
            if (!this.isloaded(_2)) {
                this._require(_2);
                this._loaded.push(_2);
            }
        }
    },
    addCss: function(css, media) {
        if (!document.getElementsByTagName &&
            !document.createElement &&
            !document.createAttribute) {
            return;
        }
        var link = document.createElement('LINK');
        /* todo: check defeat NS6 */
        link.rel = 'stylesheet';
        if (typeof(media) != 'undefined') {
            link.media = media;
        }
        link.href = css;
        document.getElementsByTagName('head')[0].appendChild(link);
    },
    isloaded: function(s) {
        for (i=0;i<this._loaded.length;i++) {
            if (this._loaded[i] == s) {
                return true;
            }
        }
        return false;
    },
    compat: function(p) {
        var compat = [];
        if (!!(window.attachEvent && !window.opera)) {
            compat.push('ie');
        }
        this.load(compat, 'compat', p);
        return compat;
    }
}
if (!Array.push ) {
    Array.prototype.push = function(e) {
        this[this.length] = e;
    }
}
