/* PROTOTYPES */
function hex2rgb(h) {
	function _cutHex(h) {
		return (h.charAt(0)=="#") ? h.substring(1,7) : h
	}
	return [
		parseInt((_cutHex(h)).substring(0,2),16),
		parseInt((_cutHex(h)).substring(2,4),16),
		parseInt((_cutHex(h)).substring(4,6),16)
	];
}
function rgb2hex(rgb) {
	function _toHex(N) {
		if (N==null) return "00";
		N=parseInt(N);
		if (N==0 || isNaN(N)) return "00";
		N=Math.max(0,N);
		N=Math.min(N,255);
		N=Math.round(N);
		return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
	}
	return _toHex(rgb[0]) + _toHex(rgb[1]) + _toHex(rgb[2]);
}

function Mouse(ev) {
	this.body = $$('body').first();
	if (ev) this._getPosition(ev);
	this.body.observe('mousemove', (function(ev) {
		this._getPosition(ev);
	}).bind(this));
}
Mouse.prototype._getPosition = function(ev) {
	this._x		= Event.pointerX(ev);
	this._y		= Event.pointerY(ev);
}

function FX() {
	this.options	= new Object({
		fps:		30,		// Frames per Second
		inertia:	70,		// Inertia in Percent
		duration:	1,
		delay:		0
	});
}
FX.prototype._setup = function(el, as) {
	var args = as || [];
	for (a in args)
		this.options[a] = args[a];
	this.element = (typeof el == "string") ? document.getElementById(el) : el;
}
FX.prototype._run = function(cb) {
	var loop = 0;
	var total = Options.animation.fps * Options.animation.duration;
	this.animations.over = window.setInterval((function() {
		if (loop < total) {
			loop++;
			var faktor = (i * 100) / total;
			cb;
			this.innerHTML	= this.test + "<br \/>"
							+ loop + " von " + total
							+ " (" + faktor + "%)<br \/>";
		} else window.clearInterval(this.animations.over);
	}).bind(this), 1000 / Options.animation.fps);
}
FX.prototype._cleanup = function() {
	window.clearInterval(this.interval);
}

FX.colorTo = function(el, tc, args) {
	this._setup(el, args);

	this.element.parent		= this;
	this.options.color		= (typeof tc == "array") ? tc : hex2rgb(tc);
	this.element._callback	= function() {
		this.parent;
	}

	this._run(this.element._callback);
	this.cleanup();
}
FX.colorTo.prototype = new FX();
FX.colorTo.prototype.constructor = FX.colorTo;
FX.colorTo.prototype.parent = FX.prototype;

String.prototype.hex2rgb = function() { return hex2rgb(this); }
Array.prototype.rgb2hex = function() { return rgb2hex(this); }