//---------------------------------------------------------------------------------
//  (c) 2007 Guardian Networks, Inc
//---------------------------------------------------------------------------------
GNgui.GNguiHExpandDiv = Class.create ( );

GNgui.GNguiHExpandDiv.prototype = 
{
	initialize : function ( ObjNameBase , Parent , X , Y , Width , Height, Image , ImageWidth, ImageHeight, overflow, Direction)
	{

   	this.ObjNameBase = ObjNameBase;
	  this.ContainerDiv = $ce( 'div' );
	  this.ContainerDiv.id = ObjNameBase;
	  this.MaxWidth = Width;
	  this.ImageWidth = ImageWidth;
	  this.Closed = true;
	  //Element.extend ( this.ContainerDiv );
	  this.ContainerDiv.style.position = 'absolute';

   	this.ContainerDiv.ParentObj = this;
    this.Direction = Direction;
   	
   	if ( this.Direction == "right")
   	{
	    this.ContainerDiv.innerHTML = '<div id="' + ObjNameBase + 'InnerDiv" class="Opacity80" style="background-color:#FFFFFF;overflow:' + overflow + ';font-family: Arial;	font-weight: normal;font-size: 10px;position:absolute;left:0px;top:0px;visibility:hidden;width:' + (Width - ImageWidth) + 'px;height:' + Height+ 'px;">' +
	    '</Div>' +
	      '<img src="' + Image + '" id="' + ObjNameBase + 'Image" style="position:absolute;left:0px;top:0px;visibility:inherit;" class="Opacity100">';

      	  
	    $ac(Parent,this.ContainerDiv);

	    $e(ObjNameBase).Persistent = true;

      $el(this.ContainerDiv.id,X)
      $et(this.ContainerDiv.id,Y)
      $ew(this.ContainerDiv.id,ImageWidth);
      $eh(this.ContainerDiv.id,Height);
    }
    else
    {
    	    this.ContainerDiv.innerHTML = '<div id="' + ObjNameBase + 'InnerDiv" class="Opacity80" style="background-color:#FFFFFF;overflow:' + overflow + ';font-family: Arial;	font-weight: normal;font-size: 10px;position:absolute;left:' + ImageWidth + 'px;top:0px;visibility:hidden;width:' + (Width - ImageWidth) + 'px;height:' + Height+ 'px;">' +
	    '</Div>' +
	      '<img src="' + Image + '" id="' + ObjNameBase + 'Image" style="position:absolute;left:0px;top:0px;visibility:inherit;" class="Opacity100">';
  	  
	    $ac(Parent,this.ContainerDiv);

	    $e(ObjNameBase).Persistent = true;

      $el(this.ContainerDiv.id,X - ImageWidth)
      $et(this.ContainerDiv.id,Y)
      $ew(this.ContainerDiv.id,ImageWidth);
      $eh(this.ContainerDiv.id,Height);
    
    }
    this.Image = $e(ObjNameBase+'Image');
    $e(ObjNameBase + 'InnerDiv').className = 'HExpandContainerInner';

    Event.observe ( this.Image , 'mousedown' , Catch.bindAsEventListener() );
    Event.observe ( this.Image , 'mouseup' , this.OpenOrClose.bindAsEventListener(this) );
    Event.observe ( this.Image , 'click' , Catch.bindAsEventListener() );

    Event.observe ( $e(this.ObjNameBase + 'InnerDiv') , 'mousedown' , Catch.bindAsEventListener() );
    Event.observe ( $e(this.ObjNameBase + 'InnerDiv') , 'mouseup' , Catch.bindAsEventListener() );
    
    Gutenberg.Subscribe ( 'RefreshMap',this.CloseDiv.bindAsEventListener(this));
	},
	
	CloseDiv : function ()
	{
	  if ( this.Direction == "right" )
    {
      $ew(this.ContainerDiv,this.ImageWidth);
      $e(this.ObjNameBase + 'InnerDiv').style.visibility = 'hidden';
      $el(this.ObjNameBase+'Image',0);
    }
    else
    {
      $ew(this.ContainerDiv,this.ImageWidth);
      $e(this.ObjNameBase + 'InnerDiv').style.visibility = 'hidden';
      $el(this.ObjNameBase+'Image',0);
      $el(this.ContainerDiv,CONTENTWIDTH - this.ImageWidth);
    }
    this.Closed = true;
	},
	
	OpenDiv : function ()
	{
	  if ( this.Closed == true )
	  {
      if ( this.Direction == "right" )
      {
        $ew(this.ContainerDiv,this.MaxWidth);
        $e(this.ObjNameBase + 'InnerDiv').style.visibility = 'inherit';
        $el(this.ObjNameBase+'Image',(this.MaxWidth - this.ImageWidth));
      }
      else
      {
        $ew(this.ContainerDiv,this.MaxWidth);
        $el(this.ContainerDiv,$el(this.ContainerDiv)-this.MaxWidth+this.ImageWidth);
        $e(this.ObjNameBase + 'InnerDiv').style.visibility = 'inherit';
        $el(this.ObjNameBase+'Image',0);
      }
      this.Closed= false;
    }
	},
	
	OpenOrClose : function ( event )
	{
	  if ( this.Closed )
	  {
      this.OpenDiv();
	  }
	  else
	  {
	    this.CloseDiv();
	  }

	  Event.stop ( event );
    return false;
	}
}

