// (C) Shelley Powers, YASD, 1999
//
// These are the newest version of the cross-browser scripting objects, incorporated into one 
// Javascript file. 
//
// each browser gets its own object, with similar interfaces but differing implementations


// create IE DHTML equalizer object
function ie_object(obj) {
	this.css1 = obj;
	this.name = obj.id;
	this.objResizeBy = domResizeBy;
	this.objHide = ieobjHide;
	this.objShow = ieobjShow;
	this.objGetLeft = domGetLeft;
	this.objGetTop = domGetTop;
	this.objSetTop = domSetTop;
	this.objSetLeft = domSetLeft;
	this.objMoveAbsolute = ieobjMoveAbsolute;
	this.objMoveRelative = ieobjMoveRelative;
	this.objGetWidth = ieobjGetWidth;
	this.objGetHeight = ieobjGetHeight;
	this.objSetHeight = ieobjSetHeight;
	this.objSetWidth = ieobjSetWidth;
	this.objSetZIndex = ieobjSetZIndex;
	this.objGetZIndex = ieobjGetZIndex;
	this.objSetClipRect = ieobjSetClipRect;
	this.objGetClipLeft = ieobjGetClipLeft;
	this.objGetClipRight = ieobjGetClipRight;
	this.objGetClipTop = ieobjGetClipTop;
	this.objGetClipBottom = ieobjGetClipBottom;
	this.replace_html = iereplace_html;
        this.objGetVisibility = ieobjGetVisibility;
	this.objChangeSource = ieobjChangeSource;
}
// create IE DHTML equalizer object
function dom_object(obj) {
	this.css1 = obj;
	this.name = obj.id;
	this.objResizeBy = domResizeBy;
	this.objHide = ieobjHide;
	this.objShow = ieobjShow;
	this.objGetLeft = domGetLeft;
	this.objGetTop = domGetTop;
	this.objSetTop = domSetTop;
	this.objSetLeft = domSetLeft;
	this.objMoveAbsolute = ieobjMoveAbsolute;
	this.objMoveRelative = ieobjMoveRelative;
	this.objGetWidth = domGetWidth;
	this.objGetHeight = domGetHeight;
	this.objSetHeight = domSetHeight;
	this.objSetWidth = domSetWidth;
	this.objSetZIndex = ieobjSetZIndex;
	this.objGetZIndex = ieobjGetZIndex;
	this.objSetClipRect = domSetClipRect;
	this.objGetClipLeft = ieobjGetClipLeft;
	this.objGetClipRight = ieobjGetClipRight;
	this.objGetClipTop = ieobjGetClipTop;
	this.objGetClipBottom = ieobjGetClipBottom;
	this.replace_html = iereplace_html;
        this.objGetVisibility = ieobjGetVisibility;
	this.objChangeSource = ieobjChangeSource;
}


function domResizeBy(wincr,hincr) {
	this.css1.style.left-=hincr;
	this.css1.style.top-=wincr;
	this.css1.style.width+=(2 * hincr);
	this.css1.style.height+=(2 * wincr);
}


// element's left position
function domGetLeft() {
	return parseInt(this.css1.style.left);
}

// element's top position
function domGetTop () {
	return parseInt(this.css1.style.top);
}

// set element's top position
function domSetTop (top) {
	this.css1.style.top = top + "px";
}

// set element's left position
function domSetLeft(left) {
	this.css1.style.left = left + "px";
}


// get element's width
function domGetWidth() {
	return this.css1.style.width;
}

// get element's height
function domGetHeight() {
	return this.css1.style.height;
}

// set element's height
function domSetHeight(height) {
	this.css1.style.height = height;
}

// set element's width
function domSetWidth(width) {
	this.css1.style.width = width;
}

// clip object
function domSetClipRect(top,left, bottom, right) {
	if (top == null) top = this.objGetClipTop();
	if (left == null) left = this.objGetClipLeft();
	if (bottom == null) bottom = this.objGetClipBottom();
	if (right == null) right = this.objGetClipRight();
      strng = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)";
	this.css1.style.clip = strng;
}
//
// Author: Shelley Powers
// The IE specific scripting object methods
//
//*************************************************************************************



function ieobjGetVisibility() {
    return this.css1.style.visibility;
}

function ieobjResizeBy(wincr,hincr) {
	this.css1.style.pixelLeft-=hincr;
	this.css1.style.pixelTop-=wincr;
	this.css1.style.pixelWidth+=(2 * hincr);
	this.css1.style.pixelHeight+=(2 * wincr);
}


// hide element
function ieobjHide() {
	this.css1.style.visibility = "hidden";
}

