
var tom = {
  VERSION: "3.1.1",
  COPYRIGHT: "www.tom.com",
  AUTHOR: "wudi msn:woodlessr@hotmail.com blog:http://blog.tom.com/woodless;",
  fnEmpty: function() {},
  fnTrue: function() { return true; },
  fnFalse: function() { return false; },
  fnEventStop: function(e) { tom.Event.stop(e||window.event); return false; }
};

tom.Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
};
if (typeof($) == 'undefined') {
  Class = tom.Class;
}

if (typeof($) == 'undefined') {
  $ = function(elem) {
    if (arguments.length > 1) {
      for (var i = 0, elems = [], length = arguments.length; i < length; i++)
        elems.push($(arguments[i]));
      return elems;
    }
    if (typeof elem == 'string') {
      return document.getElementById(elem);
    } else {
      return elem;
    }
  };
}
/*
 * 将类数组对象转换成Array对象
 */
if (typeof($A) == 'undefined') {
  $A = function(a) {
    var results = [];
    for (var i = 0, length = a.length; i < length; i++) {
      results.push(a[i]);
    }
    return results;
  };
}
/**
 * 从倒数第一个参数开始逐步将属性复制到前一个参数，参数数目必须大于1
 */
tom.extend = function(dist) {
  for (var i = 1; i < arguments.length; i++) {
    var src = arguments[i];
    for (var p in src) {
      dist[p] = src[p];
    }
  }
  return dist;
}/**
 * package tom.util
 */
tom.util = {};
/*
 * class tom.util.List
 */

tom.Event = {
  addEvent: function(elem, name, fn, useCapture) {
    if (elem.addEventListener) {
      elem.addEventListener(name, fn, useCapture);
    } else if (elem.attachEvent) {
      elem.attachEvent('on' + name, fn);
    }
  },
  removeEvent: function(elem, name, fn, useCapture) {
    if (elem.removeEventListener) {
      elem.removeEventListener(name, fn, useCapture);
    } else if (elem.detachEvent) {
      elem.detachEvent('on' + name, fn);
    }
  },
  pointer: function(e) {
    return {x: this.pointerX(e), y: this.pointerY(e)};
  },
  pointerX: function(e) {
    return e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
  },
  pointerY: function(e) {
    return e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
  },
  stop: function(e) {
    if (e.preventDefault) {
      e.preventDefault();
      e.stopPropagation();
    } else {
      e.returnValue = false;
      e.cancelBubble = true;
    }
  },
  isLeftClick: function(e) {
    return (((e.which) && (e.which == 1)) || ((e.button) && (e.button == 1)));
  }
};

//bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )


tom.Position = {
  pointer: function(e) {
    return {x: (e.pageX || e.clientX), y: (e.pageY || e.clientY)};
  },
  pointerX: function(e) {
    return e.clientX || (e.pageX - tom.Position.getWindowScrollLeft());
  },
  pointerY: function(e) {
    return e.clientY || (e.pageY - tom.Position.getWindowScrollTop());
  },
  prepare: function() {
    this.deltaX = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
    this.deltaY =  window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  },
  cumulativeOffset: function(elem, o) {
    var x = 0, y = 0;
    do {
      y += elem.offsetTop  || 0;
      x += elem.offsetLeft || 0;
      elem = elem.offsetParent;
    } while (elem);
    o = o || {};
    o.left = x;
    o.top = y;
    return o;
  },
  within: function(elem, x, y) {
    if (this.includeScrollOffsets)
      return this.withinIncludingScrolloffsets(elem, x, y);
    this.xcomp = x;
    this.ycomp = y;
    this.offset = this.cumulativeOffset(elem);
    return (y >= this.offset.top &&
            y <  this.offset.top + elem.offsetHeight &&
            x >= this.offset.left &&
            x <  this.offset.left + elem.offsetWidth);
  },
  withinVertical: function(elem, x) {
    this.offset = this.cumulativeOffset(elem);
    return (x >= this.offset.left && x < this.offset.left + elem.offsetWidth);
  },
  withinHorizontal: function(elem, y) {
    this.offset = this.cumulativeOffset(elem);
    return (y >= this.offset.top && y < this.offset.top + elem.offsetHeight);
  },
  withinIncludingScrolloffsets: function(elem, x, y) {
    var offsetcache = this.realOffset(elem);
    this.xcomp = x + offsetcache.left - this.deltaX;
    this.ycomp = y + offsetcache.top - this.deltaY;
    this.offset = this.cumulativeOffset(elem);
    return (this.ycomp >= this.offset.top &&
            this.ycomp <  this.offset.top + elem.offsetHeight &&
            this.xcomp >= this.offset.left &&
            this.xcomp <  this.offset.left + elem.offsetWidth);
  },
  bound: function(elem) {
  	var pos = this.cumulativeOffset(elem);
    return { x: pos.left, y: pos.top, w: elem.offsetWidth, h: elem.offsetHeight };
  },
  makeBound: function(el, bd) {
    this.cumulativeOffset(el, bd);
    bd.x = bd.left;
    bd.y = bd.top;
    bd.w = el.offsetWidth;
    bd.h = el.offsetHeight;
    return bd;
  },
  getWindowClientWidth: function() {
    return window.innerWidth 
        || document.documentElement.clientWidth
        || document.body.clientWidth
        || 0;
  },
  getWindowClientHeight: function() {
    return window.innerHeight 
        || document.documentElement.clientHeight
        || document.body.clientHeight
        || 0;
  },
  getWindowScrollWidth: function() {
    return window.scrollWidth 
        || document.documentElement.scrollWidth
        || document.body.scrollWidth;
  },
  getWindowScrollHeight: function() {
    return window.scrollHeight
        || document.documentElement.scrollHeight
        || document.body.scrollHeight;
  },
  getWindowScrollLeft: function() {
    if (window.scrollWidth) {
      return window.scrollLeft;
    } else if (document.documentElement.scrollWidth) {
      return document.documentElement.scrollLeft;
    } else if (document.body.scrollWidth) {
      return document.body.scrollLeft
    } else {
      return 0;
    }
  },
  getWindowScrollTop: function() {
    if (window.scrollWidth) {
      return window.scrollTop;
    } else if (document.documentElement.scrollWidth) {
      return document.documentElement.scrollTop;
    } else if (document.body.scrollWidth) {
      return document.body.scrollTop;
    } else {
      return 0;
    }
  }
};

