function hbScreenOverlay (url, screenXY, size, pane, opacity)
{
  this.url = url;
  this.screenXY = screenXY;
  this.size = size;
  this.opacity = opacity;
  this.pane = pane;
  this.visibilityHandler = null;
  this.resizeHandler = null;
}

hbScreenOverlay.prototype = new GOverlay ();
hbScreenOverlay.prototype.map_top = 0;
hbScreenOverlay.prototype.map_bottom = 0;
hbScreenOverlay.prototype.map_left = 0;
hbScreenOverlay.prototype.map_right = 0;

hbScreenOverlay.prototype.initialize = function (map)
{
  this.map = map;

  this.img = document.createElement ("img");
  this.img.style.position = "fixed";
  this.img.style.opacity = this.opacity;
  this.img.style.MozOpacity = this.opacity;
  this.img.style.filter  = "alpha(opacity=" + 100 * this.opacity + ")";
  this.img.src = this.url;

  map.getPane (this.pane).appendChild (this.img);
}

hbScreenOverlay.prototype.remove = function ()
{
  if (this.img)
  {
    this.img.parentNode.removeEventListener ('DOMAttrModified', this.visibilityHandler, false);
    document.getElementById ("map").removeEventListener ('DOMAttrModified', this.resizeHandler, false);
    this.img.parentNode.removeChild (this.img);
    this.img = undefined;
    this.map = undefined;
  }
}

hbScreenOverlay.prototype.copy = function ()
{
  return new hbScreenOverlay (this.url, this.screenXY, this.size, this.opacity);
}

hbScreenOverlay.prototype.redraw = function (force)
{
  var mapElem = document.getElementById ("map");

  if (true == force)
  {
    var w = this.size.size.width;
    var h = this.size.size.height;

    if ("fraction" == this.size.xunits)
    {
      w *= mapElem.offsetWidth;
    }

    if ("fraction" == this.size.yunits)
    {
      h *= mapElem.offsetHeight;
    }
    
    var topDist = null;

    if (undefined != this.screenXY.top)
    {
      if (this.screenXY.topUnit == "fraction")
      {
        topDist = hbScreenOverlay.prototype.map_top + this.screenXY.top * mapElem.offsetHeight - h/2;
      }
      else
      {
        topDist = hbScreenOverlay.prototype.map_top + this.screenXY.top;

        /*@cc_on
          @if (@_jscript)
            topDist = topDist - 2;
          @end
        @*/
      }
    }
    if (undefined != this.screenXY.bottom)
    {
      if (this.screenXY.bottomUnit == "fraction")
      {
        topDist = hbScreenOverlay.prototype.map_bottom - this.screenXY.bottom * mapElem.offsetHeight - h/2;
      }
      else
      {
        topDist = hbScreenOverlay.prototype.map_bottom - this.screenXY.bottom - h;

        /*@cc_on
          @if (@_jscript)
            topDist = topDist - 2;
          @end
        @*/
      }
    }

    if (undefined != topDist)
    {
      topDist = topDist + "px";

      if (topDist != this.img.style.top)
      {
        this.img.style.top = topDist;
      }
    }

    var leftDist = null;

    if (undefined != this.screenXY.left)
    {
      if (this.screenXY.leftUnit == "fraction")
      {
        leftDist = hbScreenOverlay.prototype.map_left + this.screenXY.left * mapElem.offsetWidth - w/2;
      }
      else
      {
        leftDist = hbScreenOverlay.prototype.map_left + this.screenXY.left;

        /*@cc_on
          @if (@_jscript)
            leftDist = leftDist - 2;
          @end
        @*/
      }
    }
    if (undefined != this.screenXY.right)
    {
      if (this.screenXY.rightUnit == "fraction")
      {
        leftDist = hbScreenOverlay.prototype.map_right - this.screenXY.right * mapElem.offsetWidth - w/2;
      }
      else
      {
        leftDist = hbScreenOverlay.prototype.map_right - this.screenXY.right - w;

        /*@cc_on
          @if (@_jscript)
            leftDist = leftDist - 2;
          @end
        @*/
      }
    }

    if (undefined != leftDist)
    {
      leftDist = leftDist + "px";

      if (leftDist != this.img.style.left)
      {
        this.img.style.left = leftDist;
      }
    }

    this.img.style.width = w + "px";
    this.img.style.height = h + "px";
  }

  if (!this.visibilityHandler)
  {
    var me = this;
    this.visibilityHandler = function (e)
      {
        if (me.img && (e.attrChange == e.MODIFICATION) && (e.attrName == "style"))
        {
          if ("hidden" == me.img.parentNode.style.visibility)
          {
            me.img.parentNode.style.visibility = '';
          }
        }
      };

    hbEventHandler.add (this.img.parentNode, 'DOMAttrModified', this.visibilityHandler);
//    this.img.parentNode.addEventListener (
//        'DOMAttrModified', this.visibilityHandler, false);
  }

  if (!this.resizeHandler)
  {
    var me = this;
    var w = mapElem.offsetWidth;
    var h = mapElem.offsetHeight;
    var busy = false;

    this.resizeHandler = function (e)
      {
        if (!busy && (e.attrChange == e.MODIFICATION) && (e.attrName == "style"))
        {
          busy = true;

          setTimeout (function ()
          {
            if ((w != mapElem.offsetWidth) || (h != mapElem.offsetHeight))
            {
              me.redraw (true);
              w = mapElem.offsetWidth;
              h = mapElem.offsetHeight;
            }
            
            busy = false;
          }, 100);
        }
      };

    hbEventHandler.add (mapElem, 'DOMAttrModified', this.resizeHandler);
  //  mapElem.addEventListener (
 //       'DOMAttrModified', this.resizeHandler, false);
  }
}
