/*
 *  DHTMLLayer
 *
 *  Roberto Pérez Guzmán
 *  gedas Mexico
 *
 *
 *
 *
 *  DEPENDENCIAS
 *    DHTML.js
 */

function DHTMLLayer(  name, x, y ){
  
  this.setVisible   = DHTMLLayer_setVisible;
    
  this.getX         = DHTMLLayer_getX;
  this.getY         = DHTMLLayer_getY;
  this.setX         = DHTMLLayer_setX;
  this.setY         = DHTMLLayer_setY;
  this.setXY        = DHTMLLayer_setXY;

  this.getWidth     = DHTMLLayer_getWidth;
  this.getHeight    = DHTMLLayer_getHeight;
  this.setWidth     = DHTMLLayer_setWidth;
  this.setHeight    = DHTMLLayer_setHeight;
  this.setSize      = DHTMLLayer_setSize;
  
  
  this.ref          = MM_findObj( name );
  this.name         = name;
  
  
  this.setMouseMoveHandler  = DHTMLLayer_setMouseMoveHandler;
  this.setMouseDownHandler  = DHTMLLayer_setMouseDownHandler;
  this.setMouseUpHandler    = DHTMLLayer_setMouseUpHandler;
  this.setMouseOutHandler   = DHTMLLayer_setMouseOutHandler;
  this.setOnDragHandler     = DHTMLLayer_setOnDragHandler;

  
  if(x!=null){
    this.setX( x );
  }
  if(y!=null){
    this.setY( y );
  }
}

function DHTMLLayer_getX(){
  var x;
  
  if( document.layers ){
    x = this.ref.left;
  }
  else{
    x = this.ref.offsetLeft;
  }
  return parseInt( x );
}

function DHTMLLayer_getY(){
  var y;
  if( document.layers ){
    y = this.ref.top;
  }
  else{
    y = this.ref.offsetTop;
  }
  return parseInt( y );
}

function DHTMLLayer_getWidth(){
  var width;
  if( document.layers ){
    width = this.ref.clip.width;  
  }
  else{
    width = this.ref.offsetWidth;
  }
  return parseFloat( width );
}

function DHTMLLayer_getHeight(){
  var height;
  if( document.layers ){
    height = this.ref.clip.height;
  }
  else{
    height = this.ref.offsetHeight;
  }
  return parseFloat( height );
}

function DHTMLLayer_setXY( x, y ){
  this.setX( x );
  this.setY( y );
}

function DHTMLLayer_setX( x ){
  x = parseInt( x );
  
  if( isNaN(x)) return;
  if( document.layers ){
    this.ref.left = x;
  }
  else{
    this.ref.style.left = x;
  }
}

function DHTMLLayer_setY( y ){
  y = parseInt( y );
  if( isNaN(y)) return;
  
  if( document.layers ){
    this.ref.top = y;
  }
  else{
    this.ref.style.top = y;
  }
}

function DHTMLLayer_setSize( width, height ){
  this.setWidth( width )
  this.setHeight( height )
}

function DHTMLLayer_setWidth( width ){
  if( document.layers ){
    this.ref.clip.width = width;
  }
  else{
    this.ref.style.width  = width;
    var clip =  "rect(0 " + width + " " + this.getHeight() + " 0)" 
    this.ref.style.clip = clip;    
  }
}

function DHTMLLayer_setHeight( height ){
  if( document.layers ){
    this.ref.clip.height = height;
  }
  else{
    
    this.ref.style.height = height;
    var clip =  "rect(0 " + this.getWidth() + " " + height + " 0)" 
    this.ref.style.clip = clip; 
  }
}

function DHTMLLayer_setVisible( visible ){
  MM_showHideLayers( this.name, "", visible?"show":"hide" )
}


//------------------
// Events handlers
//------------------
function DHTMLLayer_setMouseMoveHandler( handler ){
  if( document.layers ){
    this.ref.captureEvents( Event.MOUSEMOVE );
	}

  this.ref.onmousemove = handler
}

function DHTMLLayer_setMouseDownHandler( handler ){
  if( document.layers ){
    this.ref.captureEvents( Event.MOUSEDOWN);
	}
  this.ref.onmousedown = handler
}

function DHTMLLayer_setMouseUpHandler( handler ){
  if( document.layers ){
    this.ref.captureEvents( Event.MOUSEUP);
  }
  this.ref.onmouseup = handler
}
 
function DHTMLLayer_setMouseOutHandler( handler ){
  if( document.layers ){
    this.ref.captureEvents( Event.MOUSEOUT);
	}
  this.ref.onmouseout = handler
}

function DHTMLLayer_setOnDragHandler( handler ){
  if( document.layers ){
    this.ref.captureEvents( Event.MOUSEDRAG);
	}
  this.ref.ondrag = handler
}