// show element
function ieobjShow() {
	this.css1.style.visibility = "visible";
}

// element's left position
function ieobjGetLeft() {
	return this.css1.style.pixelLeft;
}

// element's top position
function ieobjGetTop () {
	return this.css1.style.pixelTop;
}

// set element's top position
function ieobjSetTop (top) {
	this.css1.style.pixelTop = top;
}

// set element's left position
function ieobjSetLeft(left) {
	this.css1.style.pixelLeft = left;
}

// make absolute move
function ieobjMoveAbsolute(newleft, newtop) {
	this.objSetLeft(newleft);
      this.objSetTop(newtop);
}

// move relative to current location
function ieobjMoveRelative(left, top) {
	this.objSetLeft(left + this.objGetLeft());
	this.objSetTop(top + this.objGetTop());
    
}

// get element's width
function ieobjGetWidth() {
	return this.css1.style.pixelWidth;
}

// get element's height
function ieobjGetHeight() {
	return this.css1.style.pixelHeight;
}

// set element's height
function ieobjSetHeight(height) {
	this.css1.style.pixelHeight = height;
}

// set element's width
function ieobjSetWidth(width) {
	this.css1.style.pixelWidth = width;
}

// set element's zindex order
function ieobjSetZIndex(zindex) {
	this.css1.style.zIndex = zindex;
}

// get element's current zindex order
function ieobjGetZIndex(zindex) {
	return this.css1.style.zIndex;
}

// clip object
function ieobjSetClipRect(top,left, bottom, right) {
	if (top == null) top = this.objGetClipTop();
	if (left == null) left = this.objGetClipLeft();
	if (bottom == null) bottom = this.objGetClipBottom();
	if (right == null) right = this.objGetClipRight();
      strng = "rect(" + top + "," + right + "," + bottom + "," + left + ")";
	this.css1.style.clip = strng;
}

// convert string to value
function convert(strng) {
    var i = parseInt(strng);
    return i;
}

function get_entry(obj,indx) {
	strng = obj.css1.style.clip;
	strng = strng.slice(5,strng.length-1);
	var entries = strng.split(" ");
	if (indx == "top")
		if (entries[0] == "auto") 
		   return obj.objGetTop();
		else
		   return convert(entries[0]);
	else if (indx == "left")
		if (entries[3] == "auto") 
		   return obj.objGetLeft();
		else
		   return convert(entries[3]);
	else if (indx == "bottom")
		if (entries[2] == "auto") 
		   return obj.objGetHeight();
		else
		   return convert(entries[2]);
	else if (indx == "right")
		if (entries[1] == "auto") 
		   return obj.objGetWidth();
		else
		   return convert(entries[1]);
	
}
	
// clip object on left
function ieobjGetClipLeft() {
	return get_entry(this,"left");
}

// clip object on right
function ieobjGetClipRight() {
	return get_entry(this, "right");
}

// clip object at top
function ieobjGetClipTop() {
	return get_entry(this,"top");
}

// clip object at bottom
function ieobjGetClipBottom() {
	return get_entry(this,"bottom");
}

function iereplace_html(html_string) {
	this.css1.innerHTML = html_string;
} 

function ieobjChangeSource(sourcefile,width) {
  var name = this.name;
  this.css1.src = sourcefile;
}


//
// Author: Shelley Powers
// The Navigator specific scripting object methods
//
//*************************************************************************************

// Navigator object
function ns_object(obj) {
	this.css1 = obj;
	this.name = obj.name;
	this.objResizeBy = nsobjResizeBy;
	this.objHide = nsobjHide;
	this.objShow = nsobjShow;
	this.objGetLeft = nsobjGetLeft;
	this.objGetTop = nsobjGetTop;
	this.objSetTop = nsobjSetTop;
	this.objSetLeft = nsobjSetLeft;
	this.objMoveAbsolute = nsobjMoveAbsolute;
	this.objMoveRelative = nsobjMoveRelative;
	this.objGetWidth = nsobjGetWidth;
	this.objGetHeight = nsobjGetHeight;
	this.objSetHeight = nsobjSetHeight;
	this.objSetWidth = nsobjSetWidth;
	this.objSetZIndex = nsobjSetZIndex;
	this.objGetZIndex = nsobjGetZIndex;
	this.objSetClipRect = nsobjSetClipRect;
	this.objGetClipLeft = nsobjGetClipLeft;
	this.objGetClipRight = nsobjGetClipRight;
	this.objGetClipTop = nsobjGetClipTop;
	this.objGetClipBottom = nsobjGetClipBottom;
	this.objGetClipWidth = nsobjGetClipWidth;
	this.objGetClipHeight = nsobjGetClipHeight;
	this.replace_html = nsreplace_html;
	this.objChangeSource = nsobjChangeSource;
}


