/*
 *  copyright: Multimedia atelier 2003
 *     author: Lukas Duffek
 *    project: WYSIWYG Sample
 *       date: 2003-02-28
 */

/* 
  ObjectRef class
*/
function ObjectRef(objId) {
  this.elementRef = null;
  this.styleRef = null;
  this.id = objId;
  this.assigned = false;

  /* ObjectRef.get() */
  ObjectRef.prototype.get = function(objId) {
    if (document.getElementById) {
      this.elementRef = document.getElementById(objId);
      (this.elementRef == null) ? this.styleRef = null : this.styleRef = this.elementRef.style;
    }
    else if (document.all) {
      this.elementRef = document.all[objId];
      (this.elementRef == null) ? this.styleRef = null : this.styleRef = this.elementRef.style;
    }
    else if (document.layers) {
      this.elementRef = document.layers[objId];
      (this.elementRef == null) ? this.styleRef = null : this.styleRef = this.elementRef;
    }
    (this.elementRef == null) ? this.assigned = false : this.assigned = true;
  }
  
  /* ObjectRef.isVisible() */
  ObjectRef.prototype.isVisible = function() {
    if (this.styleRef) {
      return ((this.styleRef.visibility != "hidden") && (this.styleRef.display != "none"));
    }
  }
  
  /* ObjectRef.toggleVisibility() */
  ObjectRef.prototype.toggleVisibility = function(value) {
    if (this.styleRef == null) return;
    if ((value != null) && ((value == "visible") || (value == "hidden"))) {
      this.styleRef.visibility = value;
    }
    if (value == null) {
      if (this.isVisible()) {
        this.styleRef.visibility = "hidden";
      }
      else {
        this.styleRef.visibility = "visible";
      }  
    }
  }
  
  /* ObjectRef.toggleDisplay() */
  ObjectRef.prototype.toggleDisplay = function(value) {
    if (this.styleRef == null) return;
    if (value != null) {
      this.styleRef.display = value;
    }
    if (value == null) {
      if (this.isVisible()) {
        this.styleRef.display = "none";
      }
      else {
        this.styleRef.display = "";
      }  
    }
  }
  
  /* ObjectRef.findChild() */
  ObjectRef.prototype.findChild = function(objId) {
    // DOM browsers only
    for (i = 0; i < this.elementRef.children.length; i++) {
      if (this.elementRef.children[i].id == objId) {
        return this.elementRef.children[i];
      }
      else {
        return this.findChild(this.elementRef.children[i]);
      }
    }
  }

  if (this.id != null) {
    this.get(objId);
  }

}



