  /**
   * eGV initializer. Handles the loading of single or multiple files scripts of OpenLayers and eGV libraries
   */


  /**
   * Before creating the eGV namespace, check to see if
   * eGV.singleFile is true.  This occurs if the
   * eGV/SingleFile.js script is included before this one - as is the
   * case with single file builds.
   */
  var singleFile = (typeof eGV == "object" && eGV.singleFile);

	var eGVInit = {
          /**
	   * Property: scriptName
	   * {String} Name of this script.
	   */
		scriptName: (!singleFile) ? "egv-init.js" : "egv-init-c.js",

        /**
	   * Property: scriptName
	   * {String} Relative path of this script.
	   */
		scriptRoot: "",

		/**
		 * Function: _getScriptLocation
		 * Return the path to this script.
		 *
		 * Returns:
		 * {String} Path to this script
		 */
		_getScriptLocation: function() {
		  var scriptLocation = "";
		  //var scriptName = OpenLayers._scriptName;
		  var scriptName = this.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 index = src.lastIndexOf(scriptName);
		          // set path length for src up to a query string
		          var pathLength = src.lastIndexOf('?');
		          if (pathLength < 0) {
		              pathLength = src.length;
		          }
		          // is it found, at the end of the URL?
		          if ((index > -1) && (index + scriptName.length == pathLength)) {
		              scriptLocation = src.slice(0, pathLength - scriptName.length);
		              break;
		          }
		      }
		  }

		  return scriptLocation;
		},

		/**
		 * Function: includeScript
		 * Includes a script to the document header
		 *
		 * Returns:
		 * Nothing
		 */
		includeScript : function(filename,id){
        // There was an ugly browser detection, probably for MSIE6?
        // Removed 28/03/2011, because it makes Firefox 4 fail
        //var agent = navigator.userAgent;
        //var docWrite = (agent.match("MSIE") || agent.match("Safari"));
        //if (docWrite) {
        if (id) id = " id='" + id + "'";
        document.write("<script src='" + filename +"'" + id + "></script>");
        /*} else {
            var s = document.createElement("script");
            s.src = filename;
            if (id) s.id = id;
            var h = document.getElementsByTagName("head").length ?
                       document.getElementsByTagName("head")[0] :
                       document.body;
            h.appendChild(s);
        }*/

      }

    }

    //Get script location
    eGVInit.scriptRoot = eGVInit._getScriptLocation();

    //Load OpenLayers and eGV
    if(!singleFile){
        eGVInit.includeScript(eGVInit.scriptRoot + "egv/lib/egv.js","scripteGV");
        eGVInit.includeScript(eGVInit.scriptRoot + "egv/lib/egv-libs.js","scripteGV");
    }else{
        eGVInit.includeScript(eGVInit.scriptRoot + "egv/egv.js","scripteGV");
    }


