/**------------------------------------------------------------------------
 * Set of function and classes which deal with coordinates of html nodes
 * 
 * @version $Id: htmlCoordinates.js,v 1.2 2010/07/16 16:17:50 grb Exp $
 *
 *-----------------------------------------------------------------------*/



/**
 * HtmlCoordinates class
 * @param node Html Node
 */

  function HtmlCoordinates(node) {
	this.node = node;
    this.x1 = 0; 
    this.y1 = 0;
    this.x2 = 0;
    this.y2 = 0;
    this.isMouseOutOfElement = isMouseOutOfElement;
    this.getScrollOffsetXY = getScrollOffsetXY;
    var currentNode = node;
    
    if(currentNode.offsetParent) {
      while(currentNode.offsetParent) {
        this.x1 += currentNode.offsetLeft;
        this.y1 += currentNode.offsetTop;
        currentNode = currentNode.offsetParent;
      }
    }
    else if (currentNode.x) {
      this.x1 = currentNode.x;
      this.y1 = currentNode.y;
    }
    this.x2 = this.x1 + node.offsetWidth;
    this.y2 = this.y1 + node.offsetHeight;
    
    
    /* Check if mouse moves out of this element */
    function isMouseOutOfElement(event) {
      var offset = this.getScrollOffsetXY();
      
      isMouseOutX = event.clientX < this.x1 - offset[0] || event.clientX > this.x2 - offset[0];
      isMouseOutY = event.clientY < this.y1 - offset[1]  || event.clientY > this.y2 - offset[1] ;
      return ( isMouseOutX || isMouseOutY );
    }
    
    
    /* Page Scroll Offset  */
    function getScrollOffsetXY() {
  	  var scrOfX = 0, scrOfY = 0;
  	  if( typeof( window.pageYOffset ) == 'number' ) {
  	    //Netscape compliant
  	    scrOfY = window.pageYOffset;
  	    scrOfX = window.pageXOffset;
  	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
  	    //DOM compliant
  	    scrOfY = document.body.scrollTop;
  	    scrOfX = document.body.scrollLeft;
  	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
  	    //IE6 standards compliant mode
  	    scrOfY = document.documentElement.scrollTop;
  	    scrOfX = document.documentElement.scrollLeft;
  	  }
  	  return [ scrOfX, scrOfY ];
  	}
  }