String.prototype.toCamel = function(){
	var s = this.replace(/( |\-)([a-z])/g, function($2){return $2.toUpperCase();});
	return s.charAt(0).toUpperCase() + s.substr(1);
};

$ = function(e){return document.getElementById(e);};

Events = {
	o: function(o) {return (o.obj)?o.obj:o;},
	add: function(){}, 
	remove:function(){},
	cancel:function(){},
	target:function(){}
}; 

if(window.addEventListener){
	Events.add = function(ob, type, fn, bub ) {this.o(ob).addEventListener(type, fn, bub );}; 
	Events.remove = function(ob, type, fn, bub ) {this.o(ob).removeEventListener(type, fn, bub );};
	Events.cancel = function(e){if(e.preventDefault) e.preventDefault(); if(e.stopPropagation) e.stopPropagation();};
	Events.target = function(e){return e.target;};
} else if (document.attachEvent) {
	Events.add = function(ob, type, fn, bub ) {
		var eProp = type + fn; 
		var o = this.o(ob);
		o['e'+eProp] = fn;
		o[eProp] = function(){o['e'+eProp](window.event);}
		o.attachEvent( 'on'+type, o[eProp]);
	}; 
	Events.remove = function(ob, type, fn, bub ) {
		var eProp = type + fn; 
		var o = this.o(ob); 
		o.detachEvent( 'on'+type, o[eProp]); 
		o[eProp] = null; 
		o["e"+eProp] = null;
	};
	Events.cancel = function(e){if(!e) e = window.event; e.returnValue = false;};
	Events.target = function(e){if(!e) e = window.event; return e.srcElement;};
}

Ajax = {
	load:function(url, success, failure, js){
		var client = new XMLHttpRequest();
		client.onreadystatechange = function(){
			if(this.readyState == 4 && this.status == 200) {
				var data = this.responseText;
				if(js){
					if(JSON != undefined){
						data = JSON.parse(data);
					}else{
						data = eval('(' + data + ')');
					}
				}
				success(data);	
			} else if (this.readyState == 4 && this.status != 200) {
				failure(null);
			}
		};
		client.open("GET", url);
		client.send();
	}
};

Host = {
	isFirefox:navigator.userAgent.indexOf('Firefox') != -1,
	isChrome:navigator.userAgent.indexOf('Chrome') != -1,
	isOpera:navigator.userAgent.indexOf('Opera') != -1,
	isIE8:window.addEventListener == undefined,
	isTouch:("createTouch" in document)
}

URL = {
	baseTitle:'',
	basePath:location.href.substring(0, location.href.indexOf('/', 14)) + '/',
	ignoreLocationChange:false,
	hashFallback:false,
	setState:function(path, title){
		
		if(location.href == path) return;
		
		if(path.indexOf('http:') != -1) path = path.substr(this.basePath.length);
		
		document.title = this.baseTitle + (title == '' ? '' : ' - ' + title);
		
		if(typeof window.history.pushState !== 'undefined'){
			window.history.pushState({title:title}, title, this.basePath + path);
		}else{
			if(!this.hashFallback){
				Events.add(window, 'hashchange', this.hashchangeHandler, false);
				this.hashFallback = true;
			}
			this.ignoreLocationChange = true;
			self.location.href = '/#/' + path;
		}
	},
	getState:function(){
		var s = location.href;
		s = s.split(this.basePath).join('');
		s = s.split('#/').join('');
		return s;
	},
	getComponents:function(){
		var hash = this.getState().split('/');
		hash.pop();
		return hash;
	},
	hashchangeHandler:function(e){
		
	}
};

function fixInputPlaceHolders(){
	var inputs = document.getElementsByTagName('input');
	for(var i = 0; i < inputs.length; i++){
		if(inputs[i].placeHolder != undefined){	
			inputs[i]._placeHolder = inputs[i].placeHolder;
			inputs[i].value = inputs[i].placeHolder;
			inputs[i].onfocus = function(e){
				if(this.value == this._placeHolder){
					this.value = '';
				}
			};
			inputs[i].onblur = function(e){
				if(this.value == ''){
					this.value = this._placeHolder;
				}
			};
		}
	}
}

function Stage(){}

/* CLASS POINT */

function Point(a, b) {
    this.x = (a != null && !isNaN(a)) ? a: 0;
    this.y = (b != null && !isNaN(b)) ? b: 0;
}
Point.fromEvent = function(a) {
    var a = (a.touches && a.touches.length > 0) ? a.touches[0] : a;
    return new Point(a.pageX, a.pageY);
};

