  /*
   * (c)2011 John Pezzetti
   *
   * addDomLoadEvent is (c)2006 Jesse Skinner/Dean Edwards/Matthias Miller/John Resig
   *
   * For more info, see:
   * http://www.johnpezzetti.com/?p=141
   * http://www.thefutureoftheweb.com/blog/adddomloadevent
   * http://www.alexandre-gomes.com/?p=115
   * http://stackoverflow.com/questions/681087/how-can-i-detect-a-scrollbar-presence-using-javascript-in-html-iframe
   *
   */

  window.scrollBarsFix = function () {

    var addDOMLoadEvent = (function () {
      var load_events = [], load_timer, script, done, exec, old_onload;
      var init = function () {
        done = true;
        clearInterval (load_timer);
        while (exec = load_events.shift ())
          exec ();
        if (script)
          script.onreadystatechange = '';
      }
      return function (func) {
        if (done)
          return func ();
        if (!load_events[0]) {
          if (document.addEventListener)
            document.addEventListener ('DOMContentLoaded', init, false);
          /*@cc_on @*/
          /*@if (@_win32)
            document.write ('<script id=__ie_onload defer src=//0><\/scr' + 'ipt>');
            script = document.getElementById ('__ie_onload');
            script.onreadystatechange = function () {
              if (this.readyState == 'complete')
                init ();
            };
          /*@end @*/
          if (/WebKit/i.test (navigator.userAgent)) {
            load_timer = setInterval (function () {
              if (/loaded|complete/.test (document.readyState))
                init ();
            }, 10);
          }
          old_onload = window.onload;
          window.onload = function () {
            init ();
            if (old_onload)
              old_onload ();
          };
        }
        load_events.push (func);
      }
    }) ();

    function getScrollerWidth () {
      var scr = null, inn = null, wNoScroll = 0, wScroll = 0;
      scr = document.createElement ('div');
      scr.style.position = 'absolute';
      scr.style.top = '-1000px';
      scr.style.left = '-1000px';
      scr.style.width = '100px';
      scr.style.height = '50px';
      scr.style.overflow = 'hidden';
      inn = document.createElement ('div');
      inn.style.width = '100%';
      inn.style.height = '200px';
      scr.appendChild (inn);
      document.body.appendChild (scr);
      wNoScroll = inn.offsetWidth;
      scr.style.overflow = 'auto';
      wScroll = inn.offsetWidth;
      document.body.removeChild (document.body.lastChild);
      return (wNoScroll - wScroll);
    }
 
    function preventPageShift () {
      var root = document.compatMode == 'BackCompat' ? document.body : document.documentElement;
      var isVerticalScrollbar = root.scrollHeight > root.clientHeight;
      if (isVerticalScrollbar) {
        var scrollWidth = getScrollerWidth ();
        //document.body.style.marginLeft = '-' + scrollWidth + 'px';
        document.body.style.marginRight = '-' + scrollWidth + 'px';
      } else
        document.body.style.marginRight = 0;
    }
 
    addDOMLoadEvent (preventPageShift);
    window.onresize = function () {
      preventPageShift ();
    }

  }


