// Test for DOM 1.0 Browser
var isDom = false;
if (document.getElementById){
	isDom = true;
}

if (isDom) {

var fully_loaded = false; // must set to true when fully loaded

var objects;
var object_count = 0;

var image_name = new Array();
var image_count = 0;

var object_name = new Array();

// create base objects
function create_base_objects() {
  objects = document.getElementsByTagName("DIV");

  for( i = 0; i < objects.length; i++ ) {
    current_name = objects[i].id;
    object_name[ current_name ] = new base_object( objects[i] );
  }
}

// create image objects
function create_image_objects(d) {
  var i = d.images;
  var n = i.length;
  for( var x = 0; x < n; x++ ) {
    current_name = i[x].name;
    if( current_name == "" ) {
      current_name = "image" + image_count;
      image_count++;
    }
    
    if( ! image_name[ current_name ] ) {
      image_name[ current_name ] = new image_object( i[x] );
    }
  }
}

function base_object( object ) {
  object_count++;
  
  this.style = object.style;
  this.name = object.id;

  // handle visibility
  this.conceal = conceal;
  this.reveal = reveal;
  this.is_visible = is_visible;

  // handle positioning variables
  this.left = get_left;
  this.get_left = get_left;
  this.set_left = set_left;
  this.top = get_top;
  this.get_top = get_top;
  this.set_top = set_top;

  // handle absolute and relative positioning
  this.place = place;
}

// image objects
function image_object(i) {
  i.get_name = get_image_name;
  i.get_height = get_image_height;
  i.get_width = get_image_width;
  i.get_x = get_image_x;
  i.get_y = get_image_y;
  i.get_left = get_image_x; // added for abut() and overlay()
  i.get_top = get_image_y; // added for abut() and overlay()
  i.get_src = get_image_src;
  i.set_src = set_image_src;

  return i;
}

// hide the object
function conceal() {
  this.style.visibility = "hidden";
}

// show the object
function reveal() {
  this.style.visibility = "visible";
}

// is the object visible?
function is_visible() {
  if (this.style.visibility == "visible") {
	return true;
  }
  return false;
}

// return the object's left position
function get_left() {
  var l = parseInt(this.style.left);
  return l;
}

// set the object's left position
function set_left(l) {
  this.style.left = l + "px";
}

// return the object's top position
function get_top() {
  var t = parseInt(this.style.top);
  return t;
}

// set the object's top position
function set_top(t) {
  this.style.top = t + "px";
}


// place object absolutely
function place( x, y ) {
  this.style.left = x + "px";
  this.style.top = y + "px";
}

// get the name of the image
function get_image_name() {
  return this.name;
}

// get image height
function get_image_height() {
  return this.height;
}

// get image width
function get_image_width() {
  return this.width;
}

// get the image's URL of origin
function get_image_src() {
  return this.src;
}

// set the image's src
function set_image_src(s) {
  this.src = s;
}

// where is the image on the page?
function get_image_x() {
  // IE returns offsetLeft relative to current container
  // so we walk the hierarchy and sum them up
  // todo: need to do the same for Netscape if image is inside a layer
  if( this.offsetParent ) {
    var current = this;
    var the_x = 0;
    while( current.offsetParent != null ) {
      the_x += current.offsetLeft;
      current = current.offsetParent;
    }
    return the_x;
  } else if( this.x ) {
    return this.x;
  } else {
    return 0;
  }
}

function get_image_y() {
  // IE returns offsetTop relative to current container
  // so we walk the hierarchy and sum them up
  // todo: need to do the same for Netscape if image is inside a layer
  if( this.offsetParent ) {
    var current = this;
    var the_y = 0;
    while( current.offsetParent != null ) {
      the_y += current.offsetTop;
      current = current.offsetParent;
    }
    return the_y;
  } else if( this.y ) {
    return this.y;
  } else {
    return 0;
  }
}

// track mouse movement
var mouse_x = 0;
var mouse_y = 0;
function track_mouse(e) {
  e = e || window.Event || window.event;
  mouse_x = e.pageX || e.clientX;
  mouse_y = e.pageY || e.clientY;
}

}