Point.fromEventInElement = function(b, a) {
    var b = (b.touches && b.touches.length > 0) ? b.touches[0] : b;
    return window.webkitConvertPointFromPageToNode(a, new WebKitPoint(b.pageX, b.pageY))
};

Point.prototype.toString = function() {
    return "Point(" + this.x + "," + this.y + ")";
};

Point.prototype.copy = function() {
    return new Point(this.x, this.y);
};

Point.prototype.equals = function(a) {
    return (this.x == a.x && this.y == a.y);
};

/* ScrollPane */
function delegate(a, b){
	if(arguments.length > 2){
		var p = [];
		for(var n = 2; n < arguments.length; ++n) p.push(arguments[n]);
		return function() { return b.apply(a,p); }
	}else{
		return function() { return b.call(a); }
	}
}

function ScrollPane(holder, pane)
{
	this.layer = holder;
	this.content = null;
	this.offset = 0;
	
	this.scrollbar = new ScrollBar();
	this.scrollbar.delegate = this;
	this.layer.appendChild(this.scrollbar.layer);
	
	this.setContent(pane);
	
	Events.add(window, 'resize', delegate(this, this.layout));
	Events.add(this.layer, 'mousewheel', delegate(this, this.mouseWheel));
	
	if(Host.isFirefox) Events.add(this.layer, 'DOMMouseScroll', this);
	if(Host.isTouch){
		this.pane.style.webkitTransform = 'translate3D(0,0,0)';
		this.pane.addEventListener('webkitTransitionEnd', this, false);
		this._contentOffset = new Point(0, 0);
		this.contentSize = {width:this.pane.scrollWidth, height:this.pane.scrollHeight};
		this.maxPoint = new Point(0, 0);
		this.layer.addEventListener('touchstart', this, false);
	}
}

ScrollPane.prototype.setContent = function(div){
	this.pane = div;
	this.content = this.pane.childNodes[0];
	
	for(var i = 0; i < this.pane.childNodes.length; i++){
		if(this.pane.childNodes[i].nodeType == 1){
			this.content = this.pane.childNodes[i];
			break;
		}
	}
		
	this.measuredHeight = this.content.scrollHeight;
	this.layout();
	this.scrollbar.setScrollPosition(0);
}

ScrollPane.prototype.layout = function()
{
	var w = this.layer.offsetWidth;
	var h = this.layer.offsetHeight;
	
	this.width = w;
	this.height = h;
	
	this.content.style.height = 'auto';
	
	this.measuredHeight = this.content.scrollHeight;
	
	this.scrollbar.setPosition( w - 10, this.offset + 3 );
	this.scrollbar.setHeight(h - this.offset - 6);
	this.scrollbar.setScrollProperties(h, 0, this.measuredHeight+this.offset-h, 12);
	
	if(Host.isTouch){
		this.contentSize = {width:this.content.scrollWidth, height:this.measuredHeight + this.offset};
		this.maxPoint = new Point(0, h - this.contentSize.height);
		//this.updateVerticalScrollIndicator();
	}
	
	if(this.measuredHeight < h && this.content.nodeName != 'TABLE'){
		this.content.style.height = h + 'px';
		this.scrollbar.setScrollPosition(0);
	}
}

ScrollPane.prototype.handleEvent = function(e){
	switch(e.type){
		case 'DOMMouseScroll':
			this.mouseWheel(e);
		break;
		case 'touchstart':
	        this.touchesBegan(e);
		break;
	    case 'touchmove':
	        this.touchesMoved(e);
	    break;
	    case 'touchend':
	        this.touchesEnded(e);
	    break;
	    case 'touchcancel':
	        this.touchesCancelled(e);
	    break;
		case 'webkitTransitionEnd':
			if(e.target == this.pane){
				clearInterval(this.timer);
				this.wheeling = false;
				this.scrollbar.setVisible(false);
			}
		break;
	}
}

ScrollPane.prototype.mouseWheel = function(e){
	var delta = 0;
	if(!e) e = window.event;
	if(e.wheelDelta){
		if(navigator.userAgent.indexOf('Chrome') != -1){
			delta = e.wheelDelta / 2;
		}else if(navigator.userAgent.toLowerCase().indexOf('safari') != -1){
				delta = e.wheelDelta / 3;
		}else{
				delta = e.wheelDelta / 3;
		}

	}else if(e.detail){
		delta = -e.detail * 4;
	}
	this.scrollbar.setScrollPosition( this.scrollbar.scrollPosition - delta );
	Events.cancel(e);
}

