var g_zIndex = new Number(0);
var g_GUI_Objects = new Array();


function DetectInternetExplorer()
{
  if (navigator.appName == 'Microsoft Internet Explorer')
    return true;
  return false;
}





function GUI_Object()
{
  // member variables ...
  this.m_htmlObject = undefined;
  this.m_parent = undefined;
  this.m_type = undefined;

  // event hooks ...
  this.OnHide = undefined;
  this.OnShow = undefined;

  // methods ...
  this.IsInternetExplorer = function()
  {
    var browser=navigator.appName;
    return (browser=="Microsoft Internet Explorer");
  }


  this.GetID = function()
  {
    return this.m_id;
  }


  this.Type = function()
  {
    return this.m_type;
  }


  this.IsGuiObject = function()
  {
    return true;
  }


  this.SetPosition = function(x, y)
  {
    this.m_htmlObject.style.position = 'absolute';
    this.m_htmlObject.style.left = x + 'px';
    this.m_htmlObject.style.top = y + 'px';
  }


  this.MoveToFront = function()
  {
    this.m_htmlObject.style.zIndex = ++g_zIndex;
  }


  this.CreateHtmlObject = function(tagType)
  {
    this.m_htmlObject = document.createElement(tagType);
    this.m_htmlObject.SetStyle = function(styleName){SetStyle(this, styleName);}  
    this.m_htmlObject.m_guiObject = this;
    this.m_id = g_GUI_Objects.length + '_' + Math.random();
    g_GUI_Objects[this.m_id] = this;
 
  }


  this.SetStyle = function(cssStyleName)
  {
    SetStyle(this.m_htmlObject, cssStyleName);
  }


  this.GetHTML = function()
  {
    return this.m_htmlObject;
  }


  this.SetParent = function(parent)
  {
    if ((parent == 0) || (parent == undefined) || (parent == null))
    {
      if (this.m_parent)
        this.m_parent.removeChild(this.m_htmlObject);
      this.m_parent = undefined;
      return;
    }

    if (this.m_parent)
      this.SetParent(0);
    this.m_parent = parent;
    parent.appendChild(this.m_htmlObject);
  }

 
  this.Show = function()
  {
    this.m_htmlObject.style.display = 'inline';
    this.m_visible = true;
    if (this.OnShow != undefined)
      this.OnShow();
  }


  this.Hide = function()
  {
    if (this.OnHide != undefined)
      this.OnHide();
    this.m_htmlObject.style.display = 'none';
    this.m_visible = false;
  }


  this.Width = function()
  {
    if (this.m_htmlObject)
      return this.m_htmlObject.offsetWidth;
    return undefined;
  }


  this.Height = function()
  {
    if (this.m_htmlObject)
      return this.m_htmlObject.offsetHeight;
    return undefined;
  }


  this.Top = function()
  {
    if (this.m_htmlObject)
    {
      var obj = this.m_htmlObject;
      var x = 0;
      while (obj)
      {
        if (obj == document.body)
          return x;
        if (!isNaN(obj.offsetTop))
          x += obj.offsetTop;
        if (!this.IsInternetExplorer())
          if (!isNaN(obj.clientTop))
            x += obj.clientTop;
        obj = obj.offsetParent;
      }
    }
    return undefined;
  }


  this.Left = function()
  {
    if (this.m_htmlObject)
    {
      var x = 0;
      var obj = this.m_htmlObject;
      while (obj)
      {
        if (obj == document.body)
          return x;
        if (!isNaN(obj.offsetLeft))
          x += obj.offsetLeft;
        if (!this.IsInternetExplorer())
          if (!isNaN(obj.clientLeft))
            x += obj.clientLeft;     
        obj = obj.offsetParent;
      }
    }
    return undefined;
  }

}
