/*
Version History
RRH 2006 04 14 added cookie
RRH 2006 03 20 added Console

JsLoader - created by Russ Hurlbut - adapted from Scriptaculous.js
Use - Method 1:  use the _defaultFiles array
Use - Method 2:  inlcude script names in the load query string parameter as a comma separated list of javascript files (must end in ".js". 
          NOTE: these will automatically get loaded.
  <SCRIPT LANGUAGE="JavaScript" src="JsLoader.js?foo=bar&load=testA,testB"> </script>
Use - Method 3:  invoke the jacascript call directly, e.g.
  JsLoader.load('testA,testB);

NOTE: All files typically are placed in the same directory as this file. 
      However, relative paths to this location may be used (NOT relative to the web page that loaded this file)
      e.g. '../../../js/foobar.js'
Either of these examples will create the follwing DOM elements:
  
<SCRIPT src="testA.js" type=text/javascript></SCRIPT>
<SCRIPT src="testA.js" type=text/javascript></SCRIPT>

*/

// portions of included js file included (c) 2006-2007 matt mikul & veloroutes.org (condition: "feel free to copy, just list veloroutes.org as a source").

var JsLoader = {
  _defaultFiles : ['Xltd', 'vars', 'globals', 'util', 'elevation', 'dpPolyline', 'route_mngmt', 'autorouting', 'gis_lib', 'gis_db', 'gmap', 'TPhoto'],
  _require: function(libraryName) {
    // inserting via DOM fails in Safari 2.0, so brute force approach
    document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
  },
  load: function(includes) {
  var nl = document.getElementsByTagName("script");
    for(var i=0; i<nl.length;i++) {
      var s = nl[i].src;
      if (s.match(/JsLoader\.js(\?.*)?$/)) {
        var path = s.replace(/JsLoader\.js(\?.*)?$/,'');
        var a = null;
        if(includes) {
          a = includes.split(',');
        } else {
          var loadStr = s.match(/[?&]load=.*[^&]/);
          if (loadStr) {
            a = loadStr[0].substr(6).split(',');
          }
        }
        a = a?a:this._defaultFiles;
        if (a) {
          for(j=0;j<a.length;j++) {
            this._require(path + a[j] + '.js');
          }
        }
      }
    }
  }
}

JsLoader.load();