ScrollPane.prototype.handleScroll = function(p){
	this.pane.style.top = -p + 'px';
}

ScrollPane.prototype.touchesBegan = function(a){
    if (a.eventPhase == Event.CAPTURING_PHASE) {
        if (a._manufactured) {
            return;
        }
        if (this.delaysContentTouches) {
            a.stopPropagation();
            if (!this.tracking) {
                this.beginTracking(a);
            }
        }
    } else {
        if (!this.tracking) {
            this.beginTracking(a);
        }
    }
};

ScrollPane.prototype.beginTracking = function(evt)
{
	
	clearInterval(this.timer);
	
	this.pane.style.webkitTransitionDuration = '0';
	
	var theTransform = window.getComputedStyle(this.pane).webkitTransform;
	theTransform = new WebKitCSSMatrix(theTransform);

	this._contentOffset.x = Math.round(theTransform.m41);
	this._contentOffset.y = Math.round(theTransform.m42);
   
	this.pane.style.webkitTransform = 'translate3d(' + this._contentOffset.x + 'px, ' + this._contentOffset.y + 'px, 0)';

	this.startContentOffset = this._contentOffset.copy();
	this.startTouchPosition = Point.fromEventInElement(evt, this.layer);
	
	var p = Point.fromEvent(evt);
	
	this.startTrackerPosition = {time:evt.timeStamp, x:p.x, y:p.y};
	this.endTrackerPosition = {time:evt.timeStamp, x:p.x, y:p.y};
	
	this.tracking = true;
	this.dragging = false;
	this.touchesHaveMoved = false;
	
	if(this.wheeling) evt.stopPropagation();
	
	window.addEventListener('touchmove', this, true);
	window.addEventListener('touchend', this, true);
	window.addEventListener('touchend', this, false);
 	window.addEventListener('touchcancel', this, true);
};

ScrollPane.prototype.touchesMoved = function(evt)
{
	
	evt.preventDefault();
	
	var p = Point.fromEventInElement(evt, this.layer);

	var nx = this.startTouchPosition.x - p.x;
	var ny = this.startTouchPosition.y - p.y;

	if(!this.dragging){
		if(Stage.draggingObject){
			this.tracking = false;
			this.touchesCancelled(null);
			return;
		}
		if(Math.abs(ny) > 3 && Math.abs(ny) > Math.abs(nx)){
			this.dragging = true;
			this.firstDrag = true;
			this.touchesHaveMoved = true;
			Stage.draggingObject = this;
		}
	}

	if (this.dragging) {
		evt.stopPropagation();

		if (this.firstDrag) {
			this.firstDrag = false;
			nx = 0;
			ny = 0;
			this.startTouchPosition = p;
			this.scrollbar.setVisible(true);
		}

		nx = this.startContentOffset.x - nx;
		ny = this.startContentOffset.y - ny;
		
		nx = 0;
		
		var max = this.height - this.contentSize.height;
		
		if(max < 0){
			if(ny > 0) ny = ny/3;
			if(ny < max) ny = max + (ny-max)/3;
		}else{
			ny = ny/3;
		}

		this._contentOffset.x = nx;
		this._contentOffset.y = ny;

		this.pane.style.webkitTransform = 'translate3d(' + nx + 'px, ' + ny + 'px, 0)';
		this.updateVerticalScrollIndicator();
	}

	this.endTrackerPosition = {time:this.startTrackerPosition.time, x:this.startTrackerPosition.x, y:this.startTrackerPosition.y};
	var p = Point.fromEvent(evt);
	this.startTrackerPosition = {time:evt.timeStamp, x:p.x, y:p.y};
	
	return false;
};

