(function() {
  screenH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  function getOffsetTop(o) {
    var t = o.offsetTop;
    var p = o.offsetParent;
    while (p != null) {
      t += p.offsetTop;
      p = p.offsetParent
    }
    return t
  }
  function LeftRight() {
    var scrollTop = 0;
    var scrollNow = 0;
    var v = {};
    v["lo"] = document.getElementById("left");
    v["ro"] = document.getElementById("right");
    v["lt"] = getOffsetTop(v["lo"]);
    v["rt"] = getOffsetTop(v["ro"]);
    v["lm"] = parseInt("0" + getStyle(v["lo"], "marginTop"));
    v["rm"] = parseInt("0" + getStyle(v["ro"], "marginTop"));
    addEvent(window, "scroll",
    function() {
      scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
      v["li"] = v["lo"].getBoundingClientRect();
      v["ri"] = v["ro"].getBoundingClientRect();
      v["lh"] = v["li"].bottom - v["li"].top;
      v["rh"] = v["ri"].bottom - v["ri"].top;
      v["la"] = v["lt"] + v["lm"] + v["lh"];
      v["ra"] = v["rt"] + v["rm"] + v["rh"];
      var d = parseInt(v["la"] - v["ra"]);
      if (d == 0) {
        return
      }
      if (d > 0) {
        var s = "r";
        var b = "l"
      } else {
        var s = "l";
        var b = "r"
      }
      d = Math.abs(d);
      if (v[s + "h"] - screenH <= 0) {
        if (scrollTop >= v[s + "t"]) {
          if (scrollTop >= v[s + "t"] + d) {
            v[s + "o"].style.marginTop = (v[s + "m"] + d) + "px"
          } else {
            v[s + "o"].style.marginTop = (v[s + "m"] + scrollTop - v[s + "t"]) + "px"
          }
        } else {
          v[s + "o"].style.marginTop = v[s + "m"] + "px"
        }
      } else {
        if (scrollTop >= v[s + "t"]) {
          if (scrollTop >= v[b + "a"] - screenH) {
            v[s + "o"].style.marginTop = (v[s + "m"] + d) + "px"
          } else {
            if (v[s + "i"].bottom - screenT < screenH) {
              v[s + "o"].style.marginTop = (v[s + "m"] + scrollTop - v[s + "t"] - (v[s + "h"] - screenH)) + "px"
            }
            if (v[s + "i"].top - screenT > 0) {
              v[s + "o"].style.marginTop = (v[s + "m"] + scrollTop - v[s + "t"]) + "px"
            }
          }
        } else {
          v[s + "o"].style.marginTop = v[s + "m"] + "px"
        }
      }
    })
  }
  addEvent(window, "load", LeftRight)
})();