/*
 * Project:     zdk-portal
 *
 * Copyright:   Copyright (c) 2007
 * Company:     SecureNet GmbH
 * Created:     Feb 11, 2010
 * Author:      Knut Sander, knut.sander@securenet.de (ks)
 * Version:     1.0
 *
 * SVN-Info:    $Revision:: 972    $ by $Author:: ks    $
 *              $LastChangedDate:: 2010-02-11 13:29:14 #$
 */

/***********************************************************************************************************************
 * jquery*.js based ZDK js stuff
 **********************************************************************************************************************/

jQuery.fn.centerElement = function()
{

  var sTop = function()
  {
    return window.pageYOffset || document.documentElement && document.documentElement.scrollTop
        || document.body.scrollTop;
  }

  var sLeft = function()
  {
    return window.pageXOffset || document.documentElement && document.documentElement.scrollLeft
        || document.body.scrollLeft;
  }

  var iHeight = function()
  {
    return window.innerHeight || document.documentElement && document.documentElement.clientHeight
        || document.body.clientHeight;
  }

  var iWidth = function()
  {
    return window.innerWidth || document.documentElement && document.documentElement.clientWidth
        || document.body.clientWidth;
  }

  return this.each(function(index)
  {
    var elmWidth = jQuery(this).width();
    var elmHeight = jQuery(this).height();
    var scrollTop = sTop();
    var scrollLeft = sLeft();
    var innerHeight = iHeight();
    var innerWidth = iWidth();

    var top = scrollTop + (innerHeight / 2) - (elmHeight / 2);
    var left = scrollLeft + (innerWidth / 2) - (elmWidth / 2);
    top = (top > 0 ? top : 0);
    left = (left > 0 ? left : 0);
    
    jQuery(this).css(
    {
      'position' : 'absolute',
      'top' : top,
      'left' : left
    });
  });
}
// -- eof --------------------------------------------------------------------------------------------------------------
