/*
 * Funktionen für den Zugriff auf Browsereigenschaften
 *
 * Author: A. Kuzmanovski
 * Date: 1.2.2011
 * Version: 1.0
 * Depends: jQuery
 *
 * 
 **/
jQuery.noConflict();

/**
 * Prüfen, ob Browser die Seite zoomt, in dem die entsprechenden Tastenschläge
 * kontrolliert werden
 *
 * Verwendung:
 *  jQuery().zoom(function(){
        doSomething();
        ....

    });
 *
 * Voraussetzungen ?
 *
 */
jQuery.fn.zoom = function(fn) {
  jQuery(document).keydown(function(e){
    switch (true) {
      case jQuery.browser.mozilla || jQuery.browser.msie :
        if (e.ctrlKey && (
          e.which == 187 ||
          e.which == 189 ||
          e.which == 107 ||
          e.which == 109 ||
          e.which == 96  ||
          e.which == 48
        )) fn();
        break;
      case jQuery.browser.opera :
        if (
          e.which == 43 ||
          e.which == 45 ||
          e.which == 42 ||
          (e.ctrlKey && e.which == 48)
        ) fn();
        break;
      case jQuery.browser.safari :
        if ((e.metaKey || e.ctrlKey) && (
          e.charCode == 43 ||
          e.charCode == 45
        )) fn();
        break;
    }
    return;
  });

  jQuery(document).bind('mousewheel', function(e){
    if (e.ctrlKey) fn();
  });

  jQuery(document).bind('DOMMouseScroll', function(e){
    if (e.ctrlKey) fn();
  });
};


/**
*
*/
function maximize_window() {
    window.resizeTo(screen.availWidth, screen.availHeight);
    window.moveTo(0,0);
}

/**
* Liefert die Größe des Browser-Fensters
*
*
* return {width, height, type:[inner,client document,client body]}
 */
function getWindowSize() {
  var myWidth = 0, myHeight = 0, t = "";
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    t = "inner";

  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    t = "client document";

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    t = "client body";

  }
   return {width: myWidth, height: myHeight, type: t};
}

/**
 *
 */
function getWindowScrollSize() {
  var myWidth = 0, myHeight = 0, t = "";
  if( typeof( window.scrollWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.scrollWidth;
    myHeight = window.scrollHeight;
    t = "inner";

  } else if( document.documentElement && (  document.documentElement.scrollHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.scrollWidth;
    myHeight = document.documentElement.scrollHeight;
    t = "client document";

  } else if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.scrollWidth;
    myHeight = document.body.scrollHeight;
    t = "client body";

  }
  return {width: myWidth, height: myHeight, type: t};
}

/**
 * 
 */
function window_has_vertical_scrollbar()  {
   ss = getWindowScrollSize();
   s = getWindowSize();
   if (s.height < ss.height)
    return true;
   else
    return false;
  }

/**
 * 
 */
function window_has_horizontal_scrollbar()  {
   elem = document.getElementById(elem_id);
   ss = getWindowScrollSize();
   s = getWindowSize();
   if (s.width < ss.width)
    return true;
   else
    return false;
}
