// (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

// note from Susanna: original script at http://www.yasd.com/samples/dhtml/cbsafety.htm
// updated for Netscape 6/W3C DOM on 8/2000 by Susanna King using Shelley Powers' code from 
// http://www.inquiry.com/techtips/dhtml_pro/10min/10min1299/10min1299.asp

var loaded = "" // added by Susanna King to aide in Netscape's event capturing
				// this variable has to be set before anything else happens

// create IE DHTML equalizer object
// note from Susanna: you can delete any functions not being used
function ie_object(obj) {
	this.css1 = obj;
	this.name = obj.id;
	this.objResizeBy = ieobjResizeBy;
	this.objHide = ieobjHide; 
	this.objShow = ieobjShow; 
	this.objGetLeft = ieobjGetLeft; 
	this.objGetTop = ieobjGetTop; 
	this.objSetTop = ieobjSetTop;
	this.objSetLeft = ieobjSetLeft;
	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;
}

//
// 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 = "inherit";
}

// 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.slice(0,strng.length-2));
	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
// note from Susanna: you can delete any functions not being used
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();
}

// new standards-compliant object code by Shelley Powers, with additions by Susanna King
// create DOM object
 function dom_object(obj) {
    this.css = obj;
    this.name = obj.name;
    this.objHide = domHide;
    this.objShow = domShow;
    this.objChangeFontColor = domChangeFontColor;
    this.objChangeBackgroundColor = domChangeBackgroundColor;
	this.objSetTop = domSetTop;
	this.objSetLeft = domSetLeft;
	this.objMoveAbsolute = domMoveAbsolute;
    this.objGetVisibility = domGetVisibility;
 }
 
 //you'll see from the code that these methods are nearly identical to those listed for IE
 // IE/DOM hide element
 function domHide() {
    this.css.style.visibility = "hidden";
 }

 // IE/DOM show element
 function domShow() {
    this.css.style.visibility = "visible";
 }

 // IE/DOM change font
 function domChangeFontColor(clr) {
    this.css.style.color=clr;
 }

 // IE/DOM change font
 function domChangeBackgroundColor(clr) {
    this.css.style.backgroundColor = clr;
 }
 
 // set element's top position
function domSetTop (top) {
	this.css.style.top = top;
}

// set element's left position
function domSetLeft(left) {
	this.css.style.left = left;
}

// make absolute move
function domMoveAbsolute(newleft, newtop) {
	this.objSetLeft(newleft);
      this.objSetTop(newtop);
}

function domGetVisibility() {
    return this.css.style.visibility;
}

// 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]);
     }
	loaded = true;
}

function create_dom_objects() {
  theelements = document.getElementsByTagName("DIV");
  theobjs = new Array();
 for (i = 0; i < theelements.length; i++) {
     var obj = theelements[i];
     theobjs[obj.id] = new dom_object(obj);
     }
}

function create_objects() {
    // if 5.0 browser
	
    if (parseInt(navigator.appVersion) > 4){
        create_dom_objects();
    }else {
        if (navigator.appName == "Microsoft Internet Explorer"){
           create_ie_objects();
        }else{
           create_ns_objects();
		 }
	}
}