// the Navigator specific implementation

// resize element
function nsobjResizeBy(w_incr, h_incr) {
	this.css1.left-=w_incr / 2;
	this.css1.width-=w_incr / 2;
	this.css1.top+=h_incr / 2;
	this.css1.height+=h_incr / 2;
}

// hide element
function nsobjHide() {
	this.css1.visibility = "hidden";
}

// show element
function nsobjShow() {
	this.css1.visibility = "inherit";
}

// element's left position
function nsobjGetLeft() {
	return this.css1.left;
}

// element's top position
function nsobjGetTop () {
	return this.css1.top;
}

// set element's top position
function nsobjSetTop(top) {
	this.css1.top = top;
}

// set element's left position
function nsobjSetLeft(left) {
	this.css1.left = left;
}

// make absolute move
function nsobjMoveAbsolute(newleft, newtop) {
	this.objSetLeft(newleft);
	this.objSetTop(newtop);
}

// move relative to current location
function nsobjMoveRelative(left, top) {
	this.objSetLeft(left + this.objGetLeft());
	this.objSetTop(top + this.objGetTop());
}

// get element's width
function nsobjGetWidth() {
	return this.css1.clip.width;
}

// get element's height
function nsobjGetHeight() {
	return this.css1.clip.height;
}

// set element's width
function nsobjSetWidth(width) {
	this.css1.clip.width = width;
}

// set element's height
function nsobjSetHeight(height) {
	this.css1.clip.height = height;
}

// set element's zindex order
function nsobjSetZIndex(zindex) {
	this.css1.zIndex = zindex;
}

// get element's current zindex order
function nsobjGetZIndex() {
	return style.zIndex;
}

// clip object
function nsobjSetClipRect (top,left,bottom,right) {
	if (top == null) top = this.objGetClipTop();
	if (left == null) left = this.objGetClipLeft();
	if (bottom == null) bottom = this.objGetClipBottom();
	if (right == null) right = this.objGetClipRight();
	this.css1.clip.left = left;
	this.css1.clip.right = right;
	this.css1.clip.top = top;
	this.css1.clip.bottom = bottom;
}

// get current clip right 
function nsobjGetClipRight() {
	return this.css1.clip.right;
}

// get current clip left
function nsobjGetClipLeft() {
	return this.css1.clip.left;
}

// get current clip top
function nsobjGetClipTop() {
	return this.css1.clip.top;
}

// get current clip bottom
function nsobjGetClipBottom() {
	return this.css1.clip.bottom;
}

// get current clip bottom
function nsobjGetClipWidth() {
	return this.css1.clip.width;
}

// get current clip bottom
function nsobjGetClipHeight() {
	return this.css1.clip.height;
}


function nsreplace_html(html_string) {
	this.css1.document.write(html_string);
	this.css1.document.close();
}

function nsobjChangeSource(sourcefile, width) {
   var clipbottom;
   this.objHide();
   clipbottom = this.objGetClipBottom();
   this.css1.load(sourcefile, width);
   this.css1.clip.bottom = clipbottom;
   this.objShow();
}



// Create the objects
//
//****************************************************************************************


// function to create named and unnamed objects
function create_ie_objects() {
   theelements = document.all;
   theobjs = new Array();
   for (i = 0; i < theelements.length; i++){
      if (theelements[i].id != "") {
	   theobjs[theelements[i].id] = new ie_object(theelements[i]);
	   }
      }
}

// function to instantiate equalizer objects
function create_ns_objects(newarray) {
   theobjs = new Array();
   for (i = 0; i < document.layers.length; i++){
     if (document.layers[i].name != "") 
   	 theobjs[document.layers[i].name] = new ns_object(document.layers[i]);
     }
}

// create DOM objects
function create_dom_objects() {
  theelements = document.getElementsByTagName("DIV");
  theobjs = new Array();
  for (i = 0; i < theelements.length; i++) {
      var obj = theelements[i];
      if (obj.id != "")
         theobjs[obj.id] = new dom_object(obj);
      }
}
// call correct object loading method    
function create_objects() {

    // if 5.0 browser
    if (navigator.appVersion.indexOf("5.0") != -1)
	create_dom_objects();
    else 
    	if (navigator.appName == "Microsoft Internet Explorer")
	   create_ie_objects();
        else
  	   create_ns_objects();
}

