Array.prototype.indexOf = function(s)
{
  for(var a = 0; a < this.length; a++)
    if(this[a] == s)
      return a;
    return -1;
};

var domAPIVersion = "3.00";
var debugMode = false;
var useCompression = true;
var internalElmCount = 0;
var domAPIElms = [];
var domAPILibs = ["core"];

function unitLoaded(name)
{
  return domAPILibs.indexOf(name) > -1;
};

function loadUnit(name)
{
//  if(unitLoaded(name))
//    return false;
  domAPILibs[domAPILibs.length] = name;
  extDir = ["animate","color","drag","reflow","validate","more_themes","quicksort","sysutils","cookie"];
  rootDir = ["core","debug","elm","theme","corecolor","mozillaext","coreutil" ];
  if(rootDir.indexOf(name) > -1)
    subdir = "";
  else if(extDir.indexOf(name) > -1)
    subdir = "ext/";
  else
    subdir = "gui/";
  name += (useCompression ? "_c" : "") + ".js";
  document.writeln('<script type="text\/javascript" src="' + domAPILibPath + subdir + name + '"><\/script>');
};

function getUnitPath(name)
{
  var r = false;
  var i;
  var re = new RegExp("\/?"+name+"[\._]");
  var tags = document.getElementsByTagName("SCRIPT");
  for(var a = 0; a < tags.length; a++)
  {
    i = tags[a].src.search(re);
    if(i > -1)
      r = tags[a].src.substr(0, i + 1);
  }
  return r;
};

var isDom = document.getElementById ? 1 : 0;
var isIE = (navigator.userAgent.indexOf("MSIE") > 0) ? 1 : 0;
var isNS = (navigator.userAgent.indexOf("Gecko") > 0) ? 1 : 0;
var isMac = (navigator.userAgent.indexOf("Mac") > 0) ? 1 : 0;
var isIE5 = 0;
var isIE50 = 0;
var isIE55 = 0;
var isIE60 = 0;

if(isIE)
{
  var i = navigator.appVersion.indexOf("MSIE");
  var temp = navigator.appVersion.substring(i + 5, i + 8);
  isIE50 = (temp == "5.0");
  isIE55 = (temp == "5.5");
  isIE60 = (temp == "6.0");
  isIE6 = (temp == "6.");
  isIE5 = isIE50 || isIE55;
};

function checkStrict()
{
  var strict = false;
  var d = document.doctype;
  strict = (document.compatMode == "CSS1Compat");
  strict = (d && d.systemId ? (d.systemId.indexOf("strict") > -1 ? true : (d.publicId.indexOf("transitional") >- 1 ? true : false)) : (d && d.publicId.indexOf("transitional") == -1 ? true : strict));
  strict = (d && d.name.indexOf(".dtd") > -1) ? true : strict;
  return strict;
}

var isStrict = checkStrict();
var needsBoxFix = (isIE5 &&!isMac) || (isIE60  && !isStrict);
var domAPILibPath = getUnitPath("core");
var domAPIImgPath = domAPILibPath + "gui/images/";
if(debugMode)
  loadUnit("debug");

function bodyElm()
{
  return document.body;
};

var cursorHand = isIE5 ? "hand":"pointer";
var cursorVertBeam = isIE ? (isIE5 ? "move" : "col-resize") : "move";
var cursorHorzBeam = isIE ? (isIE5 ? "move" : "row-resize") : "move";

loadUnit("elm");
loadUnit("theme");
loadUnit("coreutil");
loadUnit("corecolor");
if(isNS)
  loadUnit("mozillaext");
function addEvent(o, t, fn)
{
  if(o.addEventListener)
  {
    o.addEventListener(t, fn, true);
    return true;
  }
  else if(o.attachEvent)
    return o.attachEvent("on" + t, fn);
  else
    alert("Handler could not be attached");
};

function removeEvent(o, t, fn)
{
  if(o.removeEventListener)
  {
    o.removeEventListener(t, fn, true);
    return true;
  }
  else if(o.detachEvent)
    return o.detachEvent("on" + t, fn);
  else
    alert("Handler could not be removed");
};

function preventBubble(E)
{
  if(isIE)
  {
    event.cancelBubble = true;
    event.returnValue = false;
  }
  else
    E.preventDefault();
};

