
// 要素の位置
function getPosition(elem) {
  var offsetTrail = elem;
  var offsetLeft = 0;
  var offsetTop = 0;
  while (offsetTrail) {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop += offsetTrail.offsetTop;
    offsetTrail = offsetTrail.offsetParent;
  }
  if (navigator.userAgent.indexOf('Mac') != -1 && 
    typeof document.body.leftMargin != 'undefined') {
    offsetLeft += document.body.leftMargin;
    offsetTop += document.body.topMargin;
  }
  return { top: offsetTop, bottom: offsetTop + elem.offsetHeight,
    left: offsetLeft, right: offsetLeft + elem.offsetWidth };
}

// Windowの横幅
function getInnerWidth(){
  // IE
  if (isIE()) {
    return document.body.clientWidth;
  }
  // NN4, NS6/Mozilla, Opera6
  else if (document.layers !== void 0 || navigator.userAgent.indexOf('Gecko') != -1
      || (navigator.userAgent.indexOf('Opera') != -1 || window.opera !== void 0)) {
    return window.innerWidth;
  }
  // Other
  else {
    return 0;
  }
}
// Windowの縦幅
function getInnerHeight(){
  // IE
  if (isIE()) {
    return document.body.clientHeight;
  }
  // NN4, NS6/Mozilla, Opera6
  else if (document.layers !== void 0 || navigator.userAgent.indexOf('Gecko') != -1
      || (navigator.userAgent.indexOf('Opera') != -1 || window.opera !== void 0)) {
    return window.innerHeight;
  }
  // Other
  else {
    return 0;
  }
}
