/*
Carrego tots els fitxers .js definits més avall (array jsfiles)
*/

(function() {
    window.IdeLocal = {
        _scriptName: "js/ideLocal.js",
        _getScriptLocation: function () {
            var scriptLocation = "";
            var scriptName = IdeLocal._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(
		//"CercadorToponims.class.js",
		//"SceneInfo.class.js",
		"ScaleBar.class.js",
		"LayerSwitcher.class.js",
		"PanZoom.class.js",
		"PanZoomBar.class.js",
		//"Click.class.js",
		//"descarregues.js",
		//"imprimeix.js",
		//"tradueix.js",
		//"scriptaculous/scriptaculous.js",
		"PermalinkWindow.Class.js",
		"WMS.class.js",
		"NavToolbar.class.js",
		"GetFeatureInfo.class.js",
		"featureInfo.js",
		"Google.class.js"
		//"Click.class.js",
		//"Measure.js",
		//"MeasureToolbar.js",
		//"ModifyFeature.js",
		//"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 = IdeLocal._getScriptLocation() + "js/ideLocal_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(""));
	}
})();