ScrollPane.prototype.touchesEnded = function(a)
{
	window.removeEventListener('touchmove', this, true);
    window.removeEventListener('touchend', this, true);
    window.removeEventListener('touchcancel', this, true);
	
	this.tracking = false;
	
	var transitionTimingFunction = 'cubic-bezier(0, 0, 0.2, 1)';
	var decelerationTime = 450;

	var nx, ny;
	
	if (this.dragging) {
		this.dragging = false;
		Stage.draggingObject = null;
		a.stopPropagation();
		
		var p = new Point(this.startTrackerPosition.x - this.endTrackerPosition.x, this.startTrackerPosition.y - this.endTrackerPosition.y);
		var c = (this.endTrackerPosition.time - this.startTrackerPosition.time);
		this.initialVelocity = new Point(p.x / c, p.y / c);
		
		var max = this.height - this.contentSize.height;
		var bounds = false;
		if(max > 0){
			bounds = true;
			max = 0;
		}
		
		if(this._contentOffset.y > 0 || this._contentOffset.y < max){
			bounds = true;
		}

		if(bounds){
			this._contentOffset.y = this._contentOffset.y > 0 ? 0 : max;
			var decelerationTime = 350;
			var transitionTimingFunction = 'cubic-bezier(0, 0, 0.15, 1)';
			var nx = Math.round(this._contentOffset.x);
			var ny = Math.round(this._contentOffset.y);

			nx = 0;

			this.pane.style.webkitTransitionTimingFunction = transitionTimingFunction;
			this.pane.style.webkitTransitionDuration = Math.round(decelerationTime) + 'ms';
			this.pane.style.webkitTransform = 'translate3d(' + nx + 'px, ' + ny + 'px, 0)';
			
			this.timer = setInterval(delegate(this, this.updateScrollFromTransition), 1000/30);
			
			this.wheeling = true;
			
		}else if(Math.abs(this.initialVelocity.y) > 0.1){
			var that = this;
			var f = function(){
				that.render();
			}
			if(Math.abs(this.initialVelocity.y) < 1) this.initialVelocity.y = this.initialVelocity.y < 0 ? -1 : 1;
			this.initialVelocity.y *= 10;
			this.timer = setInterval(f, 1000/60);
			
			this.wheeling = true;
			
		}else{
			a.stopPropagation();
			this.scrollbar.setVisible(false);
		}
		window.removeEventListener('touchend', this, false);
	}else{
		if(this.wheeling){
			a.stopPropagation();
			this.wheeling = false;
			this.scrollbar.setVisible(false);
		}
	}
};

ScrollPane.prototype.render = function(){
	
	if(this.initialVelocity.y < 0){
		this.initialVelocity.y += 0.16;
	}else{
		this.initialVelocity.y -= 0.16;
	}
	
	var max = this.height - this.contentSize.height;
	if(this._contentOffset.y > 10 || this._contentOffset.y < max - 10){
		clearInterval(this.timer);
		this._contentOffset.y = this._contentOffset.y > 0 ? 0 : max;
		var decelerationTime = 350;
		var transitionTimingFunction = 'ease-in-out';
		var nx = Math.round(this._contentOffset.x);
		var ny = Math.round(this._contentOffset.y);

		nx = 0;

		this.pane.style.webkitTransitionTimingFunction = transitionTimingFunction;
		this.pane.style.webkitTransitionDuration = Math.round(decelerationTime) + 'ms';
		this.pane.style.webkitTransform = 'translate3d(' + nx + 'px, ' + ny + 'px, 0)';
		
		this.timer = setInterval(delegate(this, this.updateScrollFromTransition), 1000/30);
		return;
	}
	
	var ny = this._contentOffset.y - this.initialVelocity.y;
	
	this._contentOffset.y = ny;
	
	this.pane.style.webkitTransform = 'translate3d(0px, ' + ny + 'px, 0)';
	
	this.updateVerticalScrollIndicator();
	
	if(Math.abs(this.initialVelocity.y) < 0.5){
		this.scrollbar.setVisible(false);
		this.wheeling = false;
		clearInterval(this.timer);
	}
};

ScrollPane.prototype.updateScrollFromTransition = function()
{
	var theTransform = window.getComputedStyle(this.pane).webkitTransform;
	theTransform = new WebKitCSSMatrix(theTransform);

	this._contentOffset.y = Math.round(theTransform.m42);
	this.updateVerticalScrollIndicator();
};

ScrollPane.prototype.updateVerticalScrollIndicator = function()
{
	var c = 3;
	var d = this.height - 6 - c;
	var e = Math.max(this.scrollbar.thickness, Math.round((this.height / this.contentSize.height) * d));
 
	var b = (this._contentOffset.y / (this.contentSize.height - this.height)) * (d - c - e) - 3;
	
	if(this._contentOffset.y > 0){
		e = Math.round(Math.max(e - this._contentOffset.y, this.scrollbar.thickness));
		b = -3;
	}else{
		if (this._contentOffset.y < this.maxPoint.y) {
			e = Math.round(Math.max(e + this.contentSize.height - this.height + this._contentOffset.y, this.scrollbar.thickness));
			b = -this.height + e + c;
      }
	}
	this.scrollbar.setTouchPosition(0, b);
	this.scrollbar.setTouchHeight( e );
};

