﻿// JScript File

var ElementDimension = (function(){

    var d = document, w = window;
    
    /*
        summary: private method for computing the Offset of an Element
        
    */
	var getOffset = function(el){ 
	  if (document.documentElement["getBoundingClientRect"]){
		var box = el.getBoundingClientRect(),
		doc = el.ownerDocument,
		body = doc.body,
		docElem = doc.documentElement,
		// for ie 
		clientTop = docElem.clientTop || body.clientTop || 0,
		clientLeft = docElem.clientLeft || body.clientLeft || 0,
		
		// In Internet Explorer 7 getBoundingClientRect property is treated as physical,
		// while others are logical. Make all logical, like in IE8.		
		
		zoom = 1;
		
		if (body.getBoundingClientRect) {
			var bound = body.getBoundingClientRect();
			zoom = (bound.right - bound.left)/body.clientWidth;
		}
		
		if (zoom > 1){
			clientTop = 0;
			clientLeft = 0;
		}
		
		var top = box.top/zoom + (window.pageYOffset || docElem && docElem.scrollTop/zoom || body.scrollTop/zoom) - clientTop,
		left = box.left/zoom + (window.pageXOffset|| docElem && docElem.scrollLeft/zoom || body.scrollLeft/zoom) - clientLeft;
	
				
		return {
		    left: left,
			top: top
		};
	}else {
		var top = 0, left = 0;
		do {
			top += el.offsetTop || 0;
			left += el.offsetLeft || 0;
		}while (el = el.offsetParent);
		
		return {
			    left: left,
			    top: top
		 };
	
    }
}
    
    
    
    
    
    
//====================================================================================== 
    
    
   var ElementDimension = {//object Begin
   /* 
    summary:this is a public method for getting the coordinate of an Element
    parameter: el -- an Element object
    return: an object which contains the coordinate of the object.
    Note: we can call it from outside.
   */
        getElementCoordinate : function(el){ 
              var left, right, top, bottom;	
	    var offset = getOffset(el);
	    left = offset.left;
	    top = offset.top;
						
	    right = left + el.offsetWidth;
	    bottom = top + el.offsetHeight;		
		
	    return {
		        left: left,
		        right: right,
		        top: top,
		        bottom: bottom
	        };
        },
        
        /*
            summary: public method, get the size of an Element
            parameter: el -- an Element object
            return : an object which contains the width and height of the object.
            Note: we can call it from outside.
        */
        getElementSize : function(el){
        
           var width = el.offsetWidth,
               height = el.offsetHeight;
               
           return{
                width:width,
                height:height
           }; 
        
        }

    }// object End
    
    return ElementDimension;
 //====================================================================================== 
   
})();