/**
 * Part of JMF Library 
 * This file contains extension to DOM methods that are not strictly connected to dom nodes
 * SVN: $Id: domutil.js 6163 2008-08-14 14:36:31Z mjezierski $
 * @version 0.1b
 */

/**
 * Namespace for DOM utils
 */
JMF.Domutil = {
   /**
    * Returns vieport size
    * @return {Object} Vieport bounds (width, height, top, left, right, bottom)
    */
   getViewport:function() {
   	var vw = 0;
   	var vh = 0;
   	
		if (window.innerWidth) {
			vw = window.innerWidth;
			//FF includes scrollbars into inner width, so we want to substract them
			if(JMF.browser.FF && vw > document.body.parentNode.offsetWidth) {
				vw = document.body.parentNode.offsetWidth;
			}
			vh = window.innerHeight;
		} else {
			if(document.body.parentNode.clientWidth) {
				vw = document.body.parentNode.clientWidth;
			} else {
				vw = document.body.clientWidth;
			}
			
			if(document.body.parentNode.clientHeight) {
				vh = document.body.parentNode.clientHeight;
			} else {
				vh = document.body.clientHeight;
			}
		}
		
		var st;
		var sl;
		
      if(!document.body.scrollTop && document.body.parentNode && typeof(document.body.parentNode.scrollTop) !== 'undefined') {
      	st = document.body.parentNode.scrollTop;
      } else {
         st = document.body.scrollTop;
      }
      
      if(!document.body.scrollLeft && document.body.parentNode && typeof(document.body.parentNode.scrollLeft) !== 'undefined') {
      	sl = document.body.parentNode.scrollLeft;
      } else {
         sl = document.body.scrollLeft;
      }
		
		return {width:vw,height:vh,top:st,left:sl,right:vw+sl,bottom:vh+st};
	},
	/**
	 * Gets computed style
	 * @return {Object} Style object
	 * NOTE: returned styles may slightly vary due to other methods used in  various browsers
	 */
	getComputedStyle:function(obj) {
	  if(window.getComputedStyle) {
	  	  return window.getComputedStyle(obj,'');
	  }

	  if(obj.currentStyle) {
	  		return obj.currentStyle;
	  	}

      return {};
	},
	/*
	 * returns width and height of a viewport
	 */
	getViewportSize:function() {
		return {width:window.innerWidth||(document.documentElement||{}).clientWidth||0,
		        height:window.innerHeight||(document.documentElement||{}).clientHeight||0};
	},
	/**
	 * Gets full viewport size (whole accessible workspace)
	 * @member JMF.Domutil
	 * @return {Object} Bounds object
	 */
	getFullViewport:function() {
      var vh;
      var vw;
      
      if(document.body.parentNode && document.body.parentNode.offsetHeight) {
      	vh = document.body.parentNode.offsetHeight;
      } else {
      	vh = document.body.offsetHeight;
      }
      
      if(window.innerHeight && window.innerHeight > vh) {
      	vh = window.innerHeight;
      } else if(document.body.parentNode && document.body.parentNode.clientHeight > vh) {
      	vh = document.body.parentNode.clientHeight;
      } else if(document.body.clientHeight > vh) {
      	vh = document.body.clientHeight;
      }

      if(document.body.parentNode && document.body.parentNode.offsetWidth) {
         vw = document.body.parentNode.offsetWidth;
      } else {
         vw = document.body.offsetWidth;
      }
      
      if(window.innerWidth && window.innerWidth > vw) {
         wv = window.innerWidth;
      } else if(document.body.parentNode && document.body.parentNode.clientWidth > vw) {
         vw = document.body.parentNode.clientWidth;
      } else if(document.body.clientWidrh > vw) {
         vw = document.body.clientWidth;
      }

      if(document.body.scrollHeight > vh) {
         vh = document.body.scrollHeight;
      }

      if(document.body.scrollWidth > vw) {
         vw = document.body.scrollWidth;
      }

      return {top:0,left:0,bottom:vh,right:vw,width:vw,height:vh};
	}
};