function ScrollBar(){
	this.layer = document.createElement('div');
	this.layer.className = 'scrollIndicator';
	this.scrollPosition = 0;
	this.controlSize = 1;
	this.minSize = 50;
	this.isScrolling = false;
	this.thumbY = 0;
	this.callback = null;
	this.w = 7;
	this.h = 585;
	
	this.thickness = 7;
	
	this.track = document.createElement('div');
	this.track.className = 'track';
	this.layer.appendChild(this.track);
	
	this.thumb = document.createElement('div');
	this.thumb.className = 'thumb';
	this.thumb.style.top = '0px';
	this.layer.appendChild(this.thumb);
	
	if(window.addEventListener){
		Events.add(this.thumb, 'mousedown', this);
	}
	
	if(Host.isTouch){
		this.track.style.display = 'none';
	}
}

ScrollBar.prototype.setTouchHeight = function(a){
	this.thumb.style.height = a + 'px';
	this.height = a;
}

ScrollBar.prototype.setTouchPosition = function(x, y){
	this.x = Math.round(x);
	this.y = Math.round(y);
	this.thumb.style.webkitTransform = "translate3d(" + this.x + "px," + -this.y +"px, 0)";
}

ScrollBar.prototype.setVisible = function(a) {
	this._visible = a;
	this.layer.style.opacity = this._visible ? 1 : 0;
};

ScrollBar.prototype.setHeight = function(nh)
{
	this.h = nh;
}

ScrollBar.prototype.setPosition = function(x, y)
{
	this.layer.style.left 	= x + 'px';
	this.layer.style.top 	= y + 'px';
}

ScrollBar.prototype.setScrollPosition = function(value)
{
	if(Host.isTouch) return;
	if(isNaN(value)) value = 0;
	this.scrollPosition = value;
	if(!this.isScrolling){
		value = Math.min(value, this.maxPos);
		value = Math.max(value, this.minPos);
		this.scrollPosition = value;
		var d = ((value-this.minPos)*(this.h-this.thumbSize-this.controlSize*2)/(this.maxPos-this.minPos))+this.controlSize;
		if(isNaN(d)) d = 0;
		this.thumbY = d;
		this.thumb.style.top = this.thumbY + 'px';
		this.delegate.handleScroll(this.scrollPosition);
	}
}

ScrollBar.prototype.getScrollPosition = function()
{
	return this._scrollPosition;
}


ScrollBar.prototype.setScrollProperties = function(pageSize, mnPos, mxPos, ls){
	if(Host.isTouch) return;
	this.pageSize = pageSize;
	this.minPos = Math.max(mnPos, 0);
	this.maxPos = Math.max(mxPos, 0);
	
	this.scrollPosition = Math.max(this.minPos, this.scrollPosition);
	this.scrollPosition = Math.min(this.maxPos, this.scrollPosition);
	
	var enabled = (this.maxPos-this.minPos) > 0;
	
	if(enabled){
		var th = this.pageSize/(this.maxPos-this.minPos+this.pageSize)*(this.h-this.controlSize*2);
		if (th<this.minSize) {
			th = this.minSize;
		}
		
		th =  Math.round(th);
		
		this.thumb.style.height = th + 'px';
		this.thumbSize = th;
		
		
		this.ymin = this.controlSize;
		this.ymax = (this.h-this.thumbSize-this.controlSize);
		this.datamin = this.minPos;
		this.datamax = this.maxPos;

		var tmp = this.scrollPosition;
		tmp = Math.min(tmp, this.maxPos);
		this.setScrollPosition( Math.max(tmp, this.minPos) );
		
		this.track.style.height = this.h + 'px';
		this.layer.style.opacity = 1;
	}else{
		this.layer.style.opacity = 0;
	}
	
	if(Host.isIE8){
		this.layer.style.display = enabled ? 'block' : 'none';
	}
};

ScrollBar.prototype.handleEvent = function(e){
	
	Events.cancel(e);
	if(!e) e = window.event;
	switch(e.type){
		case 'mousedown':
			this.isScrolling = true;
			this.lastP = this.thumbY - e.clientY;
			Events.add(window, 'mousemove', this);
			Events.add(window, 'mouseup', this);
		break;
		case 'mousemove':
			var scrollMove = e.clientY + this.lastP;
			scrollMove = Math.min(scrollMove, this.ymax);
			scrollMove = Math.max(scrollMove, this.ymin);
			this.thumbY = scrollMove;
			this.thumb.style.top = this.thumbY + 'px';
			var pos = ((this.datamax-this.datamin)*(this.thumbY-this.ymin)/(this.ymax-this.ymin))+this.datamin;
			if (pos == this.scrollPosition) {
				return;
			}
			this.scrollPosition = pos;
			this.delegate.handleScroll(this.scrollPosition);
		break;
		case 'mouseup':
			this.isScrolling = false;
			Events.remove(window, 'mousemove', this);
			Events.remove(window, 'mouseup', this);
		break;
	}
}

