/*---------------------------------------------------------------------------*
 * -- zBrowserUtils
 *---------------------------------------------------------------------------*
 *  Browser window/DOM utilities
 *---------------------------------------------------------------------------*/

function zBrowserUtils() { }

zBrowserUtils.getWidth = function() {
  if(window.innerHeight) { return window.innerWidth; }
  if(document.documentElement && document.documentElement.clientWidth) { return document.documentElement.clientWidth; }
  if(document.body) { return document.body.clientWidth; }
};

zBrowserUtils.getHeight = function() {
  if(window.innerHeight) { return window.innerHeight; }
  if(document.documentElement && document.documentElement.clientHeight) { return document.documentElement.clientHeight; }
  if(document.body) { return document.body.clientHeight; }
};

zBrowserUtils.resizeAllImages = function() {
  var ln_max = zBrowserUtils.getWidth() * .6;
  for( var i = 0; i < document.images.length; i++ ) {
    zBrowserUtils.resizeImage( document.images[i], ln_max );
  }
};

zBrowserUtils.resizeImage = function( io_img, in_max ) {
  if( !in_max ) { var in_max = zBrowserUtils.getWidth() * .6; }
  if( io_img.width > in_max ) { io_img.width = in_max; }
};

zBrowserUtils.getCenterX = function( in_width ) {
  var ln_width = ( in_width ) ? in_width : 0;
  return ( zBrowserUtils.getWidth() / 2 ) - ( ln_width / 2 );
};

zBrowserUtils.getCenterY = function( in_height ) {
  var ln_height = ( in_height ) ? in_height : 0;
  return ( zBrowserUtils.getHeight() / 2 ) - ( ln_height / 2 );
};

zBrowserUtils.getElementLeft = function(o) {
  var x = o.offsetLeft, p = o.offsetParent;
  while (p != null) { x += p.offsetLeft; p = p.offsetParent; }
  return x;
};

zBrowserUtils.getElementTop = function(o) {
  var y = o.offsetTop, p = o.offsetParent;
  while (p != null) { y += p.offsetTop; p = p.offsetParent; }
  return y;
};

zBrowserUtils.getElementHeight = function(o) {
  return o.offsetHeight;
};
zBrowserUtils.getElementWidth = function(o) {
  return o.offsetWidth;
};

zBrowserUtils.setElementOpacity = function( io_element, in_opacity ) {
  if( in_opacity < 0 || in_opacity > 10 ) { throw new Error( 'Invalid opacity: ' + in_opacity ); }
  io_element.style.filter = 'alpha(style=0,opacity:' + (in_opacity * 10) + ')'; // IE
  io_element.style.KHTMLOpacity = in_opacity / 10;       // Konqueror
  io_element.style.MozOpacity = in_opacity / 10;         // Mozilla (old)
  io_element.style.opacity = in_opacity / 10;            // Mozilla (new)
};

zBrowserUtils.getDocumentHead = function( ) {
  return document.getElementsByTagName('head')[0];
};

zBrowserUtils.getMouseXY = function(evt) {
  var lo_coords = { left: 0, top: 0};
  //if (evt.pageX) {
  //  lo_coords.left = evt.pageX;
  //  lo_coords.top = evt.pageY;
  //} else if (evt.clientX) {
    lo_coords.left = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
    lo_coords.top = evt.clientY + document.body.scrollTop - document.body.clientTop;
    if (document.body.parentElement && document.body.parentElement.clientLeft) {
      var bodParent = document.body.parentElement;
      lo_coords.left += bodParent.scrollLeft - bodParent.clientLeft;
      lo_coords.top += bodParent.scrollTop - bodParent.clientTop;
    }
  //}
  return lo_coords;
};

zBrowserUtils.stopProp = function(e) {
  if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
};


