// ===============================================================
// copyright Grontmij | Carl Bro GIS&IT, 2009
// ===============================================================

(function() {
    /**
     * Namespace: dk.cbkort.boligejer
     * The dk.cbkort.boligejer object provides a namespace for all things dk.cbkort.boligejer
     */
    window.dk = {};
    window.dk.cbkort = {};
    window.dk.cbkort.boligejer = {

        /**
         * Property: _jsfiles
         * {Array} List of js files to include.
         */
        _jsfiles: new Array(
            //"js/jquery/jquery.js", 
            "colorpicker/js/colorpicker.js",
            "colorpicker/js/eye.js",
            //"colorpicker/js/layout.js" ,  // taken out due to IE minimize bug
            "colorpicker/js/utils.js",
            "kort/kommunedata.js",
            "kort/kort1.3.js"
        ),
        
        /**
         * Property: _scriptName
         * {String} Relative path of this script.
         */
        _scriptName: "stamkort1.3.js",

        /**
         * Function: _getScriptLocation
         * Return the path to this script.
         *
         * Returns:
         * {String} Path to this script
         */
        _getScriptLocation: function () {
            var scriptLocation = "";            
            var isOL = new RegExp("(^|(.*?\\/))(" + dk.cbkort.boligejer._scriptName + ")(\\?|$)");
         
            var scripts = document.getElementsByTagName('script');
            for (var i=0, len=scripts.length; i<len; i++) {
                var src = scripts[i].getAttribute('src');
                if (src) {
                    var match = src.match(isOL);
                    if(match) {
                        scriptLocation = match[1];
                        break;
                    }
                }
            }
            return scriptLocation;
        },
        
        _allScriptTags: [],
        
        _addScriptTag: function (jsfile) {
            var agent = navigator.userAgent;
            var docWrite = (agent.match("MSIE") || agent.match("Safari"));
            if (docWrite) {
                this._allScriptTags.push ("<script src='" + jsfile + "'></script>"); 
            } else {
                var s = document.createElement("script");
                s.src = jsfile;
                var h = document.getElementsByTagName("head").length ? 
                           document.getElementsByTagName("head")[0] : 
                           document.body;
                h.appendChild(s);
            }
        }
    };
    
    var host = dk.cbkort.boligejer._getScriptLocation();
    
    for (var i=0, len=dk.cbkort.boligejer._jsfiles.length; i<len; i++) {
        var jsfile = host + dk.cbkort.boligejer._jsfiles[i];
        dk.cbkort.boligejer._addScriptTag (jsfile);
    }

    var agent = navigator.userAgent;
    var docWrite = (agent.match("MSIE") || agent.match("Safari"));
    if (docWrite) {
        document.write(dk.cbkort.boligejer._allScriptTags.join(""));
    }
})();

/**
 * Constant: VERSION_NUMBER
 */
dk.cbkort.boligejer.VERSION_NUMBER="dk.cbkort.boligejer 0.1 -- $Revision: 1.3 $";