/* Tween */

function Tween(target, duration, vars){
	
	if(!Tween.inited)
	{
		Tween._time = new Date().getTime() * 0.001;
		Tween._timer = setInterval(Tween.updateAll, 15);
		Tween.masterList = [];
		Tween.reservedProps = {ease:1, delay:1, overwrite:1, onComplete:1, onCompleteParams:1};
		Tween.inited = true;
	}
	
	this.vars = vars;
	this.duration = duration;
	this.active = (duration == 0 && this.vars.delay == 0);
	this.target = target;
	this.ease = vars.ease == 'out' ? Tween.easeOut : Tween.easeInOut;
	this.propTweens = [];
	this.inited = false;
	
	var delay = ("delay" in this.vars) ? this.vars.delay : 0;
	this.startTime = Tween._time + delay;
	
	var a = Tween.masterList[target];
	
	if(a == null || this.vars.overwrite == true){
		Tween.masterList[target] = [this];
	}else{
		a[a.length] = this;
	}
	
	if(this.active) renderTime(0);

}

Tween.prototype.init = function(){
	var num;
	for(var p in this.vars){
		if(Tween.reservedProps[p] != 1){
			num = parseInt(this.target.style[p]);
			if(isNaN(num)) num = 1;
			this.propTweens[ this.propTweens.length ] = [p, num, (typeof(this.vars[p]) == "number") ? this.vars[p] - num : this.vars[p]]; //[property, start, change]
		}
	}
	this.inited = true;
};

Tween.prototype.renderTime = function(time){
	if(!this.inited) this.init();
	
	var pt, i = this.propTweens.length;
	
	if(time >= this.duration){
		time = this.duration;
		this.ratio = 1;
	}else if(time <= 0){
		this.ratio = 0;
	}else{
		this.ratio = this.ease(time, 0, 1, this.duration);
	}
	
	while(--i > -1){
		pt = this.propTweens[i];
		switch(pt[0]){
			case 'left':
			case 'top':
			case 'right':
			case 'bottom':
			case 'width':
			case 'height':
				this.target.style[pt[0]] = (pt[1] + (this.ratio * pt[2])) + 'px';
			break;
			case 'alpha':
				this.target.filter = "alpha(opacity=" + (pt[1] + (this.ratio * pt[2]))*100 + ")";
			break;
			default:
				this.target.style[pt[0]] = pt[1] + (this.ratio * pt[2]);
			break;
		}
		
	}
	
	if(time == this.duration) this.complete(true);
};

Tween.prototype.complete = function(){
	this.kill();
	if(this.vars.onComplete) this.vars.onComplete.apply(null, this.vars.onCompleteParams);
};

Tween.prototype.kill = function(){
	this.gc = true;
	this.active = false;
};

Tween.to = function(target, duration, vars){
	return new Tween(target, duration, vars);
};

Tween.set = function(target, vars){
	var t = new Tween(target, 0, vars);
	t.renderTime(0);
	t = null;
};

Tween.updateAll = function(){
	Tween._time = new Date().getTime() * 0.001;
	
	var ml = Tween.masterList;
	var a, tgt, i, y, tween;
	
	for(tgt in ml){
		a = ml[tgt];
		i = a.length;
		while(--i > -1){
			tween = a[i];
			t = Tween._time;
			if(tween.active || (!tween.gc && t >= tween.startTime)){
				tween.renderTime(t - tween.startTime);
			}else if(tween.gc){
				a.splice(i, 1);
			}
		}
		
		if(a.length == 0){
			delete ml[tgt];
			for(i in Tween.masterList){
				return;
			}
			clearInterval(Tween._timer);
			Tween.inited = false;
		}
	}
	
};

Tween.kill = function(target){
	if(Tween.masterList[target]){
		delete Tween.masterList[target];
	}
}

Tween.easeOut = function(t, b, c, d){
	return -1 * (t /= d) * (t - 2);
};

Tween.easeInOut = function(t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
};
