/*
 *	DHTMLScrollArea
 *
 *      +--data-----------------------------+
 *      |+-dataCONTENT----------------------|......
 *      ||                                  |     .
 *      ||                                  |     .
 *      ||                                  |     .
 *      ||                                  |     .
 *      ||                                  |     .
 *      +-----------------------------------+     .
 *       .                                        .
 *       ..........................................
 */    
function DHTMLScrollArea( divContainer, divContent ){
   /*
   * Metodos
   */
  this.move = DHTMLScrollArea_move
  
  this.isHScroll          = DHTMLScrollArea_isHScroll
  this.isVScroll          = DHTMLScrollArea_isVScroll
  this.getScrollWidth     = DHTMLScrollArea_getScrollWidth
  this.getScrollHeight    = DHTMLScrollArea_getScrollHeight
  this.getContentWidth    = DHTMLScrollArea_getContentWidth
  this.getContentHeight   = DHTMLScrollArea_getContentHeight
  this.getContainerWidth  = DHTMLScrollArea_getContainerWidth
  this.getContainerHeight = DHTMLScrollArea_getContainerHeight

  /*
   * Atributos
   */
  this.container  = new DHTMLLayer( divContainer );
  this.content    = new DHTMLLayer( divContent, 0, 0 );
}

function DHTMLScrollArea_move( offsetX, offsetY ){

  var x = this.content.getX() + offsetX;
  var y = this.content.getY() + offsetY;
  
  var maxWidth   = this.container.getWidth();
  var maxHeight  = this.container.getHeight();
  
  var width   = this.content.getWidth();
  var height  = this.content.getHeight();
  
  if( width > maxWidth ){
    offsetWidth = width - maxWidth
  }
  else{
    offsetWidth = 0
  }
  
  if( height > maxHeight ){
    offsetHeight = height - maxHeight
  }
  else{
    offsetHeight = 0
  }  

  if( x > 0  ){
    x = 0
  }
  else{
    if( Math.abs(x) > offsetWidth ){
      x = -offsetWidth
    }
  }
   
  if( y > 0  ){
    y = 0
  }
  else{
    if( Math.abs(y) > offsetHeight ){
      y = -offsetHeight
    }
  }
  
  
  this.content.setX( x );
  this.content.setY( y );
}

function DHTMLScrollArea_isHScroll(){
  return (this.getScrollWidth() != 0 );
}

function DHTMLScrollArea_isVScroll(){
  return (this.getScrollHeight() != 0 );
}

function DHTMLScrollArea_getContentWidth(){
  return this.content.getWidth();
}

function DHTMLScrollArea_getContentHeight(){
  return this.content.getHeight();
}

function DHTMLScrollArea_getContainerWidth(){
  return this.container.getWidth();
}

function DHTMLScrollArea_getContainerHeight(){
  return this.container.getHeight();
}

function DHTMLScrollArea_getScrollWidth(){
  if( this.getContentWidth() > this.getContainerWidth() ){
    return this.getContentWidth() - this.getContainerWidth();
  }
  return 0;
}

function DHTMLScrollArea_getScrollHeight(){
  if( this.getContentHeight() > this.getContainerHeight() ){
    return this.getContentHeight() - this.getContainerHeight();
  }
  return 0;
}
