var ldr_rootHttp="/", ldr_rootFile="cosmoSite/";
var ldr_relRoot=ldr_getRelativeRoot((document.location.protocol=="file:")?ldr_rootFile:ldr_rootHttp);

var ldr_styles=[
               ];

var ldr_scripts=[
                ];

//******************************************************** site independant global variables
var ldr_microsoft=(navigator.userAgent.indexOf('MSIE')!=-1);
var ldr_toLoadCount=ldr_scripts.length;

//******************************************************************************************
// gives the relative "up-dir" part that "returns" a url to the site root
//******************************************************************** ldr_getRelativeRoot()
function ldr_getRelativeRoot(root)
{
var path=document.location.pathname.replace(/\\/g, '/');
if (path.charAt(path.length-1)=='\/') path+="[DIR-INDEX]";
var pos=path.indexOf(root);
if (pos!=-1) path=path.substring(pos+root.length);
var parts=path.split(/[\/\\]/);
path="";
for (var i=0; i<parts.length-1; i++) if (parts[i].length) path+="../";
return path;
}

//******************************************************************* ldr_makeRelativeLink()
function ldr_makeRelativeLink(ref)
{
if (ref.indexOf(':')!=-1) return ref;  // contains protocol; don't mess with it
if (ref.charAt(0)=='\/') return ref;   // absolute path; dont't mess it up
if (ref.charAt(0)=='.') return ref;    // explicitly relative path; dont't change it
if (ref.indexOf('/')==-1) return ref;  // special case: no dir included; same as above
return ldr_relRoot+ref;
}

//************************************************************************ ldr_onLoadScript()
function ldr_onLoadScript(who)
{
if (--ldr_toLoadCount) return;
window.onload=pg_init;
}

//**************************************************************** ldr_loadStylesAndScripts()
function ldr_loadStylesAndScripts()
{
var head=document.getElementsByTagName('head')[0];
var i, node, last;
// insert styles BEFORE existing <style> declarations, to make sure overrides are applied last
last=head.getElementsByTagName("style").item(0);
for (i=ldr_styles.length-1; i>=0; i--)
  {
  node=document.createElement('link');
  node.rel="stylesheet";
  node.type="text/css";
  node.href=ldr_makeRelativeLink(ldr_styles[i]);
  last=head.insertBefore(node, last);
  }
// scripts are executed as loaded (e.g. global var assignments and function name 
// registrations), so order of node insertion is irrelevant. Load them at dependence
// order. No need for last=head.getElementsByTagName("script").item(0); initialization
// and last=head.insertBefore(node, last); in a reverse loop, as with styles
for (i=0; i<ldr_scripts.length; i++)
  {
  node=document.createElement('script');
  node.src=ldr_makeRelativeLink(ldr_scripts[i]);
  if (!ldr_microsoft) node.onload=ldr_onLoadScript;
  else node.onreadystatechange=function()
    { var s=event.srcElement.readyState; if (s=="complete" || s=="loaded") ldr_onLoadScript(); }
  head.appendChild(node);
  }
}

//************************************************************************************* main
ldr_loadStylesAndScripts();

