/*
Carrego tots els fitxers .js definits més avall (array jsfiles)
*/

(function() {
    window.rcc = {
        _scriptName: "javascript/ol/rcc.js",
        _getScriptLocation: function () {
            var scriptLocation = "";
            var scriptName = rcc._scriptName;
         
            var scripts = document.getElementsByTagName('script');
            for (var i = 0; i < scripts.length; i++) {
                var src = scripts[i].getAttribute('src');
                if (src) {
                    var index = src.lastIndexOf(scriptName); 
                    // is it found, at the end of the URL?
                    if ((index > -1) && (index + scriptName.length == src.length)) {  
                        scriptLocation = src.slice(0, -scriptName.length);
                        break;
                    }
                }
            }
            return scriptLocation;
         }
    };

	var jsfiles = new Array(
		
		"min.EditingToolbar.js",		
		"min.LayerSwitcher.class.js",
		"min.PanZoom.class.js",
		"min.PanZoomBar.class.js",
		"min.Click.class.js",	
		"min.WMS.class.js",
		"min.NavToolbar.class.js",
        "min.ZoomBox.js",
		"min.Utils.js",
		"min.Esborra.js"
	); // etc.

	var agent = navigator.userAgent;
	var docWrite = (agent.match("MSIE") || agent.match("Safari"));
	if(docWrite) {
		var allScriptTags = new Array(jsfiles.length);
	}
	var host = rcc._getScriptLocation() + "javascript/ol/rcc_lib/";
	for (var i = 0; i < jsfiles.length; i++) {
		if (docWrite) {
			allScriptTags[i] = "<script src='" + host + jsfiles[i] +
							   "'></script>"; 
		} else {
			var s = document.createElement("script");
			s.src = host + jsfiles[i];
			var h = document.getElementsByTagName("head").length ? 
					   document.getElementsByTagName("head")[0] : 
					   document.body;
			h.appendChild(s);
		}
	}
	if (docWrite) {
		document.write(allScriptTags.join(""));
	}
})();

