function getElementsByClassName(classname, node)  {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
			if(re.test(els[i].className))a.push(els[i]);
	return a;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/**
  * @constructor Animate
  * @param {HTMLElement} el the element we want to animate
  * @param {String} prop the CSS property we will be animating
  * @param {Object} opts a configuration object
  * object properties include
  * from {Int}
  * to {Int}
  * time {Int} time in milliseconds
  * callback {Function}
  */
function Animate(el, prop, opts) {
  this.el = el;
  this.prop = prop;
  this.from = opts.from;
  this.to = opts.to;
  this.time = opts.time;
  this.callback = opts.callback;
  this.animDiff = this.to - this.from;
}

/**
  * @private
  * @param {String} val the CSS value we will set on the property
  */
Animate.prototype._setStyle = function(val) {
  switch (this.prop) {
    case 'opacity':
      this.el.style[this.prop] = val;
      this.el.style.filter = 'alpha(opacity=' + val * 100 + ')';
      break;

    default:
      this.el.style[this.prop] = val + 'px';
      break;
  };
};

/**
  * @private
  * this is the tweening function
  */
Animate.prototype._animate = function() {
  var that = this;
  this.now = new Date();
  this.diff = this.now - this.startTime;

  if (this.diff > this.time) {
    this._setStyle(this.to);

    if (this.callback) {
      this.callback.call(this);
    }
    clearInterval(this.timer);
    return;
  }
  this.percentage = (Math.floor((this.diff / this.time) * 100) / 100);
  this.val = (this.animDiff * this.percentage) + this.from;
  this._setStyle(this.val);
};

/**
  * @public
  * begins the animation
  */
Animate.prototype.start = function() {
  var that = this;
  this.startTime = new Date();
  this.timer = setInterval(function() {
    that._animate.call(that);
  }, 4);
};
