/**
 * @projectDescription	DOM, Animations, Ajax and more Framework Library
 * @author	Sandro Lain
 * @version	1.9b
 */
var AIDA_JS = {
	version: 1.9,
	updated: 20080213
};

// Creatore di classi
var Class = function(p){
	var i, c = function(){
		var k = this.__construct, a = arguments;
		if (k && a[0] != '__extend')
			return k.apply(this, a);
		return this;
	};
	/*for (i in this)
		c[i] = this[i];*/
	
	c.extend = function(p){
		var t = new this('__extend'), a, b, i, z = function(a, b){
			if (!a.apply || !b.apply) 
				return false;
			return function(){
				this.parent = a;
				return b.apply(this, arguments);
			};
		};
		for (i in p) {
			a = t[i];
			b = p[i];
			if (a && a != b) 
				b = z(a, b) || b;
			t[i] = b;
		}
		return new Class(t);
	};
	c.implement = function(o){
		var i, p = this.prototype;
		for (i in o) 
			p[i] = o[i];
	};
	
	c.prototype = p;
	return c;
};


// Classe per il controllo dell'User Agent
var Agent = Class({
	value: '',
	__construct: function(o) {
		this.set(o);
	},
	set: function(o) {
		var u, t;
		if(o) {
			t = typeof o;
			if(t == 'string')
				u = o;
			else if(t == 'object' && o.value)
				u = o.value;
		}
		this.value = u || navigator.userAgent;
	},
	isMSIE: function(v){
		return (document.all && (v = this.value.match((new RegExp('(MSIE) (' + (v || '[0-9\.]+') + ')', 'i'))))) ? parseFloat(v[2], 10) : false;
	},
	isGecko: function(){
		var u = this.value;
		return (/Gecko/.test(u) && !(/Konqueror|Safari|KHTML/.test(u)));
	},
	isSafari: function(){
		return (/Safari/.test(this.value));
	},
	isKonqueror: function(){
		return (/Konqueror/.test(this.value));
	},
	isWebKit: function(){
		return (/WebKit/.test(this.value));
	},
	isNetscape: function(v){
		return ((v = (this.value).match((new RegExp('(Netscape|NS)[0-9]*[ /]{0,1}(' + (v || '[0-9\.]+') + ')', 'i'))))) ? parseFloat(v[2], 10) : false;
	},
	isFirefox: function(v){
		return ((v = (this.value).match((new RegExp('(Firefox|Minefield)/(' + (v || '[0-9\.]+') + ')', 'i'))))) ? parseFloat(v[2], 10) : false;
	},
	isOpera: function(v){
		return (window.opera && (v = (this.value).match((new RegExp('(Opera)[ \/](' + (v || '[0-9\.]+') + ')', 'i'))))) ? parseFloat(v[2], 10) : false;
	}
});


// Oggetto Element
var Element = {
	prototypize: function(e){
		if (!e || e._extended || e.nodeType != 1)
			return e;
		e._extended = true;
		//Element._extended.push(e);
		return Element.extend(e, Element._extensions);
	},
	extend: function(e, m, o){
		for (var i in m)
			if (!e[i] || o)
				e[i] = m[i];
		return e;
	},
	_extensions: {},
	implement: function(o){
		if (typeof o != 'object')
			throw new TypeError('Passed argument must be an object!');
		var i, m = Element._extensions, p = HTMLElement.prototype;
		for (i in o)
			p[i] = m[i] = o[i];
	},
	_extended: []
};


var GET = {};
var COOKIE = {};

// Inizializzatore del framework e prototipizzatore degli oggetti base
__init_FW = function() {
	var p = 'prototype',
		O = Object, Op = O[p],
		D = Date, Dp = D[p],
		S = String, Sp = S[p],
		Ap = Array[p],
		Np = Number[p],
		F = Function, Fp = F[p],
		M = Math,
		R = RegExp,
		ua = new Agent();

	Agent.MSIE = ua.isMSIE();
	Agent.Gecko = ua.isGecko();
	Agent.Safari = ua.isSafari();
	Agent.Konqueror = ua.isKonqueror();
	Agent.WebKit = ua.isWebKit();
	Agent.Opera = ua.isOpera();
	Agent.Firefox = ua.isFirefox();

	O.extend = function(e, o){
		e = e || {};
		o = o || {};
		for(var i in o)
			e[i] = o[i];
		return e;
	};

	D.now = function() {
		return new Date().getTime();
	};
	D.formats = {
		en: {
			m: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
			w: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
		},
		it: {
			m: ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
			w: ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato']
		},
		es: {
			m: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
			w: ['Lunes', 'Martes', 'MiÃˆrcoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo']
		},
		fr: {
			m: ['Janvier', 'FÃˆvrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'AoËšt', 'Septembre', 'Octobre', 'Novembre', 'DÃˆcembre'],
			w: ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
		}
	};

	Dp.format = function(f, l){
		var c = Date.formats, n = new Date(),
		y = n.getFullYear(), m = n.getMonth() + 1, d = n.getDate(), w = n.getDay(),
		h = n.getHours(), g = h % 12 || 12, i = n.getMinutes(), s = n.getSeconds(), a = g == h ? 'am' : 'pm',
		// Get the number of days in current month
		na = new Date(y, m - 1, 1), nb = new Date(y, m, 1), t = ((na.getTime() - nb.getTime()) / 86400000).round() + 1;

		l = c[(l || 'en').toLowerCase()] || c.en;

		f = f.replace('G', h).replace('g', g).replace('H', h.zeroFill(2)).replace('h', g.zeroFill(2));
		f = f.replace('i', i.zeroFill(2)).replace('s', s.zeroFill(2));
		f = f.replace('Y', y).replace('y', y.zeroFill(2, true)).replace('n', m).replace('m', m.zeroFill(2));
		f = f.replace('j', d).replace('w', w).replace('t', t);

		e = /(a|A|M|F|D|l)/g;
		if(f.match(e))
			f = f.replace(e, function(s, b){
				switch (b) {
					case 'a':
						return a;
					case 'A':
						return a.toUpperCase();
					case 'M':
						return l.m[m - 1].substr(0, 3);
					case 'F':
						return l.m[m - 1];
					case 'D':
						return l.w[w].substr(0, 3);
					case 'l':
						return l.w[w];
				}
				return b;
			});
		return f;
	};

	S.random = function(l, c){
		c = c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		for (var g = c.length, r = '', n, i = l || 8; i > 0; i--) {
			n = Math.floor(Math.random() * g);
			r += c.substring(n, n + 1);
		}
		return r;
	};
	
	S.randomId = function() {
		return 'aidajs_' . String.random();
	};

	Sp.cleanSize = function(a){
		var s = this, v = 0, u = '', e = s.match(/(-?[0-9\.]*)(in|cm|mm|pt|pc|em|ex|px|%)?/i);
		if (e) {
			v = parseFloat(e[1], 10);
			u = e[2];
			if (!v)
				v = 0;
			if (!u)
				u = '';
		}
		return a ? [v, u] : v;
	};
	
	// PHP Like	
	Sp.addSlashes = function() {
		return this.replace(/(\'|\"|\\|\0)/g, '\\$1');
	};
	Sp.stripSlashes = function() {
		return this.replace(/\\(\'|\"|\\|\0)/g, '$1');
	};
	Sp.htmlEntities = function () {
		return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
	};
	Sp.nl2br = function() {
		return this.replace(/[^>]\n/g, '<br/>');
	};
	Sp.stripTags = function() {
		return this.replace(/<[^>]+>/g, '');
	};
	// End PHP Like
	
	Sp.has = function(s) {
		return (this.indexOf(s) >= 0);
	};
	Sp.trim = function() {
		return this.replace(/^\s+|\s+$/g, '');
	};
	Sp.ltrim = function() {
		return this.replace(/^\s+/g, '');
	};
	Sp.rtrim = function() {
		return this.replace(/^\s+$/g, '');
	};
	Sp.clean = function() {
		return this.replace(/\s{2,}/g, ' ').trim();
	};
	Sp.empty = function(s) {
		return (this.length === 0 || (s && this.match(/^[\s]*$/gm))) ? true : false;
	};
	Sp.toInt = function(i) {
		return parseInt(this, i || 10);
	};
	Sp.toFloat = function(i) {
		return parseFloat(this, i || 10);
	};
	Sp.camelCase = function() {
		return this.replace(/-\D/g, function(m) { return m.charAt(1).toUpperCase(); });
	};
	Sp.hyphenate = function(){
		return this.replace(/\w[A-Z]/g, function(m){
			return (m.charAt(0) + '-' + m.charAt(1).toLowerCase());
		});
	};
	Sp.capitalize = function(){
		return this.toLowerCase().replace(/\b[a-z]/g, function(m){
			return m.toUpperCase();
		});
	};
	Sp.parseCss = function() {
		for(var s = this, p = s.split(';'), r = {}, i = p.length - 1, d, n; i >= 0; i--) {
			d = p[i].split(':');
			n = d[0].trim().camelize();
			if(n) r[n] = d[1].trim();
		}
		return r;
	};

	Sp.whiteSpaceChar = function(i) {
		return (this.charCodeAt(i || 0) <= 32);
	};
	Sp.digitChar = function(i) {
		return ((i = this.charCodeAt(i || 0)) && i >= 48  && i <= 57);
	};
	Sp.letterChar = function(i) {
		return ((i = this.charCodeAt(i || 0)) && ((i >= 65  && i <= 90) || (i >= 97 && i <= 122)));
	};
	Sp.upperCaseChar = function(i) {
		return ((i = this.charCodeAt(i || 0)) && i >= 65  && i <= 90);
	};
	Sp.lowerCaseChar = function(i) {
		return ((i = this.charCodeAt(i || 0)) && i >= 97 && i <= 122);
	};

	Sp.isJSON = function() {
		return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''));
	};
	Sp.compareVersion = function(b){
		b = (b + '').split('.');
		var a = this.split('.'), i, c, d, l = Math.min(a.length, b.length);
		for (i = 0; i < l; i++) {
			c = a[i].toInt();
			d = b[i].toInt();
			if (c > d) 
				return 1;
			if (c < d) 
				return -1;
		}
		return 0;
	};

	// Implementazioni dello standard
	if(!Ap.indexOf) {
		Ap.indexOf = function(v, b) {
			for(var i =+ b || 0, l = this.length; i < l; i++) if(this[i] === v) return i;
			return -1;
		};
	}
	// Nota: tolti i controlli rispetto allo standard
	if(!Ap.filter) {
		Ap.filter = function(f, t) {
			if(typeof f != "function") throw new TypeError();
			for(var a = this, l = a.length, r = [], i = 0, j = 0, o; i < l; i++) {
				o = a[i]; if(f.call(t, o, i, a)) r[j++] = o;
			}
			return r;
		};
	}
	if(!Ap.forEach) {
		Ap.forEach = function(f, t) {
			if(typeof f != "function")
				throw new TypeError();
			for(var i = 0, a = this, l = a.length; i < l; i++)
				f.call(t, a[i], i, a);
		};
	}
	Ap.each = Ap.forEach;
	if(!Ap.every) {
		Ap.every = function(f, t){
			for(var i = 0, a = this, l = a.length; i < l; i++) if(!f.call(t, a[i], i, a)) return false;
			return true;
		};
	}
	if(!Ap.map) {
		Ap.map = function(f, t) {
			if(typeof f != "function") throw new TypeError();
			for(var a = this, l = a.length, r = [], i = 0; i < l; i++) r = r.concat(f.call(t, a[i], i, a));
			return r;
		};
	}
	if(!Ap.some) {
		Ap.some = function(f, t){
			for(var i = 0, a = this, l = a.length; i < l; i++) if(f.call(t, a[i], i, a)) return true;
			return false;
		};
	}
	// Implementazioni personalizzate
	Ap.unique = function(b) {
		var a = [], i, l = this.length;
		for(i = 0; i < l; i++) if(a.indexOf(this[i], 0, b) < 0) a.push(this[i]);
		return a;
	};
	Ap.replace = function(f, p) {
		for(var r = [], i = this.length - 1; i >= 0 ; i--) r[i] = (this[i] === f) ? p : this[i];
		return r;
	};
	Ap.intersect = function(a) {
		var r = [], b = this, k = b.length, i, j = 0, c;
		for(i = 0; i < k; i++) {
			c = b[i];
			if(a.indexOf(c) >= 0) r[j++] = c;
		}
		return r;
	};
	Ap.remove = function(a) {
		var i = 0;
		while(i < this.length) if(this[i] === a) this.splice(i, 1); else i++;
		return this;
	};
	Ap.copy = function(s, l){
		var h = this.length, i, r = [];
		if (!s)
			s = 0;
		if (s < 0)
			s = h + s;
		if (!l)
			l = h - s;
		for (i = 0; i < l; i++)
			r[i] = this[s++];
		return r;
	};
	Ap.exists = function(i, s) {
		return this.indexOf(i, s) != -1;
	};
	Ap.has = Ap.exists;
	Ap.clean = function() {
		for(var a = this, r =[], j = 0, i = 0, l = a.length, e; i < l; i++) {
			e = a[i];
			if(e || e === 0) r[j++] = e;
		}
		return r;
	};
	Ap.nearest = function(o) {
		if(typeof o != 'number') return null;
		for(var a = this, r = null, e, d = null, n, i = a.length - 1; i >= 0; i--) {
			e = a[i];
			n = Math.abs(e - o);
			if(d === null || n < d) {
				d = n;
				r = e;
			}
		}
		return d;
	};
	Ap.randomize = function() {
		return this.copy().sort(Sort.random);
	};
	Ap.random = function() {
		return this[Math.floor(Math.random() * this.length)];
	};

	// ### Number prototypes
	Np.bound = function(n, m) {
		return this < n ? n : (this > m ? m : this);
	};
	Np.round = function(p) {
		p = Math.pow(10, p || 0);
		return Math.round(this * p) / p;
	};
	Np.ceil = function() {
		return Math.ceil(this);
	};
	Np.floor = function() {
		return Math.floor(this);
	};
	Np.pow = function(e) {
		return Math.pow(this, e);
	};
	Np.toInt = function(i) {
		return parseInt(this, i || 10);
	};
	Np.toFloat = function(i) {
		return parseFloat(this, i || 10);
	};
	Np.zeroFill = function(z, m){
		var i, r = '', n = this, l;
		n = parseInt(n, 10) + '';
		l = n.length;
		if (m && l > z)
			return n.substr(l - z, z);
		l = z - l;
		for (i = 0; i < l; i++)
			r += '0';
		return r + '' + n;
	};

	// Function Prototypes
	F.get = function(f) {
		var t = typeof f;
		if(t == 'function') return f;
		if(t == 'string') return new Function(f);
		return null;
	};
	F.empty = function(){};
	F.value = function(f){
		return (typeof f === 'function') ? f : function(){
			return f;
		};
	};
	F.exists = function(f) {
		return typeof f == 'string' ? typeof window[f] == 'function' : f instanceof Function;
	};

	Fp.interval = function(t, a) {
		var f = this, r = function() { f.apply(null, a || []); };
		return window.setInterval(r, t);
	};
	Fp.timeout = function(t, a) {
		var f = this, r = function() { f.apply(null, a || []); };
		return window.setTimeout(r, t);
	};
	Fp.tryCatch = function(t, a, f) {
		try {
			return this.apply(t, a || []);
		} catch(e) {
			return (f ||
			function(){
				return false;
			}).apply(t, e);
		}
	};

	// ### Math prototypes

	M.rand = function(n, m) {
		if(arguments.length < 2) {
			m = n;
			n = 0;
		}
		return (Math.random() * (m - n + 1) + n).floor();
	};
	M.rad = function(g) {
		return ((2 * Math.PI) / 360) * g;
	};
	p = 1.61803398874989484820458683;
	M.PHI = p;
	M.LOW_PHI = 1 / p;

	R.EMAIL = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	R.TIMESTAMP = /([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/;
	R.URL = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

	// eliminare il flickering su IE6
	if (ua.isMSIE(6))
		try {
			document.execCommand('BackgroundImageCache', false, true);
		} catch (e) {
		}

	// Fix both IE and Opera (adjust when they implement this method properly)
	if (Agent.MSIE || ((Op = Agent.Opera) && Op < 9.5)) {
		document.nativeGetElementById = document.getElementById;
		//redefine it!
		document.getElementById = function(id){
			var o = document.nativeGetElementById(id);
			if (o) {
				// Verifica se l'elemento ottenuto ha l'id specificato
				if (o.id == id)
					return o;
				else {
					for (var i = 1, a = document.all[id], l = a.length; i < l; i++) {
						if ((o = a[i]).id == id)
							return o;
					}
				}
			}
			return null;
		};
	}

	// Costruttore di HTMLElement

	var h, d, e = {
		extend: function(m, o){
			Element.extend(this, m, o);
		}
	};
	if (typeof HTMLElement == 'undefined') {
		h = window.HTMLElement = function(){};
		p = document.createElement('div').__proto__;
		// Dovrebbe funzionare per Safari 1.3
		d = window["[[DOMElement.prototype]]"];
		if (d)
			h.prototype = d;
		// Dovrebbe funzionare per Safari 2
		else
			if ((d = document.createElement('html').constructor) && (d = d.__proto__) && (d = d.__proto__))
				h.prototype = d;
			// Dovrebbe funzionare se tutti gli elementi hanno lo stesso costruttore
			else
				if (p && p == document.createElement('span').__proto__)
					h.prototype = p;
				// SennÃš Ã‹ un normale oggetto
				else
					h.prototype = {};
		if (typeof p == 'undefined') {
			h.prototype.__proto__ = e.__proto__ = h.prototype;
		}
	}
	HTMLElement.prototype._extended = true;
	Element.implement(e);
	
	
	// Ottengo i parametri passati via GET
	var q = unescape(window.location.search.substr(1)).split('&'), l = q.length, i, v;
	for (i = 0; i < l; i++) {
		if (!(p = q[i]))
			continue;
		p = p.split('=');
		GET[p[0]] = p[1] || '';
	}
	
};
__init_FW();
delete __init_FW;


function isArray(a) {
	return (a instanceof Array);
}


/**
 * @alias				isElement
 * @classDescription	Funzione per il controllo del tipo di oggetto Element
 * @param				{Object} element
 * @param				{String} tag
 * @return				{Boolean} Restituisce vero o falso
 */
function isElement(e, t) {
	if (t)
		return ((e = e.nodeName) && e.toLowerCase() == t.toLowerCase());
	return (e.nodeName && e.ownerDocument);
}

/**
 * @alias				isNumber
 * @classDescription	Funzione per la verifica della numericitâ€¡
 * @param				{String,Number} number
 * @return				{Boolean} Restituisce vero o falso
 */
function isNumeric(n) {
	return !isNaN(parseInt(n, 10));
}

/**
 * @alias				isEnumerable
 * @classDescription	Funzione per verificare se il valore passato Ã‹ un oggetto numerabile
 * @param				{Void} value
 * @return				{Boolean} Restituisce vero o falso
 */
function isEnumerable(o) {
	return (typeof o == 'object' && (o.constructor == Array || o.callee || typeof o.length == 'number'));
}

/**
 * @alias				is
 * @classDescription	Funzione per la verifica della validitâ€¡ del valore
 * @param				{Void} value
 * @return				{Boolean} Restituisce vero o falso
 */
function is(v) {
	return (v !== false && v !== undefined && v !== null);
}

/**
 * @alias				Arr
 * @classDescription	Funzione per la conversione ad array dei tipi di dato listabili o altro
 * @param				{Void} value
 * @return				{Array} Restituisce l'array creato
 */
function Arr(a){
	for (var r = [], i = a.length - 1; i >= 0; i--)
		r[i] = Element.prototypize(a[i]);
	return r;
}
/*function Arr(a){
	//if (isEnumerable(a)) {
		for (var r = [], i = a.length - 1; i >= 0; i--)
			r[i] = a[i];
		return r;
	//}
	return is(a) ? [a] : [];
}*/

function forEach(o, f, t, p){
	if (typeof f != 'function')
		throw new TypeError();
	var i, l;
	if (typeof o == 'object')
		for (i in o)
			f.call(t, o[i], i, o);
	else {
		if (f.construnctor != Array)
			o = [o];
		l = o.length;
		for (i = 0; i < l; i++)
			f.call(t, o[i], i, o);
	}
}

function test(){
	for (var i = 0, a = arguments, l = a.length, r = null; i < l; i++) {
		try {
			r = a[i].apply();
			break;
		} catch (e) {
		}
	}
	return r;
}

function exec(c) {
	return window.execScript ? window.execScript(c) : (this.eval ? this.eval(c) : eval(c));
}

function typeOf(o){
	var t = typeof o;
	if (t == 'object') {
		if (o === null)
			return 'null';
		if (o.constructor == Array)
			return 'array';
		if (o.constructor == Date)
			return 'date';
		if (o.nodeName)
			switch (o.nodeType) {
				case 1:
					return 'element';
				case 3:
					return 'textnode';
			}
		if (o.callee)
			return 'arguments';
		/*if (typeof o.length === 'number' && !(o.propertyIsEnumerable('length')))
			return 'list';*/
		if (o instanceof Error)
			return 'error';
	}
	return t;
}


function I(o, d){
	// Se non è stato specificato un documento o non è valido come documento, uso 'document'
	if (!d || !d.documentElement)
		d = document;
	// Se non è stato specificato un elemento ritorno document
	if (!o)
		return Element.prototypize(d);
	// Se è una stringa lo ottengo per id
	if (typeof o == 'string')
		return Element.prototypize(d.getElementById(o));
	// Se è qualcos'altro verifico che sia un elemento o un documento
	if (o.nodeName || o.getElementById)
		return Element.prototypize(o);
	return o;
}
if(!window.$)
	$ = I;

function T(t, e){
	return Arr((I(e) || document).getElementsByTagName(t || '*'));
}

function C(c, o, t){
	for (var a = T(t || '*', o), r = [], i = 0, l = a.length, j = 0; i < l; i++) {
		o = I(a[i]);
		if (o.hasClass(c))
			r[j++] = o;
	}
	return r;
}

function N(n, o, t){
	for (var a = T(t || '*', o), r = [], i = 0, l = a.length, j = 0; i < l; i++) {
		o = a[i];
		if (o.getAttribute('name') == n)
			r[j++] = o;
	}
	return r;
}

function A(c, o, t){
	for (var a = T(t || '*', o), r = [], i = 0, l = a.length, j = 0; i < l; i--) {
		o = a[i];
		if (o.hasAttribute(c))
			r[j++] = o;
	}
	return r;
}

// Function to obtain a new Dom elements structure
// Modification of graft() function by Sean M. Burke from interglacial.com
// La funzione più utile del Dom
function D(t, o){
	var r;
	if (!t && t !== '')
		return null;
	var c = typeOf(t), l, e, m;
	if (c == 'array') {
		l = t.length;
		for (var i = 0; i < l; i++) {
			e = t[i];
			if (!e)
				return null;
			c = typeOf(e);
			if (i === 0 && c == 'string') {
				if (!(m = e.match(/^(\*|[a-z][a-z0-9]*)?(#([a-z][a-z0-9_-]*))?((\.[a-z][a-z0-9_-]*)+)?$/i)))
					return null;
				r = I(document.createElement(m[1]));
				if (m[2])
					r.setAttribute('id', m[3]);
				if (m[4])
					r.className = m[4].replace('.', ' ').trim();
			}
			else if (c == 'number' || c == 'string' || c == 'array' || c == 'element')
				D(e, r);
			else if (c == 'object')
+				r.set(e);
			else
				return null;
		}
	}
	else if (c == 'number' || c == 'string')
		r = document.createTextNode(t + '');
	else if(c == 'element')
		r = t;
	if (o)
		I(o).appendChild(r);
	return r;
}

// Function to obtain a group of elements by a css-like path
function P(p, e){
	p = p.replace('>', ' > ');
	p = p.replace(/(:[a-z][a-z0-9_-]*)/gi, ' $1 ');
	var s = [I(e)], t = p.split(/[\s]+/i), l = t.length, r, n, c, i, j, f, d, g, a = false;
	for (i = 0; i < l; i++) {
		d = t[i];
		if (!d)
			continue;
		g = s.length;
		if (d == '>')
			a = true;
		// Controllo primo figlio
		else if (d == ':first-child') {
			c = [];
			for (j = 0; j < g; j++) {
				f = s[j].first(true);
				if (f)
					c.push(f);
			}
			if (c.length === 0)
				return null;
			s = c;
			// Controllo prima lettera
		}
		else if (d == ':first-letter') {
			c = [];
			for (j = 0; j < g; j++) {
				f = s[j].firstLetter(true);
				if (f)
					c.push(f);
			}
			if (c.length === 0)
				return null;
			s = c;
		}
		else {
			r = null;
			// Controllo elemento
			m = d.match(/^(\*|[a-z][a-z0-9]*)/i);
			if (m) {
				n = m[1];
				if (n) {
					c = [];
					for (j = 0; j < g; j++)
						c = c.concat(T(n, s[j]));
					r = c;
					if (r.length === 0)
						return null;
				}
			}
			// Controllo id
			m = d.match(/#([a-z][a-z0-9_-]*)/i);
			if (m) {
				n = m[1];
				if (n) {
					c = [];
					for (j = 0; j < g; j++) {
						f = I(s[j].getElementById(n));
						if (f) {
							c = [f];
							break;
						}
					}
					r = (r) ? r.intersect(c) : c;
					if (r.length === 0)
						return null;
				}
			}
			// Controllo Classe
			m = d.match(/(\.[a-z][a-z0-9_-]*)+/i);
			if (m) {
				n = m[0];
				if (n) {
					c = [];
					for (j = 0; j < g; j++)
						c = c.concat(C(n, s[j]));
					r = (r) ? r.intersect(c) : c;
					if (r.length === 0)
						return null;
				}
			}
			// Controllo attributi
			m = d.match(/\[([a-z]+)((~|\^|\$|\*)?=?([^\]]*))\]?/i);
			if (m) {
				n = m[0];
				if (n) {
					c = [];
					for (j = 0; j < g; j++)
						c = c.concat(A(n, s[j]));
					r = (r) ? r.intersect(c) : c;
					if (r.length === 0)
						return null;
				}
			}
			// Controllo figli
			if (a && r) {
				c = [];
				for (j = 0; j < g; j++)
					c = c.concat(Arr(s[j].childNodes));
				r = (r) ? r.intersect(c) : c;
				if (r.length === 0)
					return null;
			}
			if (!r)
				return null;
			s = r;
		}
	}
	return s.unique();
}

function V(o, a){
	o = I(o);
	var n = o.nodeName.toLowerCase(), v = null;
	if (n == 'input' || n == 'textarea' || n == 'select' || n == 'option' || n == 'button') {
		v = o.value;
		if (a)
			o.value = a;
	}
	else {
		v = o.nodeValue;
		if (a)
			o.nodeValue = a;
	}
	return v;
}


var Dom = {
	spanSubtext: function(o, s, f){
		if (o.nodeType != 3) 
			throw new TypeError();
		var v = o.nodeValue, b = v.substring(s, f), r = D(['span', b]), l = v.length, a = [o];
		if (s > 0) 
			a.push(v.substring(0, s));
		a.push(r);
		if (f && f < l) 
			a.push(v.substring(f, l));
		Dom.after.apply(null, a);
		Dom.remove(o);
		return r;
	},
	_implements: {
		getText: function() {
			var c = this.childNodes, l = c.length, i, o, t, r = '';
			for(i = 0; i < l; i++) {
				o = c[i];
				t = o.nodeType;
				if(t == 1)
					r += I(o).getText();
				else if(t == 3)
					r += o.nodeValue;
			}
			return r;
		},
		/*spanSubtext: function(s, f) {
			var v = o.nodeValue, b = v.substring(s, f), r = D(['span', b]), l = v.length, a = [o];
			if(s > 0)
				a.push(v.substring(0, s));
			a.push(r);
			if(f && f < l)
				a.push(v.substring(f, l));
			Dom.after.apply(null, a);
			o.remove();
			return r;
		},*/
		// Metodo che ritorna il primo nodo all'interno di quello passato
		first: function(t){
			var g = this.childNodes, i, c, l = g.length;
			if (t && l > 0)
				return I(g[0]);
			for (i = 0; i < l; i++) {
				c = g[i];
				if (c.nodeType == 1)
					return c;
			}
			return null;
		},
		last: function(t){
			var g = this.childNodes, i, c, l = g.length;
			if (t && l > 0)
				return g[l - 1];
			for (i = 0; i < l; i++) {
				c = g[i];
				if (c.nodeType == 1)
					return c;
			}
			return null;
		},
		next: function(t){
			var o = this.nextSibling;
			if (t && o)
				return o;
			while (o && (o = o.nextSibling))
				if (o.nodeType == 1)
					return o;
			return null;
		},
		// Metodo che ritorna il nodo precedente a quello passato
		prev: function(t){
			var o = this.previousSibling;
			if (t && o)
				return o;
			while (o && (o = o.previousSibling))
				if (o.nodeType == 1)
					return o;
			return null;
		},
		// Metodo che ritorna la prima lettera all'interno del nodo passato
		firstLetter: function(t){
			var g = this.childNodes, l = g.length, i, c, p;
			for (i = 0; i < l; i++) {
				c = I(g[i]);
				p = c.nodeType;
				if (p == 1) {
					p = c.firstLetter(t);
					if (p)
						return p;
				}
				else if (p == 3) {
					p = c.nodeValue;
					if (!p.match(/^[\s]*$/gm)) {
						if (t)
							return p.substr(0, 1);
						if (p.length == 1 && !c.previousSibling && !c.nextSibling && c.parentNode.nodeName.toLowerCase() == 'span')
							return c.parentNode;
						return Dom.spanSubtext(c, 0, 1);
					}
				}
			}
			return null;
		},
		//### Class Name Functions
		// Function to check if an element has a class name
		hasClass: function(s) {
			s = s.split(/[\.\s]+/gi);
			for(var o = this.className, j = s.length - 1, e; j >= 0; j--) {
				if((e = s[j])) {
					e = new RegExp("(^|\\s)" + e + "(\\s|$)", 'g');
					if(!e.test(o))
						return false;
				}
			}
			return true;
		},
		// Function to add one o more classnames to an element
		addClass: function(s){
			this.removeClass(s).className += ' ' + s.split(/[\.\s]+/g).join(' ');
			return this;
		},
		// Function to remove one or more classnames from an element
		removeClass: function(s){
			this.className = this.className.replace((new RegExp("(^|\\s+)(" + s.split(/[\.\s]+/gi).join('|') + ")(\\s+|$)", 'g')), ' ');
			return this;
		},
		getClasses: function() {
			return this.className.split(/[\.\s]+/gi);
		} ,
		switchClass: function(){
			for (var a = arguments, l = a.length, i = 0, e; i < l; i++) {
				e = a[i];
				if (this.hasClass(e)) {
					this.removeClass(e);
					e = (i == l - 1) ? a[1] : a[i + 1];
					this.addClass(e);
					return;
				}
			}
			this.addClass(a[1]);
			return this;
		},
		booClass: function(){
			for (var a = arguments, i = a.length - 1, e; i >= 0; i--) {
				e = a[i];
				if (this.hasClass(e))
					this.removeClass(e);
				else
					this.addClass(e);
			}
			return this;
		},
		//### End Class Name Functions
		// Function to remove elements
		remove: function(){
			this.parentNode.removeChild(this);
			return this;
		},
		// Function to append multiple elements to a specified element
		append: function() {
			for(var a = arguments, l = a.length, i = 0; i < l; i++)
				this.appendChild(D(a[i]));
			return this;
		},
		prepend: function(){
			for (var o = this, a = arguments, i = a.length - 1, f; i >= 0; i++) {
				n = D(a[i]);
				if ((f = o.firstChild))
					o.insertBefore(n, f);
				else
					o.appendChild(n);
			}
			return this;
		},
		// Function to insert a child before another
		before: function(){
			for (var a = arguments, p = this.parentNode, l = a.length, i = 0; i < l; i++)
				p.insertBefore(D(a[i]), this);
			return this;
		},
		// Function to insert a child after another
		after: function(){
			for (var a = arguments, p = this.parentNode, n, i = a.length - 1, c; i >= 0; i--) {
				c = D(a[i]);
				if ((n = this.nextSibling))
					p.insertBefore(c, n);
				else
					p.appendChild(c);
			}
			return this;
		},
		copy: function(d) {
			o = I(this.cloneNode(true));
			if(d)
				I(d).append(o);
			return o;
		},
		move: function(o, d) {
			d = o.copy(d);
			o.remove();
			return d;
		},
		childs: function() {
			for(var c = this.childNodes, r = [], j = 0, l = c.length, i = 0; i < l; i++) {
				o = c[i];
				if(o.nodeType == 1)
					r[j++] = o;
			}
			return r;
		},
		// Function to delete all child nodes of an element
		removeChilds: function() {
			while(this.hasChildNodes())
				this.removeChild(this.firstChild);
			return this;
		},
		// Function to move all child nodes of an element to all other elements
		moveChilds: function(d) {
			var f;
			d = I(d);
			while(this.hasChildNodes()) {
				f = this.firstChild;
				d.appendChild(f.cloneNode(true));
				this.removeChild(f);
			}
			return this;
		},
		replaceChilds: function() {
			this.removeChilds();
			this.append.apply(this, arguments);
			return this;
		},
		// Function to copy all child nodes of an element to all other elements
		copyChilds: function(d){
			this.moveChilds.apply(I(this.cloneNode(true)), d);
			return this;
		},
		into: function(t) {
			t = I(t);
			var o = this;
			do {
				if (o === t)
					return true;
			}
			while ((o = o.parentNode));
			return false;
		},
		get: function() {
			var a = arguments, f = a[0], l = a.length;
			if (l == 1) {
				if(f == 'class' || f == 'className')
					return this.className;
				return this.getAttribute(f);
			}
			for(var i = 0, r = {}, c; i < l; i++) {
				c = a[i];
				r[c] = this.get(c);
			}
			return r;
		},
		// Function to set multiple attributes to a specified element
		set: function(k, v) {
			if (typeof k == 'object') 
				for (v in k)
					this.set(v, k[v]);
			else if (typeof v == 'function') 
				this.addEvent(k, v);
				//o[i] = function() { e.apply(this, arguments); };
			else if (k == 'class' || k == 'className') 
				this.addClass(v);
			else if (k == 'style') 
				this.setStyles(v);
			else 
				this.setAttribute(k, v);
			return this;
		},
		hasAttribute: function(c, d) {
			var e = '', v, m;
			if (typeof c == 'string') {
				if(d)
					c += '=' + d;
				if ((m = c.match(/^\[?([a-z]+)(\~|\^|\$|\*)?(\=([^\]]+))?\]?$/i))) {
					var a = m[1], s = m[4];
					//s.replace(/(\\|\.|\(|\)|\[|\]|\^|\$)/gmi, '\\' + '\\1');
					if((v = this.get(a))) {
						if (vm[3]) {
							switch(m[2]) {
								case '~':
									e = '(^|\\s)' + s + '(\\s|$)';
								break;
								case '^':
									e = '^' + s;
								break;
								case '$':
									e = s + '$';
								break;
								case '*':
									e = s;
								break;
								default:
									e = '^' + s + '$';
									break;
							}
							if (v.match((new RegExp(e))))
								return true;
						}
						return true;
					}
				}
				return false;
			}
			var j = 0, l;
			if(c instanceof Array) {
				for (j = 0, l = c.length; i < l; i++) 
					if (!this.hasAttribue(c[j]))
						return false;
				
			} else 
				for (j in c) 
					if(!this.hasAttribue(j, c[j]))
						return false;
			return true;
		},
		// Function to set the CSS style attribute to an element
		setStyles: function(s){
			var z = this.style, e = Agent.MSIE, i, c;
			if (typeof s == 'object') {
				var f = (e) ? 'styleFloat' : 'cssFloat';
				for (i in s) {
					c = s[i];
					if (i == 'opacity')
						this.setOpacity(c);
					else if (i == 'backgroundAlphaImage')
						this.alphabackground(c);
					else if (i == 'float')
						z[f] = c;
					else
						z[i] = c;
				}
			}
			else if (typeof s == 'string') {
				if (e)
					z.cssText = s;
				else
					this.setAttribute('style', s);
			}
			return this;
		},
		getStyle: function(s){
			if(s == 'opacity')
				return this.getOpacity();
			s = s.camelCase();
			var z = this.style, c = this.currentStyle, k = document.defaultView;
			c = c ? c : (k ? k.getComputedStyle(this, '') : {});
			s = z[s] || c[s] || '';
			return s;
		},
		// Function to obtain the values of requested style properties
		getStyles: function(){
			var a = arguments, r = {}, z = this.style, c = this.currentStyle, k = document.defaultView, e = null, i;
			c = c ? c : (k ? k.getComputedStyle(this, '') : {});
			for (i = a.length - 1; i >= 0; i--) {
				e = a[i].camelCase();
				r[e] = z[e] || c[e] || '';
			}
			return r;
		},
		switchStyle: function(){
			var a = arguments, n = a[0], s = this.getStyle(n), l = a.length, i;
			if (n.toLowerCase().has('color'))
				s = new Color(s).hex();
			for (i = 1, e; i < l; i++) {
				e = a[i];
				if (e == s) {
					e = (i == l - 1) ? a[1] : a[i + 1];
					this.style[n] = e;
					return;
				}
			}
			return this;
		},
		setOpacity: function(o){
			var s = this.style, e = Agent.MSIE;
			o = o.toFloat().bound(0, 1);
			//o = (o < 0.01) ? 0 : ((o > 1) ? 1 : o);
			if (e && e < 8)
				s.filter = this.getStyle('filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + (o * 100).round() + ')';
			else 
				s.opacity = o < 1 ? o : (Agent.Gecko ? 0.99 : 1);
			return this;
		},
		getOpacity: function(){
			var o, e = Agent.MSIE;
			if (e && e < 8) {
				if ((o = this.getStyles('filter').filter.match(/alpha\([\s]*opacity=([0-9]+)[\s]*\)/i)))
					o = o[1].toInt() / 100;
			} else
				o = this.getStyles('opacity').opacity;
			return isNumeric(o) ? o.toFloat() : 1;
		},
		removeOpacity: function(){
			var s = this.style, e = Agent.MSIE;
			if (e && e < 8)
				s.filter = this.getStyle('filter').replace(/alpha\([^\)]*\)/gi, '');
			else
				s.opacity = '';
			return this;
		},
		alphaBackground: function(o, m){
			var e = Agent.MSIE, s = this.style;
			if (e && e < 7) {
				if (m != 'crop' && m != 'image' && m != 'scale')
					m = 'crop';
				s.filter += 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src=\'' + o + '\', sizingMethod=\'' + m + '\')';
			}
			else
				s.backgroundImage = 'url(\'' + o + '\')';
			return this;
		},
		// Corretto il bug con IE6 e position:absolute
		realHeight: function(v){
			var o = this.copy(), r = 0, s = o.style, g = this.getStyles('paddingTop', 'paddingBottom'), e = Agent.MSIE;
			s.visibility = 'hidden';
			s.display = 'block';
			s.height = 'auto';
			if (e && e < 7)
				s.position = 'absolute';
			if (v)
				s.width = v + 'px';
			this.before(o);
			r = o.clientHeight - (g.paddingTop + '').cleanSize() - (g.paddingBottom + '').cleanSize();
			o.remove();
			return r;
		},
		document: function(){
			var d = this.contentWindow || this.contentDocument || this.document || document, c;
			if (d)
				c = d.document;
			if (c)
				d = c;
			return d;
		},
		window: function() {
			return this.contentWindow || window;
		},
		insertText: function(t){
			var n = this.nodeName.toLowerCase();
			if (n == 'input' || n == 'select' || n == 'option' || n == 'textarea')
				o.value = t;
			else
				o.appendChild(document.createTextNode(t));
			return this;
		},
		getId: function(a){
			var r = this.getAttribute('id');
			if (!r)
				this.setAttribute('id', (r = 'random_id_' + String.random()));
			return r;
		},
		body: function() {
			return T('body', this.document())[0];
		},
		head: function() {
			return T('head', this.document())[0];
		},
		clearPosition: function(){
			var s = this.style;
			s.position = s.top = s.left = s.bottom = s.right = '';
		},
		position: function(p){
			var o = this, l = 0, t = 0, c;
			do {
				l += o.offsetLeft;
				t += o.offsetTop;
			}
			while ((o = o.offsetParent));
	
			if (p) {
				c = p.alignment;
				p = p.element;
				if (p) {
					p = p.position();
					l -= p[0];
					t -= p[1];
				}
				if (c) {
					var d = this.sizes();
					// Allineamento orrizzontale
					if (c == 2 || c == 5 || c == 8)
						l += Math.round(d[0] / 2);
					else
						if (c == 3 || c == 6 || c == 9)
							l += d[0];
					// Allineamento verticale
					if (c >= 4 && c <= 6)
						t += Math.round(d[1] / 2);
					if (c >= 7 && c <= 9)
						t += d[1];
				}
			}
			return [l, t];
		},
		sizes: function(o){
			return [this.offsetWidth, this.offsetHeight];
		},
		at: function(x, y){
			var p = this.position(), s = this.sizes(), l = p[0], t = p[1], w = s[0], h = s[1];
			return (x >= l && x < (l + w) && y >= t && y < (t + h));
		},
		disableSelect: function(){
			Event.add(this, 'selectstart', function(e){
				Event.stop(e);
				return false;
			});
			this.unselectable = "on";
			var s = this.style;
			s.MozUserSelect = "none";
			s.cursor = "default";
		}
	}
};

Element.implement(Dom._implements);
delete Dom._implements;
// Funzioni per caricare nuovi js

var Include = {};

Include.JS = (function () {
	var a = {}, f = function (u) {
		return a[u] ? false : D(['script', {
			src: u,
			type: 'text/javascript',
			defer: 'defer'
		}], HEAD);
	};
	f.once = function (u) {
		a[u] = true;
		return Include(u);
	};
	f.included = function(u) {
		return a[u] ? true : false;
	}
	return f;
})();

Include.CSS = (function () {
	var a = {}, f = function (o) {
		var u = o.url;
		return a[u] ? false : D(['link', {
			href: u,
			type: 'text/css',
			rel: (o.rel || 'stylesheet'),
			media: (o.media || 'screen')
		}], HEAD);
	};
	f.once = function (u) {
		a[u] = true;
		return Include(u);
	};
	f.included = function(u) {
		return a[u] ? true : false;
	}
	return f;
})();

var LoadImage = (function(){
	var f = function(o){
		var g = new Image(), oLo = o.onload || Function.empty;
		g.onload = function(){
			var ac = arguments.callee;
			if (ac.done) 
				return false;
			ac.done = true;
			this.onload = null;
			return oLo.call(this);
		};
		g.onerror = o.onerror || Function.empty;
		g.onabort = o.onabort || Function.empty;
		g.src = o.url;
		return g;
	};
	f.more = function(o){
		var i = (o || (o = {})).images, l, j = 0, y = 0, r = [],
		oSt = o.onstart || Function.empty, p = oPr.onprogress || Function.empty, c = oCo.oncomplete || Function.empty;

		i = isArray(i) ? i : [i];
		l = i.length;

		oSt(l);
		i.each(function(g){
			if (typeof g != 'object')
				g = {
					url: g
				};
			var oLo = g.onload || Function.empty, oEr = g.onerror || Function.empty, oAb = g.onabort || Function.empty;
			g.onload = function(e){
				oLo.call(this, e);
				j++;
				oPr.call(this, j, l);
				if (j == l)
					oCo.call(this, l);
			};
			g.onerror = function(e){
				oEr.call(this, e);
				j++;
				oPr.call(this, j, l);
				if (j == l)
					oCo.call(this, l);
			};
			g.onabort = function(e){
				oAb.call(this, e);
				j++;
				oPr.call(this, j, l);
				if (j == l)
					oCo.call(this, l);
			};
			r[y++] = Load.image(g);
		});
		return r;
	};
})();

var Sort = {
	random: function() {
		return 0.5 - Math.random();
		//return (Math.round(Math.random())-0.5);
	},
	number: function(a, b) {
		return a - b;
	},
	numberDesc: function(a, b) {
		return b - a;
	},
	string: function(a, b) {
		a = (a + '').toLowerCase();
		b = (b + '').toLowerCase();
		return a < b ? -1 : (a > b ? 1 : 0);
	},
	stringDesc: function(a, b) {
		a = (a + '').toLowerCase();
		b = (b + '').toLowerCase();
		return a < b ? 1 : (a > b ? -1 : 0);
	},
	date: function(a, b) {
		return a.getTime() - b.getTime();
	},
	dateDesc: function(a, b) {
		return b.getTime() - a.getTime();
	},
	natural: function(a, b){

		a += '';
		b += '';

		var cr = function(a, b){
			var bias = 0, ia = 0, ib = 0, ca, cb, da, db;

			while (true) {
				ca = a.charAt(ia++);
				cb = b.charAt(ib++);
				da = ca.digitChar();
				db = cb.digitChar();

				if (!da && !db)
					return bias;
				else if (!da)
					return -1;
				else if (!db)
					return +1;
				else if (ca < cb) {
					if (bias === 0)
						bias = -1;
				}
				else if (ca > cb) {
					if (bias === 0)
						bias = +1;
				}
				else if (ca === 0 && cb === 0)
					return bias;
			}
		};

		var ia = 0, ib = 0, na, nb, ca, cb, r;

		while (true) {
			na = nb = 0;

			while ((ca = a.charAt(ia++)) && (ca.whiteSpaceChar() || ca == '0'))
				if (ca == '0')
					na++;
				else
					na = 0;

			while ((cb = b.charAt(ib++)) && (cb.whiteSpaceChar() || cb == '0'))
				if (cb == '0')
					nb++;
				else
					nb = 0;

			if ((ca.digitChar() && cb.digitChar()) && ((r = cr(a.substring(ia), b.substring(ib))) !== 0))
				return r;

			if (ca === 0 && cb === 0)
				return na - nb;

			if (ca < cb)
				return -1;
			else if (ca > cb)
				return +1;
		}
	}
};

var IFrame = {
	focus: function(o){
		o = I(o);
		if (o.contentWindow)
			o.contentWindow.focus();
		else
			o.focus();
	}
};

var Window = Class({
	url: '',
	options: {},
	value: null,
	name: '',
	_construct: function(u, o) {
		this.set(u, o);
	},
	set: function(u, o) {
		if(u)
			this.url = u;
		if(o)
			this.options = o;
	},
	open: function() {
		var u = this.url, o = this.options, n = o.name || 'win_' + String.random(),
		w = o.width, h = o.height, aw = screen.availWidth, ah = screen.availHeight, sw = screen.width, sh = screen.height,
		x = 0, y = 0, a = '';
		if (o.fullscreen) {
			w = aw;
			h = ah;
		}
		if(o.center) {
			y = Math.floor((ah - (h || ah)) / 2) - (sh - ah);
			x = Math.floor((aw - (w || aw)) / 2) - (sw - aw);
		}
		if (w)
			a += 'width=' + w + ',';
		if (h)
			a += 'height=' + h + ',';
		a += 'screenx=' + x + ',screeny=' + y + ',left=' + x + ',top=' + y + ',';
		if(o.scrollbars)
			a += 'scrollbars=1,';
		if(o.menubar)
			a += 'menubar=1,';
		if(o.locationbar)
			a += 'location=1,';
		if(o.resizable)
			a += 'resizable=1,';
		this.name = n;
		return (this.value = window.open(u, n, a));
	}
});



var Env = {
	viewSize: function(){
		var e = document.documentElement, o = document.body, w, h, a, b;
		a = e.clientWidth;
		b = o.clientWidth;
		w = a && b ? (a < b ? a : b) : (a || b);
		a = e.clientHeight;
		b = o.clientHeight;
		h = a && b ? (a < b ? a : b) : (a || b);
		return [w, h];
	},
	pageScroll: function() {
		var e = document.documentElement, o = document.body;
		return [self.pageXOffset || e.scrollLeft || o.scrollLeft || 0, self.pageYOffset || e.scrollTop || o.scrollTop || 0];
	},
	maxScroll: function() {
		var p = Env.pageSize(), v = Env.viewSize();
		return [p[0] - v[0], p[1] - v[1]];
	},
	pageSize: function() {
		var o = document.body, n = window, e = document.documentElement, x = 0, y = 0, a, b;
		if ((a = e.clientHeight) && (b = n.scrollMaxY)) {
			x = e.clientWidth + n.scrollMaxX;
			y = a + b;
		} else {
			x = (a = o.scrollWidth) > (b = o.offsetWidth) ? a : b;
			y = (a = o.scrollHeight) > (b = o.offsetHeight) ? a : b;
		}
		return [x, y];
	},
	viewCenter: function(w, h, wd, hd) {
		var t = typeOf(w), c = Env.viewSize(), s = Env.pageScroll();
		if(t == 'array' || (t == 'element' && (w = I(w).sizes()))) {
			hd = wd;
			wd = h;
			h = w[1];
			w = w[0];
		}
		return [Math.round((c[0] - (w || 0)) * (wd || 0.5)) + s[0], Math.round((c[1] - (h || 0)) * (hd || 0.5)) + s[1]];
	},
	gridPosition: function(x, y, o){
		var s = Env.clientSizes(), c = (o || (o = {})).cols, r = o.rows, w = o.width, h = o.height, i = 0, xc = 0, yc = 0;
		w = c ? s[0] / c : w || 50;
		h = r ? s[1] / r : h || 50;
		while ((w * i) <= x)
			xc = i++;
		i = 0;
		while ((h * i) <= y)
			yc = i++;
		return [xc, yc];
	},
	generateGrid: function(w, h, n, s) {
		for(var i = 0, j = 0, x = 0, y = 0, r = []; i < n; i++, j++) {
			x = w * j;
			if ((x + w) > s) {
				x = j = 0;
				y += h;
			}
			r[i] = [x, y];
		}
		return r;
	},
	gridCoords: function(w, h, n, s) {
		s = Math.floor(s / w);
		return [((n % s) * w), Math.floor(n / s) * h];
	},
	positionRatio: function(p, s, t) {
		if(!t)
			return s / p;
		t = t.bound(0, 1);
		var fh = s * t, sh = s - fh;
		return p < fh ? (p / fh) - 1 : (p > fh ? (p - fh) / sh : 0);
	}
};

var Cookie = {
	set: function(o){
		var p = o.path, d = o.domain, s = o.secure;
		document.cookie = o.name + '=' + escape(o.value || '') +
		'; expires=' + (new Date((new Date().getTime()) + ((o.expire || 0) * 1000))).toGMTString() +
		(p ? '; path=' + p : '') +
		(d ? '; domain=' + d : '') +
		(s ? '; secure' : '');
	},
	getAll: function() {
		for(var e = document.cookie.split(';'), i = 0, l = e.length, r = {}; i < l; i++) {
			c = e[i].split('=');
			r[c[0]] = unescape(c[1]);
		}
		return r;
	},
	get: function(n){
		return ((n = document.cookie.match((new RegExp('(^|;)\\s*' + n + '=([^;]*)')))) && (n = n[1])) ? unescape(n) : null;
	},
	unset: function(o){
		(o || (o = {})).expire = -30000000;
		Cookie.set(o);
	}
};

var Event = {
	mousePosition: function(e, o){
		var x, y, c, d = document, p;
		if ((x = ((e || (e = window.event)).pageX))) 
			y = e.pageY;
		else if ((x = e.clientX) && (c = d.body) && (d = d.documentElement)) {
			x += c.scrollLeft + d.scrollLeft;
			y = e.clientY + c.scrollTop + d.scrollTop;
		}
		return o && (o = typeof o == 'boolean' ? Env.pageScroll() : I(o).position()) ? [x - o[0], y - o[1]] : [x, y];
	},
	fromElement: function(e) {
		return (e || (e = window.event)).relatedTarget || e.fromElement;
	},
	toElement: function(e) {
		return (e || (e = window.event)).relatedTarget || e.toElement;
	},
	exitElement: function(e, o) {
		o = I(o) || Event.target(e);
		e = Event.toElement(e);
		while(e != o && e.tagName.toLowerCase() != 'body')
			e = e.parentNode;
		return !(e == o);
	},
	target : function(e) {
		return (e || (e = window.event)).target || e.srcElement;
	},
	cancelBubble: function(e) {
		(e || window.event).cancelBubble = true;
	},
	preventDefault: function(e) {
		if((e || (e = window.event)).preventDefault)
			e.preventDefault();
		else
			e.returnValue = false;
		return e;
	},
	stopPropagation: function(e){
		if((e || (e = window.event)).stopPropagation)
			e.stopPropagation();
		else
			e.cancelBubble = true;
		return e;
	},
	stop: function(e) {
		Event.stopPropagation(e);
		Event.preventDefault(e);
		return false;
	},
	getKey: function(e) {
		var n = (e || (e = window.event)).keyCode || e.which, k = String.fromCharCode(n), s = e.shiftKey, c = e.ctrlKey, a = e.altKey, m = Event.keysMap, v, i;
		if(n <= 13 || n >= 20) {
			v = (s ? 4 : 0) + (c ? 2 : 0) + (a ? 1 : 0);
			for(i = m.length - 1; i >= 0; i--) {
				e = m[i];
				if(e[0] === n && e[1] == v) {
					k = c[2];
					break;
				}
			}
		}
		return {
			code: n,
			key: k,
			shift: s,
			ctrl: c,
			alt: a
		};
	},
	keysMap: [
		[8, 0, 'BackSpace'],
		[9, 0, 'Tab'],
		[9, 4, 'Btab'],
		[12, 0, 'CursorCenter'],
		[13, 0, 'Enter'],
		[19, 0, 'Pause'],
		[20, 0, 'CapsLock'],
		[27, 0, 'Escape'],
		[33, 0, 'PageUp'],
		[34, 0, 'PageDown'],
		[35, 0, 'End'],
		[35, 2, 'GoToBottom'],
		[36, 0, 'CursorHome'],
		[36, 2, 'ControlHome'],
		[37, 0, 'CursorLeft'],
		[38, 0, 'CursorUp'],
		[39, 0, 'CursorRight'],
		[40, 0, 'CursorDown'],
		[44, 0, 'Print'],
		[45, 0, 'Insert'],
		[46, 0, 'Delete'],
		[46, 4, 'EraseField'],
		[46, 2, 'EraseEOP'],
		[46, 1, 'ClearScreen'],
		[91, 0, 'LeftWin'],
		[92, 0, 'RightWin'],
		[144, 0, 'NumLock'],
		[145, 0, 'ScrollLock']
	],
	getButton: function(e) {
		var n = (e || (e = window.event)).button, l, m, r;
		if(n) {
			l = n & 1;
			r = n & 2;
			m = n & 4;
		} else {
			n = e.which;
			l = n == 1;
			r = n == 2;
			m = n == 3;
		}
		return {button: n, left: l, middle: m, right: r, shift: e.shiftKey, ctrl: e.ctrlKey, alt: e.altKey};
	},
	getWheel: function(e) {
		var d = (e || (e = window.event)).detail;
		if(d)
			d = -d / 3;
		else {
			d = e.wheelDelta / 120;
			if(window.opera)
				d = -d;
		}
		return {wheel: d, shift: e.shiftKey, ctrl: e.ctrlKey, alt: e.altKey};
	},
	add : function(o, t, f, w) {
		f = Function.get(f);
		if(typeof f !== 'function') throw new TypeError('Not a function');
		o = I(o);
		t = t.toLowerCase().replace(/^on/, '');
		if(t == 'domloaded') {
			if(o == window) Event._onDomLoaded.add(f);
		} else {

			if(t == 'scroll' && o == document && Agent.MSIE)
				o = window;

			if(['clickout', 'dblclickout', 'mousemoveout'].has(t)) {
				var of = f, oo = o;
				o = document;
				t = t.replace(/out$/, '');
				f = function(e) {
					var p = Event.target(e), g = p;
					do { if(p === oo) return; } while((p = p.parentNode));
					of.call(g, e);
				};
			}
			if(!o._events) o._events = {};
			var e = o._events;
			if(!e[t]) e[t] = [];
			e[t].push(f);
			if(o.attachEvent) {
				o['e'+t+f] = f;
				o[t+f] = function(){o['e'+t+f](window.event);};
				o.attachEvent('on'+t, o[t+f]);
			} else {
				if(t == 'mousewheel') t = 'DOMMouseScroll';
				o.addEventListener(t, f, false);
			}
		}
	},
	remove: function(o, t, f) {
		o = I(o);
		t = t.toLowerCase().replace(/^on/, '');
		var e = o._events;
		if(e && e[t]) {
			e = e[t];
			for(var i = e.length - 1, a; i >= 0; i--) {
				a = e[i];
				if(a === f) {
					e[i] = e[e.length - 1];
					e.length--;
				}
			}
		}
		if(o.detachEvent) {
			o.detachEvent('on'+t, o[t+f]);
			o[t+f] = null;
		} else {
			if(t == 'mousewheel') t = 'DOMMouseScroll';
			o.removeEventListener(t, f, false);
		}
	},
	get: function(o, t) {
		o = I(o);
		t = t.toLowerCase().replace(/^on/, '');
		var e = o.events;
		return (e && e[t]) ? e[t] : [];
	},
	clone: function(o, u) {
		o = I(o);
		var e = o._events;
		if(e) {
			for(var t in e) {
				var a = e[t];
				for(var i = 0, l = a.length; i < l; i++) {
					Event.add(u, t, a[i]);
				}
			}
		}
	},
	/* onDomLoaded */
	_onDomLoaded: {
		cache: [],
		run: function() {
			var m = Event._onDomLoaded, e = m.cache, i, l = e.length;
			m.cache = [];
			for(i = 0; i < l; i++) e[i]();
		},
		/*executer: function() {
			var m = this, o = window.opera;
			onload = m.run;
			if(/WebKit|Konqueror/i.test(navigator.userAgent))
				(function() { if(/loaded|complete/.test(document.readyState)) m.callback(); else setTimeout(arguments.callee, 1); })();
			else if((!o || parseInt(o.version(), 10) >= 9) && document.addEventListener)
				document.addEventListener('DOMContentLoaded', Event._onDomLoaded.callback, false);
			else document.write('<scr' + 'ipt src="void(0)" defer="defer" onreadystatechange="if(this.readyState === \'complete\') Event._onDomLoaded.callback()"></scr'+'ipt>');
		},*/
		executer: function() {
			var m = this, a = Agent, o = a.Opera, t = window.setTimeout, d = document;
			//onload = m.run;
			if(a.Konqueror || a.WebKit)
				(function() { if(/loaded|complete/.test(d.readyState)) m.callback(); else t(arguments.callee, 1); })();
			else if((!o || o >= 9) && d.addEventListener)
				d.addEventListener('DOMContentLoaded', Event._onDomLoaded.callback, false);
			else if(Agent.MSIE)
				(function() { try{ d.documentElement.doScroll('left'); m.run(); } catch(e) { t(arguments.callee, 1); }})();
			else
				Event.add(window, 'load', m.run());
		},
		callback: function() { window.onload = null; Event._onDomLoaded.run(); },
		add: function(e) {
			var m = Event._onDomLoaded;
			if(m.cache.length === 0) m.executer();
			e = Function.get(e);
			m.cache.push(e);
		}
	},
	// onClickOut
	// Metodi per creare e eseguire eventi
	_eventTypes: {
		'DOMFocusIn': 'UIEvent',
		'DOMFocusOut': 'UIEvent',
		'DOMActivate': 'UIEvent',
		'focus': 'UIEvent',
		'blur': 'UIEvent',
		'click': 'MouseEvent',
		'mousedown': 'MouseEvent',
		'mouseup': 'MouseEvent',
		'mouseover': 'MouseEvent',
		'mousemove': 'MouseEvent',
		'mouseout': 'MouseEvent',
		'keydown': 'keyboardEvent',
		'keyup': 'KeyboardEvent',
		'textInput': 'TextEvent',
		'DOMSubtreeModified': 'MutationEvent',
		'DOMNodeInserted': 'MutationEvent',
		'DOMNodeRemoved': 'MutationEvent',
		'DOMNodeRemovedFromDocument': 'MutationEvent',
		'DOMNodeInsertedIntoDocument': 'MutationEvent',
		'DOMAttrModified': 'MutationEvent',
		'DOMCharacterDataModified': 'MutationEvent',
		'DOMElementNameChanged': 'MutationNameEvent',
		'DOMAttributeNameChanged': 'MutationNameEvent',
		'load': 'Event',
		'unload': 'Event',
		'abort': 'Event',
		'error': 'Event',
		'select': 'Event',
		'change': 'Event',
		'submit': 'Event',
		'reset': 'Event',
		'resize': 'Event',
		'scroll': 'Event'
	},
	getEventType: function(t) {
		t = t.replace(/^on/, '');
		var i, p = Event._eventTypes;
		for(i in p) if(t == i) return p[i];
		return null;
	},
	create: function(t, m) {
		var e = null, c;
		// Mozilla / DOM
		if (document.createEvent) {
			c = Event.getEventType(t);
			if (c) {
				e = document.createEvent(c);
				m = Event.cleanEventProperties(m);
				switch (c) {
					case 'Event':
						e.initEvent(t, m.bubbles, m.cancelable);
					break;
					case 'UIEvent':
						e.initUIEvent(t, m.bubble, m.cancelable, m.view, m.detail);
					break;
					case 'MouseEvent':
						e.initMouseEvent(t, m.bubble, m.cancelable, m.view, m.detail, m.screenX, m.screenY, m.clientX, m.clientY, m.ctrlKey, m.altKey, m.shiftKey, m.metaKey, m.button, m.relatedTarget);
					break;
					case 'KeyboardEvent':
						e.initKeyEvent(t, m.bubble, m.cancelable, m.view, m.ctrlKey, m.altKey, m.shiftKey, m.metaKey, m.keyCode, m.charCode);
					break;
					case 'MutationEvent':
						e.initMutationEvent(t, m.bubble, m.cancelable, m.relatedNode, m.prevValue, m.newValue, m.attrName, m.attrChange);
					break;
					case 'MutationNameEvent':
						e.initMutationNameEvent(t, m.bubble, m.cancelable, relatedNode, prevNamespaceUri, prevNodeName);
					break;
					case 'TextEvent':
						e.initTextEvent(t, m.bubble, m.cancelable, m.view, m.data);
					break;
					case 'PopupBlocked':
						e.initPopupBlockedEvent();
					break;
					case 'XULCommandEvent':
						e.initCommandEvent();
					break;
					default:
						e = null;
					break;
				}
			}
		// MSIE
		}
		else if (document.createEventObject) {
			e = document.createEventObject();
			if (m) 
				Tools.object(e, m);
		}
		return e;
	},
	fire: function(o, t, e) {
		o = I(o);
		t = t.replace(/^on/, '');
		if(!e) e = Event.create(t, e);
		// MSIE
		if(o.fireEvent) {
			o.fireEvent('on' + t, e);
		} else if(o.dispatchEvent) {
			o.dispatchEvent(e);
		}
	},
	cleanEventProperties: function(p) {
		if(!p) p = {};
		return Tools.object({
			altKey: false,
			bubbles: true,
			button: 0,
			cancelable: true,
			//cancelBubble: false,
			charCode: 0,
			clientX: 0,
			clientY: 0,
			ctrlKey: false,
			currentTarget: null,
			detail: 0,
			eventPhase: null,
			//explicitOriginalTarget: null,
			isChar: false,
			keyCode: 0,
			layerX: 0,
			layerY: 0,
			metaKey: false,
			//originalTarget: null,
			pageX: 0,
			pageY: 0,
			relatedTarget: null,
			screenX: 0,
			screenY: 0,
			shiftKey: false,
			target: null,
			timeStamp: 0,
			type: '',
			view: window,
			which: 0
		}, p);
	},
	// Implementazione degli eventi
	_implements: {
		addEvent: function(e, f){
			Event.add(this, e, f);
			return this;
		},
		removeEvent: function(e, f){
			Event.remove(this, e, f);
			return this;
		},
		getEvent: function(e){
			return Event.getEvent(this, e);
		}
	}
};
Element.implement(Event._implements);
delete Event._implements;

var Cinematic = Class({
	_interval: null,
	_func: '',
	_stepTime: 0,
	step: 0,
	__construct: function(f, o) {
		this._init(f, o);
	},
	_init: function(f, o){
		o = o || {};
		var t = o.time || 1, fps = o.fps || 25, w = (o.wait || 0) * 1000, st = (t * fps).floor(), i = 0, ff, self = this, args, tg = o.target;
		this._func = function(){
			var args = [self.step++, st, self];
			f.apply(tg, args);
			if (self.step == st) 
				clearInterval(self._interval);
		};
		this._stepTime = (1000 / fps).round();
	},
	start: function() {
		var ff;
		this._interval = ff = setInterval(this._func, this._stepTime);
	},
	pause: function() {
		clearInterval(this._interval);
	},
	stop: function() {
		this.pause();
		this.step = 0;
	}
});


var Point = Class({
	x: 0,
	y: 0,
	__construct: function(x, y) {
		var t = typeOf(x);
		if (t == 'array' || (t == 'element' && (x = I(x).position(y)))) {
			y = x[1];
			x = x[0];
		} else if(t == 'object') {
			y = x.y;
			x = x.x;
		}
		this.x = x || 0;
		this.y = y || 0;
	},
	toArray: function() {
		return [this.x, this.y];
	},
	toString: function() {
		return this.x + ', ' + this.y;
	},
	distance: function(x, y) {
		var p = new Point(x, y), px = p.x, py = p.y, tx = this.x, ty = this.y;
		px = px > tx ? px - tx : tx - px;
		py = py > ty ? py - ty : ty - py;
		return Math.sqrt((px * px) + (py * py));
	}
});

var Template = Class({
	openTag: '{$',
	closeTag: '}',
	template: '',
	variables: null,
	__construct: function(t) {
		this.variables = {};
		if(t)
			this.setTemplate(t);
	},
	setTemplate: function(t) {
		this.template= '' + t;
	},
	setVariables: function(s, v) {
		var i, c = this.variables;
		if(typeof s == 'string')
			c[s] = v || '';
		else
			for(i in s)
				c[i] = s[i];
	},
	parse: function(s, v) {
		var t = this.template, v = this.variables, ot = this.openTag, ct = this.closeTag, i, e;
		for(i in v)
			t = t.replace(ot + i + ct, v[i]);
		return t;
	}
});

var Url = Class({
	scheme: '',
	host: '',
	port: '',
	user: '',
	pass: '',
	path: '',
	query: '',
	fragment: '',
	extension: '',
	relative: false,
	__construct: function(u) {
		this.set(u);
	},
	set: function(u) {
		var t  =  typeof u, p, h;
		if(t == 'string') {
			if ((u = u.match(Url.URL_EREG))) {
				this.scheme = u[2] || '';
				this.user = u[4] || '';
				this.pass = u[5] || '';
				this.host = h = u[6] || '';
				this.port = u[8] || '';
				this.path = p = u[9] || '';
				this.query = u[11] || '';
				this.fragment = u[13] || '';
				if(h == '.' || h == '..' || (!h && p.substr(0, 1) != '/'))
					this.relative = true;
					
				if(p) {
					p = p.split('/').pop().split('.').pop();
					this.extension = p || '';
				}
			}
		}
	},
	getDirUrl: function() {
		var u = '', s;
		if((s = this.scheme))
			u += s == 'mailto' ? s + ':' : s + '://';
		if((s = this.path))
			u += s;
		return u;
	},
	toString: function() {
		var u = '', s;
		if((s = this.scheme))
			u += s == 'mailto' ? s + ':' : s + '://';
		if ((s = this.user)) {
			u += s;
			if((s = this.pass))
				u += ':' + s;
			u += '@';
		}
		u += this.host;
		if((s = this.port))
			u += ':' + s;
		if((s = this.path))
			u += s;
		if((s = this.query))
			u += '?' + s;
		if((s = this.fragment))
			u += '#' + s;
		return u;
	}
});

Url.URL_EREG = /^(([a-z]+):\/*)?(([^:]+):?([^@]+)@)?([a-z0-9\.-]+)?(:([0-9]+))?(\/[^\?#]*)(\?([^#]*))?(#(.*))?$/i;
Url.isUrl = function(u) {
	return u.match(Url.URL_EREG);
};

var Color = Class({
	red: 0,
	green: 0,
	blue: 0,
	alpha: 1,
	_names: {
		AliceBlue: '#F0F8FF',
		AntiqueWhite: '#FAEBD7',
		Aqua: '#00FFFF',
		Aquamarine: '#7FFFD4',
		Azure: '#F0FFFF',
		Beige: '#F5F5DC',
		Bisque: '#FFE4C4',
		Black: '#000000',
		BlanchedAlmond: '#FFEBCD',
		Blue: '#0000FF',
		BlueViolet: '#8A2BE2',
		Brown: '#A52A2A',
		BurlyWood: '#DEB887',
		CadetBlue: '#5F9EA0',
		Chartreuse: '#7FFF00',
		Chocolate: '#D2691E',
		Coral: '#FF7F50',
		CornflowerBlue: '#6495ED',
		Cornsilk: '#FFF8DC',
		Crimson: '#DC143C',
		Cyan: '#00FFFF',
		DarkBlue: '#00008B',
		DarkCyan: '#008B8B',
		DarkGoldenRod: '#B8860B',
		DarkGray: '#A9A9A9',
		DarkGrey: '#A9A9A9',
		DarkGreen: '#006400',
		DarkKhaki: '#BDB76B',
		DarkMagenta: '#8B008B',
		DarkOliveGreen: '#556B2F',
		Darkorange: '#FF8C00',
		DarkOrchid: '#9932CC',
		DarkRed: '#8B0000',
		DarkSalmon: '#E9967A',
		DarkSeaGreen: '#8FBC8F',
		DarkSlateBlue: '#483D8B',
		DarkSlateGray: '#2F4F4F',
		DarkSlateGrey: '#2F4F4F',
		DarkTurquoise: '#00CED1',
		DarkViolet: '#9400D3',
		DeepPink: '#FF1493',
		DeepSkyBlue: '#00BFFF',
		DimGray: '#696969',
		DimGrey: '#696969',
		DodgerBlue: '#1E90FF',
		FireBrick: '#B22222',
		FloralWhite: '#FFFAF0',
		ForestGreen: '#228B22',
		Fuchsia: '#FF00FF',
		Gainsboro: '#DCDCDC',
		GhostWhite: '#F8F8FF',
		Gold: '#FFD700',
		GoldenRod: '#DAA520',
		Gray: '#808080',
		Grey: '#808080',
		Green: '#008000',
		GreenYellow: '#ADFF2F',
		HoneyDew: '#F0FFF0',
		HotPink: '#FF69B4',
		IndianRed : '#CD5C5C',
		Indigo : '#4B0082',
		Ivory: '#FFFFF0',
		Khaki: '#F0E68C',
		Lavender: '#E6E6FA',
		LavenderBlush: '#FFF0F5',
		LawnGreen: '#7CFC00',
		LemonChiffon: '#FFFACD',
		LightBlue: '#ADD8E6',
		LightCoral: '#F08080',
		LightCyan: '#E0FFFF',
		LightGoldenRodYellow: '#FAFAD2',
		LightGray: '#D3D3D3',
		LightGrey: '#D3D3D3',
		LightGreen: '#90EE90',
		LightPink: '#FFB6C1',
		LightSalmon: '#FFA07A',
		LightSeaGreen: '#20B2AA',
		LightSkyBlue: '#87CEFA',
		LightSlateGray: '#778899',
		LightSlateGrey: '#778899',
		LightSteelBlue: '#B0C4DE',
		LightYellow: '#FFFFE0',
		Lime: '#00FF00',
		LimeGreen: '#32CD32',
		Linen: '#FAF0E6',
		Magenta: '#FF00FF',
		Maroon: '#800000',
		MediumAquaMarine: '#66CDAA',
		MediumBlue: '#0000CD',
		MediumOrchid: '#BA55D3',
		MediumPurple: '#9370D8',
		MediumSeaGreen: '#3CB371',
		MediumSlateBlue: '#7B68EE',
		MediumSpringGreen: '#00FA9A',
		MediumTurquoise: '#48D1CC',
		MediumVioletRed: '#C71585',
		MidnightBlue: '#191970',
		MintCream: '#F5FFFA',
		MistyRose: '#FFE4E1',
		Moccasin: '#FFE4B5',
		NavajoWhite: '#FFDEAD',
		Navy: '#000080',
		OldLace: '#FDF5E6',
		Olive: '#808000',
		OliveDrab: '#6B8E23',
		Orange: '#FFA500',
		OrangeRed: '#FF4500',
		Orchid: '#DA70D6',
		PaleGoldenRod: '#EEE8AA',
		PaleGreen: '#98FB98',
		PaleTurquoise: '#AFEEEE',
		PaleVioletRed: '#D87093',
		PapayaWhip: '#FFEFD5',
		PeachPuff: '#FFDAB9',
		Peru: '#CD853F',
		Pink: '#FFC0CB',
		Plum: '#DDA0DD',
		PowderBlue: '#B0E0E6',
		Purple: '#800080',
		Red: '#FF0000',
		RosyBrown: '#BC8F8F',
		RoyalBlue: '#4169E1',
		SaddleBrown: '#8B4513',
		Salmon: '#FA8072',
		SandyBrown: '#F4A460',
		SeaGreen: '#2E8B57',
		SeaShell: '#FFF5EE',
		Sienna: '#A0522D',
		Silver: '#C0C0C0',
		SkyBlue: '#87CEEB',
		SlateBlue: '#6A5ACD',
		SlateGray: '#708090',
		SlateGrey: '#708090',
		Snow: '#FFFAFA',
		SpringGreen: '#00FF7F',
		SteelBlue: '#4682B4',
		Tan: '#D2B48C',
		Teal: '#008080',
		Thistle: '#D8BFD8',
		Tomato: '#FF6347',
		Turquoise: '#40E0D0',
		Violet: '#EE82EE',
		Wheat: '#F5DEB3',
		White: '#FFFFFF',
		WhiteSmoke: '#F5F5F5',
		Yellow: '#FFFF00',
		YellowGreen: '#9ACD32'
	},
	__construct: function(c) {
		this.set(c);
	},
	set: function(c) {
		if(c) {
			var r = 0, g = 0, b = 0, a = 1;
			if(typeof c == 'string') {
				c = c.replace(/[\s]+/g, '');
				var i, n = this._names, m;
				if(c.match(/^[a-z]+$/gi)) {
					c = c.toLowerCase();
					for (i in n) {
						if (c == i.toLowerCase()) {
							c = n[i];
							break;
						}
					}
				}
				//if((/^#[0-9A-F]{3,8}$/gi).test(c)) {
				if(c.match(/^#[0-9A-F]{3,8}$/gi)) {
					a = 'FF';
					switch(c.length) {
						case 5:
							a = c.substring(4, 5);
							a += a;
						case 4:
							r = c.substring(1, 2);
							g = c.substring(2, 3);
							b = c.substring(3, 4);
							r += r;
							g += g;
							b += b;
						break;
						case 9:
							a = c.substring(7, 9);
						default:
						case 7:
							r = c.substring(1, 3);
							g = c.substring(3, 5);
							b = c.substring(5, 7);
						break;
					}
					r = r.toInt(16);
					g = g.toInt(16);
					b = b.toInt(16);
					a = a.toInt(16) / 255;
				} else if((m = c.match(/rgb\(([0-9]+%?),([0-9]+%?),([0-9]+%?)\)/i)) || (m = c.match(/rgba\(([0-9]+%?),([0-9]+%?),([0-9]+%?),([0-9\.]+%?)\)/i))) {
					r = m[1]; g = m[2]; b = m[3]; a = m[4];
					r = r.toInt() * (r.has('%') ? 2.55 : 1);
					g = g.toInt() * (g.has('%') ? 2.55 : 1);
					b = b.toInt() * (b.has('%') ? 2.55 : 1);
					a = (a) ? (a.has('%') ? a.toInt() * 2.55 : a.toFloat()) : 1;
				} else  if((m = c.match(/cmyk\(([0-9]+%?),([0-9]+%?),([0-9]+%?),([0-9]+%?)\)/i)) || (m = c.match(/cmyka\(([0-9]+%?),([0-9]+%?),([0-9]+%?),([0-9]+%?),([0-9\.]+%?)\)/i))) {
					var y = m[3], k = m[4];
					c = m[1]; m = m[2];
					c = c.toInt() * (c.has('%') ? 2.55 : 1);
					m = m.toInt() * (m.has('%') ? 2.55 : 1);
					y = y.toInt() * (y.has('%') ? 2.55 : 1);
					k = (255 - (k.toInt() * (k.has('%') ? 2.55 : 1))) / 255;
					r = (255 - c) * k;
					g = (255 - m) * k;
					b = (255 - y) * k;
					a = (a) ? (a.has('%') ? a.toInt() * 2.55 : a.toFloat()) : 1;
				} else if((m = c.match(/hsl\(([0-9]+),*([0-9]+)%,*([0-9]+)%\)/i)) || (m = c.match(/hsla\(([0-9]+),*([0-9]+)%,*([0-9]+)%,([0-9\.]+%?)\)/i))) {
					var h = m[1].toInt() / 360, s = m[2].toInt() / 100, l = m[3].toInt() / 100,
					f = function(m1, m2, h) {
						if(h < 0) h = h + 1;
						if(h > 1) h = h - 1;
						if(h * 6 < 1) return m1 + (m2 - m1) * h * 6;
						if(h * 2 < 1) return m2;
						if(h * 3 < 2) return m1 + (m2 - m1) * (2 / 3 - h) * 6;
						return m1;
					};
					s = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
					l = l * 2 - s;
					r = f(l, s, h + 1 / 3) * 255;
					g = f(l, s, h) * 255;
					b = f(l, s, h - 1 / 3) * 255;
					a = m[4];
					a = (a) ? (a.has('%') ? a.toInt() * 2.55 : a.toFloat()) : 1;
				}
			} else if(c.constructor == Array) {
				r = c[0];
				g = c[1];
				b = c[2];
				a = c[3];
				if(!is(a)) a = 1;
			} else if(c.red || c.green || c.blue || c.alpha) {
				r = c.red;
				g = c.green;
				b = c.blue;
				a = c.alpha;
			}
			this.red = r.bound(0, 255);
			this.green = g.bound(0, 255);
			this.blue = b.bound(0, 255);
			this.alpha = a.bound(0, 1);
		}
		return false;
	},
	media: function() {
		var a = arguments, l = a.length, i, c, r = 0, g = 0, b = 0;
		for(i = l - 1; i >= 0; i--) {
			c = new Color(a[i]);
			r += c.red;
			g += c.green;
			b += c.blue;
		}
		this.set([r / l, g / l, b / l]);
	},
	hex: function(a) {
		var f = function(o) {
			o = o.bound(0, 255);
			return (o < 16 ? '0' : '')  + o.toString(16);
		};
		return ('#' + f(this.red) + f(this.green) + f(this.blue) + (a ? f(this.alpha * 255) : '')).toUpperCase();
	},
	rgb: function() {
		return 'rgb(' + this.red + ',' + this.green + ',' + this.blue + ')';
	},
	rgba: function() {
		return 'rgba(' + this.red + ',' + this.green + ',' + this.blue + ',' + this.alpha + ')';
	},
	sepia: function() {
		var r = this.red, g = this.green, b = this.blue;
		return new Color([
			((r * 0.393) + (g * 0.769) + (b * 0.189)).round(),
			((r * 0.349) + (g * 0.686) + (b * 0.168)).round(),
			((r * 0.272) + (g * 0.534) + (b * 0.131)).round(),
			this.alpha
		]);
	},
	negative: function(c) {
		return new Color([255 - this.red, 255 - this.green, 255 - this.blue, this.alpha]);
	},
	grayscale: function(f) {
		var a = this.red, b = this.blue, c = this.green, r;
		switch(f) {
			case 1: case 'SimpleAverage':
				r = [((a + b + c) / 3).round(),
					((a + b + c) / 3).round(),
					((a + b + c) / 3).round()];
			break;
			case 2: case 'WeightAverage':
				r = [((3 * a) + (4 * c) + (2 * b) / 9).round(),
					((3 * a) + (4 * c) + (2 * b) / 9).round(),
					((3 * a) + (4 * c) + (2 * b) / 9).round()];
			break;
			case 3: case 'CCIRRec709':
				r = [((0.2125 * a) + (0.7154 * b) + (0.0721 * c)).round(),
					((0.2125 * a) + (0.7154 * b) + (0.0721 * c)).round(),
					((0.2125 * a) + (0.7154 * b) + (0.0721 * c)).round()];
			break;
			default: case 4: case 'NtscPal':
				r = [((0.299 * a) + (0.587 * b) + (0.114 * c)).round(),
					((0.299 * a) + (0.587 * b) + (0.114 * c)).round(),
					((0.299 * a) + (0.587 * b) + (0.114 * c)).round()];
			break;
		}
		r[3] = this.alpha;
		return new Color(r);
	},
	colorize: function(f) {
		f = new Color(f);
		var a = this.red, b = this.green, c = this.blue, x = f.red, y = f.green, z = f.blue;
		return new Color([
			((a * (x / 255)) + (b * (x / 255)) + (c * (x / 255))).round(),
			((a * (y / 255)) + (b * (y / 255)) + (c * (y / 255))).round(),
			((a * (z / 255)) + (b * (z / 255)) + (c * (z / 255))).round(),
			this.alpha
		]);
	},
	color: function(f) {
		var r = this.red, g = this.green, b = this.blue, a = this.alpha;
		f = new Color(f);
		return new Color([
			r + (r / 100 * f.red).round(),
			g + (g / 100 * f.green).round(),
			b + (b / 100 * f.blue).round(),
			this.alpha
		]);
	},
	contrast: function(f) {
		var n = function(v) {
			return (((v / 255) - 0.5) * (1 + (f / 100).pow(2)) + 0.5) * 255;
		};
		return new Color([n(this.red), n(this.green), n(this.blue), this.alpha]);
	},
	brightness: function(c, f) {
		return new Color([
			this.red + (255 / 100 * f).round(),
			this.green + (255 / 100 * f).round(),
			this.red + (255 / 100 * f).round(),
			this.alpha
		]);
	},
	toString: function() {
		return this.hex();
	}
});

Color.isColor = function(s) {
	return s.match(/((rgb|rgba|hsl|hsla|cmyk|cmyka)\([0-9]%?,[\s]*[0-9]+%?,[\s]*[0-9]+%?(,[\s]*[0-9\.]+)?\)|#[0-9A-F]{3,8})/gi);
};


var ViewPort = {
	_onOpen: [],
	_onClose: [],
	config: {},
	init: function(c){
		if (!I('aidajs_viewport')) {
			ViewPort.config = c || {};
			APPS_LAYER.before(['div', {
				style: {
					backgroundColor: '#000000',
					color: '#FFFFFF',
					width: '100%',
					position: 'absolute',
					top: '0px',
					left: '0px',
					display: 'none',
					zIndex: '25',
					opacity: '0'
				},
				id: 'aidajs_viewport',
				onclick: function(){
					ViewPort.close();
				}
			}]);
			ViewPort.setSizes();
			Event.add(window, 'resize', ViewPort.setSizes);
		}
	},
	setSizes: function() {
		I('aidajs_viewport').style.height = Env.pageSize()[1] + 'px';
	},
	open: function(e) {
		ViewPort.init();
		var c = ViewPort.config, a = ViewPort._onOpen, v = I('aidajs_viewport');
		if(!v.hasClass('open')) {
			ViewPort.setSizes();
			v.morph({
				styles: {
					opacity: [0, (c.opacity || 0.8)],
					display: ['block', 'block']
				},
				time: (c.time || 0.3),
				effect: (c.animation)
			});
			a.each(function(f){
				f[0].call(f[1], e);
			});
			v.addClass('open');
		}
	},
	close: function(e) {
		ViewPort.init();
		var c = ViewPort.config, a = ViewPort._onClose, v = I('aidajs_viewport');
		if(v.hasClass('open')) {
			v.morph({
				styles: {
					opacity: [ACTUAL, 0],
					display: ['block', 'none']
				},
				time: (c.time || 0.3),
				effect: (c.animation)
			});
			a.each(function(f) {
				f[0].call(f[1], e);
			});
			v.removeClass('open');
		}
	},
	addOpenEvent: function(e, b) {
		ViewPort._onOpen.push([e, b || null]);
	},
	addCloseEvent: function(e, b) {
		ViewPort._onClose.push([e, b || null]);
	}
};

var BODY, HEAD, APPS_LAYER;
Event.add(window, 'domloaded', function(){
	HEAD = T('head')[0];
	BODY = T('body')[0];
	APPS_LAYER = D(['div', {
		id: 'aidajs_apps_layer',
		style: {
			position: 'absolute',
			left: '0px',
			top: '0px',
			zIndex: '26'
		}
	}], BODY);
});


// Morph Constants
var ACTUAL = 'actual';
var ORIGINAL = 'original';

var Morph = {
	// Inizializza la proprietâ€¡ privata per gli elementi in morphing
	_init: function(o){
		// Ottengo o creo
		var m = o._morph || (o._morph = {
			// Gli stili originali
			originals: {},
			// Lista animazioni in pausa
			paused: [],
			// La cache interna degli eventi
			cache: []
		}), n = m.paused.shift();
		// I frames dell'animazione attuale
		m.frames = [];
		// Flag per idicare se l'elemento Ã‹ animato
		m.animated = false;
		// Flag per bloccare l'inizio di nuove animazioni
		m.locked = false;
		// La chiave del loop attuale
		m.loop = null;
		if(n)
			o.morph(n);
		return o;
	},
	// Inizializzatore del morphing
	_core: function(u, o) {
		var i = u.getId(),
		mor = u._morph,
		styles = o.styles, style, j, ll,								// Gli stili, lo stile, la chiave e i passi
		fps = o.fps || 25,												// Il framerate
		t = ((o.time || 1) * fps).round(), lastFrame = t - 1,			// Il numero di frames totali
		e = o.effect || Effects.linear, ee,								// L'effetto generale e specifico
		r = (o.wait || 0) * 1000,										// Il tempo di attesa prima dell'inizio
		c = ['in', 'cm', 'mm', 'pt', 'pc', 'em', 'ex', 'px', '%'], unit,// Le unitâ€¡ di misura dei css
		act, orig,
		p, g,
		ii, jj, yy,
		ss, ff,
		m, mm = null,
		exec = [], args = [], ar;

		for(j in styles) {
			// Controllo che lo stile sia un array
			style = ((style = styles[j]).constructor != Array) ? [style] : style.copy();

			// Ottengo lo stile attuale
			act = u.getStyle(j);

			// Se lo stile attuale Ã‹ un colore diverso nel formato rg o hsl lo converto
			/*if(Color.isColor(act))
				act = new Color(act).hex();*/

			// Ottengo lo stile originale e nel caso lo setto
			orig = mor.originals[j];
			orig = (!is(orig)) ? (mor.originals[j] = act) : orig;

			// Sostituisco gli stili attuali e originali
			style = style.replace(ACTUAL, act).replace(ORIGINAL, orig);

			// Se il primo elemento Ã‹ una funzione la estraggo e la considero come effetto
			ee = (typeof style[0] == 'function') ? style.shift() : e;

			// Se il primo elemento Ã‹ una unitâ€¡ di misura la estraggo e la conservo
			unit = (c.has(style[0])) ? style.shift() : '';

			// Lunghezza dell'array
			ll = style.length;

			// Indice di scorrimento dei frame
			yy = 0;

			// Se Ã‹ un colore
			//if(Color.isColor(style[0])) {
			if(j.toLowerCase().has('color')) {
				if(ll < 2) {
					style = [act].concat(style);
					ll++;
				}
				p = (t / (ll - 1)).round();
				var s0, s1, s2, f0, f1, f2;
				for(ii = 0; ii < (ll - 1); ii++) {

					// Ottengo i colori 2 alla volta
					ss = new Color(style[ii]);
					s0 = ss.red;
					s1 = ss.green;
					s2 = ss.blue;

					ff = new Color(style[ii + 1]);
					f0 = ff.red;
					f1 = ff.green;
					f2 = ff.blue;

					g = (ii > 0) ? p + 1 : p;

					for(jj = 0; jj < g; jj++) {
						if(ii === 0 || (ii > 0 && jj > 0)) {
							m = (new Color([
								(ee(jj, s0, (f0 - s0), g - 1)).floor(),
								(ee(jj, s1, (f1 - s1), g - 1)).floor(),
								(ee(jj, s2, (f2 - s2), g - 1)).floor()
							])).rgb();
							if (m !== mm) {
								ar = args[yy];
								if (!ar)
									exec[yy] = args[yy] = '';
								exec[yy] += 's.' + j + '="' + m + '";';
								args[yy] += ((!ar) ? '' : ',') + '"' + j + '":"' + m + '"';
								mm = m;
							}
							yy++;
						}
					}
				}
			} else if(unit || typeof style[0] == 'number') {
				if(ll < 2) {
					style = [(act+'').cleanSize()].concat(style);
					ll++;
				}

				p = (t / (ll - 1)).round();

				for (ii = 0; ii < (ll - 1); ii++) {
					// Ottengo i passi 2 alla volta
					ss = (style[ii] + '').cleanSize();
					ff = (style[ii + 1] + '').cleanSize();
					g = (ii > 0) ? p + 1 : p;
					for (jj = 0; jj < g; jj++) {
						if (ii === 0 || (ii > 0 && jj > 0)) {
							m = ee(jj, ss, (ff - ss), g - 1);
							if (!isNaN(m)) {
								m = ((unit == 'em' || unit === '') ? (m * 100).floor() / 100 : m.floor()) + unit;
								if ((m || m === 0) && m !== mm) {
									ar = args[yy];
									if (!ar)
										exec[yy] = args[yy] = '';
									exec[yy] += (j == 'opacity') ? 'u.setOpacity(' + m + ');' : 's.' + j + '="' + m + '";';
									args[yy] += ((!ar) ? '' : ',') + '"' + j + '":"' + m + '"';
									mm = m;
								}
							}
							yy++;
						}
					}
				}
			} else {
				if (ll < 2) {
					style = [style[0], style[0]];
					ll++;
				}
				p = (t / (ll - 1)).round();

				m = style[0];
				if(!args[0])
					exec[0] = args[0] = '';
				exec[0] += 's.' + j + '="' + m + '";';
				args[0] += '"' + j + '":"' + m + '"';

				for (ii = 1; ii < lastFrame; ii++) {
					if (ii % p === 0) {
						m = style[(ii / p)];
						ar = args[ii];
						if (!ar)
							exec[ii] = args[ii] = '';
						exec[ii] += 's.' + j + '="' + m + '";';
						args[ii] += ((!ar) ? '' : ',') + '"' + j + '":"' + m + '"';
					}
				}

				m = style[ll - 1];
				ar = args[lastFrame];
				if(!ar)
					exec[lastFrame] = args[lastFrame] = '';
				exec[lastFrame] += 's.' + j + '="' + m + '";';
				args[lastFrame] += ((!ar) ? '' : ',') + '"' + j + '":"' + m + '"';
			}

			/* Non dovrebbe piË˜ servire, mah
			if(unit)
				style = [unit].concat(style);
			if(e !== ee)
				style = [ee].concat(style);
			styles[j] = style;*/

		}

		// Istanzio le nuove variabili
		var oSt = o.onstart, oFi = o.onfinish, oCh = o.onchange, oFr = o.onframe,
		oAr, k = 0, str, frames = [], fCount = 0,
		init = 'var u = document.getElementById("' + i + '"), s = u.style, m = u._morph;';

		j = 0;
		fps = 1000 / fps;

		// onStart // per il frame iniziale, prima di settare i nuovi stili
		if(oSt) {
			mor.cache[k] = oSt;
			oSt = 'm.cache[' + k++ + '].apply(u,';
		}
		// onChange // per i frame non vuoti
		if (oCh) {
			mor.cache[k] = oCh;
			oCh = 'm.cache[' + k++ + '].apply(u,';
		}
		// onFrame // per ogni frame
		if (oFr) {
			mor.cache[k] = oFr;
			oFr = 'm.cache[' + k++ + '].apply(u,';
		}
		// onFinish // per il frame finale, dopo aver settato gli stili
		if (oFi) {
			mor.cache[k] = oFi;
			oFi = 'm.cache[' + k++ + '].apply(u,';
		}

		while(j < t) {
			str = '';

			// Lista degli argomenti passati ai vari eventi
			oAr = '[{' + (args[j] || '') + '},' + (j + 1) + ',' + t + ']);';

			// Se Ã‹ il frame 0 e non coincide con l'ultimo, inserisco onstart
			if (j === 0 && j != lastFrame && oSt)
				str += oSt + oAr;

			// Ottengo i nuovi cambiamenti
			m = exec[j];

			// Inserisco i nuovi stili
			str += (m || '');

			// Se c'Ã‹ un cambiamento in questo frame o Ã‹ l'ultimo frame inserisco onchange
			if (oCh && (m || j == lastFrame))
				str += oCh + oAr;

			// Inserisco onframe
			if (oFr)
				str += oFr + oAr;

			// Se Ã‹ l'ultimo frame
			if (j == lastFrame) {
				// Resetto la proprietâ€¡ con i dati dell'animazione
				str += 'Morph._init(u);';
				if (oFi)
					str += oFi + oAr;
			}

			// Passo al frame successivo
			j++;

			if (str) {
				frames[fCount++] = setTimeout(init + 'm.frames.shift();' + str, ((fps * j) + r).round());
				//I('try').value += init + 'm.frames.shift();' + str + '\n';
			}
		}

		mor.frames = frames;
		mor.locked = o.locked || false;
		mor.animated = true;
	},
	_implements: {
		morph: function(o){
			var m = this._morph || Morph._init(this);
			if (m.animated) {
				if (o.stop && !m.locked) 
					Morph._core(this.stopMorph(), o);
				else 
					m.paused.push(o);
			}
			else 
				Morph._core(this, o);
			return this;
		},
		forceMorph: function(o){
			o.stop = true;
			return this.morph(o);
		},
		loopMorph: function(o){
			var oFi = o.onfinish;
			o.onfinish = function(){
				if (oFi) 
					oFi.apply(this);
				this.morph(o);
			};
			this.morph(o);
		},
		// Ferma il morphing
		stopMorph: function(){
			var m, f, g, l;
			if ((m = this._morph)) {
				f = m.frames;
				l = f.length;
				for (i = 0; i < l; i++) 
					clearTimeout(f[i]);
				m.paused = [];
			}
			Morph._init(this);
			return this;
		}
	}
};

// Implemento il morph
Element.implement(Morph._implements);
delete Morph._implements;

// Animazioni avanzate
var Fx = {
	_implements: {
		//### Opacity
		opacityUp: function(o){
			((o || (o = {})).styles || (o.styles = {})).opacity = [ACTUAL, 1];
			return this.morph(o);
		},
		opacityDown: function(o){
			((o || (o = {})).styles || (o.styles = {})).opacity = [ACTUAL, 0];
			return this.morph(o);
		},
		opacityShift: function(o){
			return this[(this.getOpacity() < 0.5 ? 'opacityUp' : 'opacityDown')](o);
		},
		//### Opacity Pulse
		opacityPulse: function(o){
			var r = [ACTUAL], t = (o || (o = {})).hits || 3;
			for (i = 0; i < t; i++)
				r = r.concat([0, 1]);
			(o.styles || (o.styles = {})).opacity = r;
			return this.morph(o);
		},
		//### Blind
		blindInit: function(c){
			var s = this.style;
			s.overflow = 'hidden';
			s.display = 'block';
			if (c)
				s.height = '0px';
			return this;
		},
		blindUp: function(o){
			this.blindInit();
			((o || (o = {})).styles || (o.styles = {})).height = ['px', ACTUAL, 0];
			if (!o.effect)
				o.effect = Effects.outCubic;
			return this.morph(o);
		},
		blindDown: function(o){
			this.blindInit();
			((o || (o = {})).styles || (o.styles = {})).height = ['px', ACTUAL, this.realHeight()];
			if (!o.effect)
				o.effect = Effects.outCubic;
			return this.morph(o);
		},
		blindShift: function(o){
			return this[(this.blindState() < 0.5 ? 'blindUp' : 'blindDown')](o);
		},
		blindState: function(){
			return this.getStyle('height').cleanSize() / this.realHeight();
		},
		// Effetti complessi
		foldUp: function(o){
			var e = (o || (o = {})).effect || Effects.outCubic, z = (o.styles ||
			{}), t = (o.time || 1) / 2, n = this.getStyle('height').cleanSize(), h = this.realHeight();
			this.blindInit();

			return this.morph({
				onstart: o.onstart,
				styles: {
					height: ['px', ACTUAL, 5]
				},
				effect: e,
				time: t
			}).morph({
				styles: {
					width: ['px', ACTUAL, 0],
					height: ['px', ACTUAL, 0]
				},
				onfinish: o.finish,
				effect: e,
				time: t
			});
		},
		drop: function(o){
			var s = this.getStyles('height', 'position', 'top'), t = s.top.cleanSize(), h = s.height.cleanSize();
			if (s.position != 'absolute')
				this.style.position = 'relative';
			s = (o || (o = {})).styles || (o.styles = {});
			if (!o.effect)
				o.effect = Effects.outCubic;
			s.opacity = [1, 0];
			s.top = ['px', t, t + h];
			return this.morph(o);
		},
		vanish: function(o){
			var s = this.getStyles('width', 'height', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'fontSize'),
			w = s.width.cleanSize(true), h = s.height.cleanSize(true), f = s.fontSize.cleanSize(true);
			if (f[0] === 0)
				f = [1, 'em'];
			s = (o || (o = {})).styles || (o.styles = {});
			if (!o.effect)
				o.effect = Effects.outCubic;
			s.opacity = [1, 0];
			s.width = [w[1], w[0], (w[0] * 2)];
			s.height = [h[1], h[0], (h[0] * 2)];
			s.fontSize = [f[1], f[0], (f[0] * 2)];
			o.onframe = function(){
				var s = this.getStyles('width', 'height'), z = this.style;
				z.marginTop = z.marginBottom = ((h[0] - s.height.cleanSize()) / 2) + h[1];
				z.marginLeft = z.marginRight = ((w[0] - s.width.cleanSize()) / 2) + w[1];
			};
			this.morph(o);
		},
		vclose: function(o){
			var s = this.getStyles('height', 'marginTop', 'marginBottom', 'fontSize'),
			n = s.height.cleanSize(), f = s.fontSize.cleanSize(true), h = this.realHeight(i), z = this.style;
			s = (o || (o = {})).styles || (o.styles = {});
			if (!o.effect)
				o.effect = Effects.outCubic;
			this.blindInit();

			h = (h > n) ? h : n;

			if(f[0] === 0)
				f = [1, 'em'];

			//s.opacity = [1, 0];
			//s.fontSize = [f[1], f[0], 0];

			s.height = ['px', h, 0];

			o.onframe = function(s){
				var a = (s.height || this.getStyle('height')).cleanSize();
				z.marginTop = ((h - a) / 2) + 'px';
				z.marginBottom = ((h - a) / 2) + 'px';
			};
			Morph.set(o);
		},
		animage: function(o){
			if (o) {
				var u = o.url, w = o.width, h = o.height, v = o.vertical, f = o.frames, d = 1000 / (o.fps || 25), p = (o.pause || 0) * 1000, l = o.loop || Infinity, i = 'animage_' + String.random(), s = o.style ||
				{}, g = new Image(), iw, ih, self = this;

				o = D(['div', {
					style: {
						//display: 'inline-block',
						width: w + 'px',
						height: h + 'px',
						backgroundImage: 'url("' + u + '")',
						backgroundRepeat: 'no-repeat',
						backgroundPosition: '0px 0px'
					},
					id: i,
					className: 'animage'
				}], self);

				g.onload = function(){
					iw = g.width;
					ih = g.height;

					if (v) {
						f = f || (ih / h).floor();
						w = 0;
					}
					else {
						f = f || (iw / w).floor();
						h = 0;
					}

					var a = 0, s = o.style, m = function(){
						var t = d;
						if (a === 0 || a == f) {
							a = 0;
							t += p;
							l--;
						}
						if (l > 0) {
							s.backgroundPosition = "-" + (w * a) + "px -" + (h * a) + "px";
							a++;
							setTimeout(m, t);
						}
					};

					m();
				};
				g.src = u;
			}
			return this;
		},
		colors: function(){
			return this.getStyles('backgroundColor', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor', 'color');
		},
		hide: function() {
			this.style.display = 'none';
			return this;
		},
		show: function() {
			this.style.display = 'block';
			return this;
		},
		tooltip: function(o) {

			var e = this,
			// Cerco il titolo da inserire nell'attributo 'title' se non è stato specificato
			t = o.title || this.getAttribute('title'),
			// Cerco il contenuto da inserire nell'attributo 'alt' se non è stato specificato
			m = o.content || this.getAttribute('alt'),
			// Se non è stato settato un target uso l'elemento del tooltip
			g = o.target || this,
			oSh = o.onshow, oMo = o.onmove, oHi = o.onhide, c = o.className || 'tooltip',
			// Cerco eventuali offset
			f = o.offset || {}, fx = f.x || 16, fy = f.y || 16,
			s = o.style || {}, p = o.position, b, d;

			// Aggiungo position:relative agli stili
			s.position = 'relative';

			// Creo l'elemento del tooltip e gli eventuali per il titolo e contenuto
			b = ['div', {
				style: s,
				className: c
			}];

			if(t)
				b.push(['div', {className: 'title'}, t]);
			if(m)
				b.push(['div', {className: 'content'}, m]);

			// Creo l'elemento tooltip
			b = D(b);

			// Creo l'elemento contenitore del tooltip
			d = D(['div', {
					style: {
						position: 'absolute',
						top: '0px',
						left: '0px',
						zIndex: '1000',
						display: 'none'
					}
				},
				b
			], APPS_LAYER);

			if (p && p.constructor == Array) {
				s = d.style;
				s.visibility = 'hidden';
				s.display = 'block';
				n = b.sizes();
				s.visibility = '';
				s.display = 'none';

				c = p[1];

				// Allineamento orrizzontale
				if (c == 2 || c == 5 || c == 8)
					fx -= Math.round(n[0] / 2);
				else if (c == 3 || c == 6 || c == 9)
					fx -= n[0];

				// Allineamento verticale
				if (c >= 4 && c <= 6)
					fy -= Math.round(n[1] / 2);
				if (c >= 7 && c <= 9)
					fy -= n[1];

				p = p[0];
			}

			// Setto gli eventi
			Event.add(this, 'mouseover', function(ev){
				var s = d.style, m = p ? g.position({
					alignment: p
				}) : Event.mousePosition(ev);

				s.left = (m[0] + fx) + 'px';
				s.top = (m[1] + fy) + 'px';

				if (oSh)
					oSh.call(b, ev);

				s.display = 'block';
			});

			Event.add(this, 'mousemove', function(ev){
				var s = d.style, m = p ? g.position({
					alignment: p
				}) : Event.mousePosition(ev);

				s.left = (m[0] + fx) + 'px';
				s.top = (m[1] + fy) + 'px';

				if (oMo)
					oMo.call(b, ev);
			});

			Event.add(this, 'mouseout', function(ev){
				if (oHi)
					oHi.call(b, ev);
				else
					d.style.display = 'none';
			});
			return this;
		}
	},
	// #############################################
	// Non usa il morph
	makeTabs: function(a) {
		for(var l = (a = P(a)).length, f = false, i = 0, b, s, d; i < l; i++) {
			b = I(a[i]);
			if(isElement(b, 'a')) {
				d = I(b.getAttribute('href').split('#')[1]);
				if (d) {
					s = d.style;
					if (!f) {
						s.display = 'block';
						b.addClass('active');
						f = true;
					}
					else {
						s.display = 'none';
						s.height = '0px';
						d.setOpacity(0);
					}
					Event.add(b, 'click', function(e){
						if (this.hasClass('active'))
							return false;

						var h = null, j = 0, b, s = I(this.getAttribute('href').split('#')[1]);
						for (j = 0; j < l; j++) {
							b = a[j];
							if (isElement(b, 'a')) {
								if (b.hasClass('active')) {
									h = I(b.getAttribute('href').split('#')[1]);
									b.removeClass('active');
									break;
								}
							}
						}

						if (h) {
							h.blindUp({
								styles: {
									opacity: [1, 0],
									display: ['block', 'none']
								},
								onfinish: function(){
									s.blindDown({
										styles: {
											opacity: [0, 1],
											display: ['block']
										},
										time: 0.5
									});
								},
								time: 0.5
							});
						}
						else {
							s.blindDown({
								styles: {
									opacity: [0, 1],
									display: ['block']
								},
								time: 0.5
							});
						}
						this.addClass('active');
						return false;
					});

				}
			}
		}
	},
	IEAlphaPngFix: function() {
		var e = Agent.MSIE,a = arguments;
		if(!e || e < 5.5 || e >= 7)
			return false;
		(a.length > 0 ? Arr(a) : T('img')).forEach(function(o) {
			o = I(o);
			var s = o.src;
			if (s.match(/^[^\?]+\.png(\?.*)?(#.*)?$/gi)) {
				var a = {}, i = o.id, c = o.className, g = o.align, t, n;
				if (i)
					a.id = i;
				if (c)
					a.className = c;
				if ((t = o.title || o.alt))
					a.title = t;

				a.style = 'width:' + o.width + 'px;height:' + o.height + 'px;display:inline-block;' +
					(g == 'left' ? 'float:left;' : (g == 'right' ? 'float:right;' : '')) +
					(o.parentElement.href ? 'cursor:hand;' : '') + o.style.cssText +
					';filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + s + '\', sizingMethod=\'scale\');';

				n = D(['span', a]);
				o.after(n);
				Event.clone(o, n);
				o.remove();
			}
		});
	}
};

Element.implement(Fx._implements);
delete Fx._implements;

// Easing Equations from Robert Penner http://www.robertpenner.com/
var Effects = {
	linear: function (t, b, c, d) {
		return c*t/d + b;
	},
	inQuad: function(t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	outQuad: function(t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	inOutQuad: function(t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	inCubic: function (t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	outCubic: function (t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	inOutCubic: function (t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	inQuart: function (t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	outQuart: function (t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	inOutQuart: function (t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	inQuint: function (t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	outQuint: function (t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	inOutQuint: function (t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	inSine: function (t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	outSine: function (t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	inOutSine: function (t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	inExpo: function (t, b, c, d) {
		return (t===0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	outExpo: function (t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	inOutExpo: function (t, b, c, d) {
		if (t===0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	inCirc: function (t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	outCirc: function (t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	inOutCirc: function (t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	inElastic: function (t, b, c, d, a, p) {
		if (t===0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*0.3; if(!a) a=0;
		var s;
		if (a < Math.abs(c)) { a=c; s=p/4; }
		else s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	outElastic: function (t, b, c, d, a, p) {
		if (t===0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*0.3; if(!a) a=0;
		var s;
		if (a < Math.abs(c)) { a=c; s=p/4; }
		else s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	inOutElastic: function (t, b, c, d, a, p) {
		if (t===0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(0.3*1.5); if(!a) a=0;
		var s;
		if (a < Math.abs(c)) { a=c; s=p/4; }
		else s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -0.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
	},
	inBack: function (t, b, c, d, s) {
		if (s === undefined)
			s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	outBack: function (t, b, c, d, s) {
		if (s === undefined)
			s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	inOutBack: function (t, b, c, d, s) {
		if (s === undefined) s = 1.70158;
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	inBounce: function (t, b, c, d) {
		return c - Effects.outBounce (d-t, 0, c, d) + b;
	},
	outBounce: function (t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
		}
	},
	inOutBounce: function (t, b, c, d) {
		if (t < d/2) return Effects.inBounce (t*2, 0, c, d) * 0.5 + b;
		return Effects.outBounce (t*2-d, 0, c, d) * 0.5 + c*0.5 + b;
	}
};

// Estendo le Easing Equations Basi con quelle personali
Object.extend(Effects, {
	circleY: function(t, b, c, d) {
		return (c * Math.sin(t / d * 2 * Math.PI)) + b;
	},
	circleX: function(t, b, c, d) {
		return (c * Math.cos(t / d * 2 * Math.PI)) + b;
	},
	outSpiralY: function(t, b, c, d) {
		return ((c / d * t) * Math.sin(t / d * 2 * Math.PI)) + b;
	},
	outSpiralX: function(t, b, c, d) {
		return ((c / d * t) * Math.cos(t / d * 2 * Math.PI)) + b;
	},
	inSpiralY: function(t, b, c, d) {
		return ((c / d * (d-t)) * Math.sin(t / d * 2 * Math.PI)) + b;
	},
	inSpiralX: function(t, b, c, d) {
		return ((c / d * (d-t)) * Math.cos(t / d * 2 * Math.PI)) + b;
	}
});

var _DRAG_ACTIVE = null;
var _DRAG_INIT = false;

// Drag
Element.implement({
	enableDrag: function() {
		var d = this._drag;
		if(d)
			d.disabled = false;
		return this;
	},
	disableDrag: function() {
		var d = this._drag;
		if(d)
			d.disabled = true;
		return this;
	},
	makeDraggable : function(o) {
		var u = this;

		u._drag = {
			xS: 0,
			yS: 0,
			xD: 0,
			yD: 0,
			mD: 0,
			dragging: false,
			onstart: o.onstart,
			onmove: o.onmove,
			onfinish: o.onfinish,
			disabled: false
		};

		// Inizializzo il drag se non Ã‹ giâ€¡ stato fatto
		if(!_DRAG_INIT) {
			// Al movimento del mouse nel documento
			Event.add(document, 'mousemove', function(e){
				if (_DRAG_ACTIVE) {
					var c = _DRAG_ACTIVE._drag;
					if (!c.disabled) {
						if (!e)
							e = window.event;
						var x = parseInt(e.clientX, 10), y = parseInt(e.clientY, 10), oMo = c.onmove,
						xD = c.xS - x, yD = c.yS - y, mD = Math.sqrt((xD * xD) + (yD * yD));
						c.xD = xD;
						c.yD = yD;
						c.mD = mD;
						c.xS = x;
						c.yS = y;
						if (oMo)
							oMo.call(_DRAG_ACTIVE, e, xD, yD, mD);
					}
					return Event.stop(e);
				}
			});
			// Al rilascio del mouse nel documento
			Event.add(document, 'mouseup', function(e) {
				if(_DRAG_ACTIVE) {
					var c = _DRAG_ACTIVE._drag;
					if(!c.disabled) {
						var oFi = c.onfinish;
						c.dragging = false;
						if (oFi)
							oFi.call(_DRAG_ACTIVE, (e || window.event));
						_DRAG_ACTIVE = null;
					}
				}
			});
		}
		// Alla pressione del mouse sopra all'elemento
		Event.add(u, 'mousedown', function(e){
			var c = this._drag;
			if (!c.disabled) {
				var s = c.onstart;
				c.xS = parseInt(e.clientX, 10);
				c.yS = parseInt(e.clientY, 10);
				c.dragging = true;
				if (s)
					s.call(this, (e || window.event));
				_DRAG_ACTIVE = this;
			}
		});
		/*
		// Al rilascio del mouse sopra all'elemento
		Event.add(u, 'mouseup', function() {
			var c = this._xDrag;
			if(!c.disabled) {
				var f = o.onfinish;
				c.dragging = false;
				if(f) f.apply(this);
				Drag._active = null;
			}
		});
		*/
		this.disableSelect();
	}
});

var Scroll = Cinematic.extend({
	__construct: function(o) {
		
		var s = Env.pageScroll(), sx = s[0], sy = s[1], f = Scroll.validate(o.x || sx, o.y || sy), dx = f[0] - sx, dy = f[1] - sy, e = o.effect || Effects.linear, px, py;
		
		alert(s + '\n' + f);
		
		this._init(function(i, t){
			
			px = e(i, sx, dx, t);
			py = e(i, sy, dy, t);
			
			window.scrollTo(px, py);
		}, o);
		this.start();
		
	}
});
Scroll.validate = function(x, y) {
	var m = Env.maxScroll();
	return [Math.min(x || 0, m[0]), Math.min(y || 0, m[1])];
};
(function(){
	if(!window.XMLHttpRequest) {
		window.XMLHttpRequest = function() {
			for(var a = [
				'Microsoft.XMLHTTP',
				'MSXML2.XMLHTTP',
				'MSXML2.XMLHTTP.3.0',
				'Msxml2.XMLHTTP.4.0',
				'Msxml2.XMLHTTP.5.0',
				'Msxml2.XMLHTTP.6.0',
				'Msxml2.XMLHTTP.7.0'
			], i = a.length, c, x; i >= 0 && !x; i--) {
				c = a[i];
				try {
					x = new ActiveXObject(c);
				} catch(e) {
					x = null;
				}
			}
			return x;
		};
	}
})();

var AsyncRequest = Class({
	__construct: function(o) {
		this.reset();
		this.createRequest();
		Object.extend(this.options, o || {});
	},
	resetData: function() {
		this.xhr = null;
		this.GETs = {};
		this.POSTs = {};
		this.HEADs = {};
		this.path = '';
		this.response = {
			text : '',
			XML : null,
			headers : {}
		};
		this.status = {
			code : 0,
			text : 'Unknown',
			type : 'Unknown'
		};
		this.options = {
			timeout: 0,
			escapeCache: true,
			urlEncoded: true,
			encoding: 'utf-8'
		};
	},
	resetFunctions: function() {
		this.onRequest = function() {};
		this.onLoaded = function() {};
		this.onInteractive = function() {};
		this.onSuccess = function() {};
		this.onFailure = function() {};
		this.onAbort = function() {};
		this.onException = function() {};
	},
	reset: function() {
		this.resetFunctions();
		this.resetData();
	},
	createRequest: function() {
		var x = null;
		try {
			x = new XMLHttpRequest();
		} catch(e) {
			x = null;
			this.onException(e, c);
		}
		return (this.xhr = x) ? true : false;
	},
	addGetData: function(o, v) {
		var p = this.GETs, i;
		if(typeof o == 'object')
			for(i in o)
				p[i] = o[i];
		else
			p[o] = v;
	},
	addPostData: function(o, v) {
		var p = this.POSTs, i;
		if(typeof o == 'object')
			for(i in o)
				p[i] = o[i];
		else
			p[o] = v;
	},
	urlPath: function(u) {
		this.path = u.has('?') ? u.split('?')[0] : u;
	},
	urlParameters: function(u) {
		if(!u.has('?'))
			return;
		var p = u.split('?')[1].replace('&amp;', '&').split('&'), l = p.length, i, v, o = {};
		for(i = 0; i < l; i++) {
			v = p[i].split('=');
			o[v[0]] = v[1];
		}
		this.addGetData(o);
	},
	url: function(u) {
		this.urlPath(u);
		this.urlParameters(u);
	},
	abort: function() {
		if(!this.running)
			return this;
		this.running = false;
		var x = this.xhr;
		x.abort();
		x.onreadystatechange = function(){};
		this.createRequest();
		this.onAbort();
	},
	setHeaders: function(o, v) {
		var p = this.HEADs, i;
		if(typeof o == 'object')
			for(i in o)
				p[i] = o[i];
		else
			p[o] = v;
	},
	getHeaders: function(){
		var r = {}, n = this.xhr.getAllResponseHeaders().split(/(\n)/gmi), i, l = n.length, h;
		for(i = 0; i < l; i++) {
			h = n[i].trim();
			if(!h)
				continue;
			h = h.split(/:[\s]+/gmi);
			r[h[0]] = h[1];
		}
		return r;
	},
	getStatus: function() {
		var q = this.xhr, c = q.status, t = q.statusText, p;
		if(c) {
			if(!t) {
				t = function(){
					switch (c) {
						case 100:	return 'Continue';
						case 101:	return 'Switching Protocols';
						case 200:	return 'OK';
						case 201:	return 'Created';
						case 202:	return 'Accepted';
						case 203:	return 'Non-Authoritative Information';
						case 204:	return 'No Content';
						case 205:	return 'Reset Content';
						case 206:	return 'Partial Content';
						case 207:	return 'Multi-Status';
						case 300:	return 'Multiple Choices';
						case 301:	return 'Moved Permanently';
						case 302:	return 'Found';
						case 303:	return 'See Other';
						case 304:	return 'Not Modified';
						case 305:	return 'Use Proxy';
						case 306:	return 'Switch Proxy';
						case 307:	return 'Temporary Redirect';
						case 400:	return 'Bad Request';
						case 401:	return 'Unauthorized';
						case 402:	return 'Payment Required';
						case 403:	return 'Forbidden';
						case 404:	return 'Not Found';
						case 405:	return 'Method Not Allowed';
						case 406:	return 'Not Acceptable';
						case 407:	return 'Proxy Authentication Required';
						case 408:	return 'Request Timeout';
						case 409:	return 'Conflict';
						case 410:	return 'Gone';
						case 411:	return 'Length Required';
						case 412:	return 'Precondition Failed';
						case 413:	return 'Request Entity Too Large';
						case 414:	return 'Request-URI Too Long';
						case 415:	return 'Unsupported Media Type';
						case 416:	return 'Requested Range Not Satisfiable';
						case 417:	return 'Expectation Failed';
						case 449:	return 'Retry With';
						case 500:	return 'Internal Server Error';
						case 501:	return 'Not Implemented';
						case 502:	return 'Bad Gateway';
						case 503:	return 'Service Unavailable';
						case 504:	return 'Gateway Timeout';
						case 505:	return 'HTTP Version Not Supported';
						case 509:	return 'Bandwidth Limit Exceeded';
					}
				}();
			}
			p = function(){
				if(c < 200) return 'Informational';
				if(c < 300) return 'Success';
				if(c < 400) return 'Redirection';
				if(c < 500) return 'Client Error';
				if(c < 600) return 'Server Error';
			}();
		}
		return {
			code : c,
			text : t || 'Unknown',
			type : p || 'Unknown'
		};
	},
	run: function() {
		if(this.xhr) {

			var s = this,
			r = s.response,
			q = s.xhr,
			u = s.timeout,
			e = s.encoding,
			h = s.HEADs,
			g = s.GETs,
			p = s.POSTs,
			o = s.options;

			// Aggiungo headers base
			h['Connection'] = 'close';
			h['X-Ajax-Request'] = 'AIDA-JS';
			h['Accept'] = 'text/javascript, text/html, application/xml, text/xml, */*';

			// Evado la cache
			if (o.escapeCache)
				g['AjdaJsAjaxEscapeCache'] = new Date().getTime();

			var qs = function(p) {
				var a = [], j = 0, i;
				for(i in p)
					a[j++] = encodeURIComponent(i) + "=" + encodeURIComponent(p[i]);
				return a.join('&');
			},
			qg = qs(g),
			qp = qs(p) || null,
			d, k, t, m = (qp || o.urlEncoded) ? 'POST' : 'GET';

			q.onreadystatechange = function() {
				if(u > 0 && !d) {
					u = new Date().getTime() + (u * 1000);
					(function(){
						if(new Date().getTime() >= u)
							s.abort();
						else
							d = setTimeout(arguments.callee, 100);
					})();
				}
				switch(q.readyState) {
					case 1:
						s.onRequest();
					break;
					case 2:
						s.onLoaded();
					break;
					case 3:
						s.onInteractive();
					break;
					case 4:
						// Se esisteva un timer lo termino
						if(d)
							clearTimeout(d);
						var rT, rX, rH;
						// Conservo le informazioni sulla risposta
						rT = r.text = q.responseText;
						rX = r.XML = q.responseXML;
						rH = r.headers = s.getHeaders();
						// Ottengo i dettagli sullo stato
						s.status = d = s.getStatus();
						s.runnig = false;
						s[(d.type == 'Success' ? 'onSuccess' : 'onFailure')](rT, rX, rH, d);
					break;
				}
			};

			// Se è una richiesta via POST imposto l'encoding e il charset
			if(m == 'POST')
				h['Content-type'] = 'application/x-www-form-urlencoded' + (e ? '; charset=' + e : '');

			s.runnig = true;

			// Apro la richiesta
			q.open(m, this.path + (qg ? '?' + qg : ''), true);
			for(k in h) {
				try {
					q.setRequestHeader(k, h[k]);
				} catch (e) {
					this.onException(e, k, h[k]);
				}
			}
			q.send(qp);
		}
	}
});


var XMLSerializer = Class({
	_cdata: false,
	_vars: [],
	__construct: function(c) {
		this._cdata = c;
	},
	// Function to add a new variable
	add: function(v, n) {
		this._vars[this._vars.length] = [v, n];
	},
	serialize: function(h) {
		var a = this._vars, r = '', i, v;
		for(i = a.length - 1; i >= 0; i--) {
			v = a[i];
			r = this._serializer(v[0], v[1]) + r;
		}
		return (h || '<?xml version="1.0" ?>') + (r ? '<vars/>' : '<vars>' + r + '</vars>');
	},
	_serializer: function(v, n) {
		var r = '';
		n = n ? ' name="' + n.toString() + '"' : '';
		switch(typeof v) {
			case 'boolean':
				r = '<boolean' + n + '>' + (v ? 'true' : 'false') + '</boolean>';
			break;
			case 'string':
				if(this._cdata)
					v = '<![CDATA[' + v + ']]>';
				else
					v.replace(/&/g, '&amp;').replace(/</g, '&lt;');
				r = '<string' + n + '>' + v + '</string>';
			break;
			case 'number':
				if(Math.round(v) === v)
					r = '<integer' + n + '>' + v + '</integer>';
				else
					r = '<float' + n + '>' + v + '</float>';
			break;
			case 'object':
				var i, w;
				if (v === null)
					r = '<null' + n + '/>';
				else if (v instanceof Date)
					r = '<date' + n + '>' + v.getTime() + '</date>';
				else if (v instanceof Array) {
					for (i = v.length - 1; i >= 0; i--)
						r = this._serializer(v[i], null) + r;
					r = '<array' + n + '>' + r + '</array>';
				}
				else {
					for (i in v) {
						w = v[i];
						if (typeof(w) == 'function')
							continue;
						r += this._serializer(w, i);
					}
					r = '<associative' + n + '>' + r + '</associative>';
				}
			break;
			default:
			case 'undefined':
				r = '<undefined' + n + '/>';
			break;
		}
		return r;
	}
});
XMLSerializer.serialize = function() {
	var a = arguments, l = a.length, i, s = new XMLSerializer(true);
	for(i = 0; i < l; i++)
		s.addVariable(a[i]);
	return s.serialize();
};

var JSON = {
	encode: function(o){
		switch (typeOf(o)) {
			case 'string':
				var s = {
					'\b': '\\b',
					'\t': '\\t',
					'\n': '\\n',
					'\f': '\\f',
					'\r': '\\r',
					'"': '\\"',
					'\\': '\\\\'
				};
				return '"' +
				o.replace(/["\\\x00-\x1f\x7f-\x9f]/g, function(c){
					return s[c] || '\\u00' + Math.floor(c.charCodeAt() / 16).toString(16) + (c.charCodeAt() % 16).toString(16);
				}) +
				'"';
			case 'array':
			case 'arguments':
			case 'list':
				for (var i = 0, l = o.length, v, r = []; i < l; i++) {
					v = JSON.encode(o[i]);
					if (v)
						r.push(v);
				}
				return '[' + r + ']';
			case 'date':
				var d = function(n){
					return n < 10 ? '0' + n : n;
				};
				return o.getUTCFullYear() + '-' + d(o.getUTCMonth() + 1) + '-' +
				d(o.getUTCDate()) +
				'T' +
				d(o.getUTCHours()) +
				':' +
				d(o.getUTCMinutes()) +
				':' +
				d(o.getUTCSeconds()) +
				'Z';
			case 'number':
				return isFinite(o) && !isNaN(o) ? o + '' : 'null';
			case 'object':
				var i, v, r = [];
				for (i in o) {
					v = JSON.encode(o[i]);
					if (v)
						r.push(JSON.encode(i) + ':' + v);
				}
				return '{' + r + '}';
			case 'null':
			case 'boolean':
				return o + '';
		}
		return false;
	},
	decode: function(s) {
		return (s && typeof s == 'string' && s.isJSON()) ? eval('(' + string + ')') : null;
	}
};



var Ajax = {
	_origTitle: null,
	_cache: [],
	// Ottiene i dati per l'url passato
	_getCached: function(u) {
		var c = Ajax._cache, n = new Date().getTime(), i, e;
		for(i = c.length - 1; i >= 0; i--) {
			e = c[i];
			if(e[0] == u && e[2] > n)
				return e[1];
		}
		return false;
	},
	// Aggiungi i dati dell'url
	_addToCache: function(u, r, t) {
		var c = Ajax._cache, l = c.length, n = (new Date().getTime()) + (t * 1000), i, e;
		for(i = l - 1; i >= 0; i--) {
			e = c[i];
			if(e[0] == u) {
				Ajax._cache[i] = [u, r, n];
				return i;
			}
		}
		Ajax._cache[l] = [u, r, n];
		return l;
	},
	_history: [null],
	_initHistory: function() {
		if(!I('xfa_history_frame')) {
			APP_LAYER.innerHTML +=
				'<div style="margin-left: -9000px">' +
				'<iframe src="./xframe/ajax/foo.html" id="ajax_history_frame" name="ajax_history_frame"></iframe>' +
				'<form id="ajax_history_form" action="./xframe/ajax/foo.html" method="get" target="ajax_history_frame">' +
				'<input type="hidden" name="history" id="ajax_history_input" value="none" /></form></div>';
			Event.add('xfa_history_frame', 'load', function() {
				var c = Dom.window('xfa_history_frame').location.search.toString().match(/.*history=([0-9]+)/i);
				if(c && (c = parseInt(c[1], 10)) && Ajax._actual != c)
					Ajax._historyBack(c);
			});
		}
	},
	_historyBack: function(c) {
		var h = Ajax._history[c];
		if(h) {
			Ajax._actual = c;
			Ajax.get(h[0], h[1]);
		}
	},
	_addToHistory: function(o, a) {
		var c = Ajax._history.length;
		Ajax._initHistory();
		I('xfa_history_input').value = c;
		I('xfa_history_form').submit();
		Ajax._history[c] = [o, a];
		Ajax._actual = c;
	},
	_setTitle: function(t) {
		// Imposto il titolo
		if(t) {
			var o = Ajax._origTitle;
			if(!o)
				Ajax._origTitle = document.title;
			document.title = t;
		}
	},
	get: function(o, r) {
		var i = I(o.element),
			u = o.url,
			eF = Function.empty,
			oS = o.onSuccess || eF,
			c = o.cache,
			h = o.history,
			t = o.time || 1800;

		// Se l'history Ã‹ abilitata e la chiamata proviene da li eseguo
		if(h && r)
			return oS.apply(i, [r[0], r[1], r[2]]);

		// Provo a cercare nella cache se abilitata
		if(c && (r = Ajax._getCached(u)))
			return oS.apply(i, [r[0], r[1], r[2]]);

		// Creo la chiamata
		var a = new AsyncRequest();
		a.url(u, true);
		a.addGetData(o.get || {});
		a.addPostData(o.post || {});
		a.onRequest = o.onRequest || eF;
		a.onFailure = o.onFilure || eF;
		a.onLoading = o.onLoading || eF;
		a.onInteractive = o.onInteractive || eF;
		a.onAbort = o.onAbort || eF;
		a.onSuccess = function() {
			var a = arguments;
			// Aggiungo alla cache se impostato
			if(c)
				Ajax._addToCache(u, a, t);
			// Aggiungo all'history se impostato
			if(h)
				Ajax._addToHistory(u, o, a);
			oS.apply(null, a);
			Ajax._setTitle(o.title);
		};
		a.run();
	},
	hiddenFrame: function(o) {
		var i = (o || (o = {})).id || String.randomId();
		(I(o.into) || APPS_LAYER).innerHTML +=
			'<div style="margin-left:-9000px;overflow:hidden;height:0px;width:0px;"><iframe src="' + (o.url || '') + '" id="' + i + '" name="' + (o.name || i) + '"></iframe></div>';
		return I(i);
	}
};
/*
 * Implementations of
 *
 * Base64 encode / decode
 * Javascript crc32
 * MD5 (Message-Digest Algorithm)
 * Secure Hash Algorithm (SHA1)
 * Secure Hash Algorithm (SHA256)
 * UTF-8 data encode / decode
 *
 * http://www.webtoolkit.info/
 */

(function() {
	var Sp = String.prototype;

	Sp.base64encode = function() {
		var input = this.utf8encode(), l = input.length,
		output = "", chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0,
		k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

		while(i < l) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if(isNaN(chr2)) enc3 = enc4 = 64;
			else if(isNaN(chr3)) enc4 = 64;

			output = output + k.charAt(enc1) + k.charAt(enc2) + k.charAt(enc3) + k.charAt(enc4);
		}

		return output;
	};

	Sp.base64decode = function() {
		var input = this.replace(/[^A-Za-z0-9\+\/\=]/g, ""), l = input.length,
		output = "", chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0,
		k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
		f = String.fromCharCode;

		while(i < l) {
			enc1 = k.indexOf(input.charAt(i++));
			enc2 = k.indexOf(input.charAt(i++));
			enc3 = k.indexOf(input.charAt(i++));
			enc4 = k.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + f(chr1);

			if (enc3 != 64) output = output + f(chr2);
			if (enc4 != 64) output = output + f(chr3);
		}

		return output.utf8decode();
	};

	Sp.crc32 = function() {
		var str = this.utf8encode(), x = 0, y = 0,
		table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D",
		crc = 0, i, iTop = str.length;
		crc = crc ^ (-1);
		for(i = 0; i < iTop; i++ ) {
			y = (crc ^ str.charCodeAt(i)) & 0xFF;
			x = "0x" + table.substr(y * 9, 8);
			crc = (crc >>> 8) ^ x;
		}
		return crc ^ (-1);
	};

	Sp.md5 = function() {
		var string = this;

		function RotateLeft(lValue, iShiftBits) {
			return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
		}

		function AddUnsigned(lX,lY) {
			var lX4,lY4,lX8,lY8,lResult;
			lX8 = (lX & 0x80000000);
			lY8 = (lY & 0x80000000);
			lX4 = (lX & 0x40000000);
			lY4 = (lY & 0x40000000);
			lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
			if (lX4 & lY4) {
				return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
			}
			if (lX4 | lY4) {
				if (lResult & 0x40000000) {
					return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
				} else {
					return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
				}
			} else {
				return (lResult ^ lX8 ^ lY8);
			}
	 	}

	 	function F(x,y,z) { return (x & y) | ((~x) & z); }
	 	function G(x,y,z) { return (x & z) | (y & (~z)); }
	 	function H(x,y,z) { return (x ^ y ^ z); }
		function I(x,y,z) { return (y ^ (x | (~z))); }

		function FF(a,b,c,d,x,s,ac) {
			a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
			return AddUnsigned(RotateLeft(a, s), b);
		}

		function GG(a,b,c,d,x,s,ac) {
			a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
			return AddUnsigned(RotateLeft(a, s), b);
		}

		function HH(a,b,c,d,x,s,ac) {
			a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
			return AddUnsigned(RotateLeft(a, s), b);
		}

		function II(a,b,c,d,x,s,ac) {
			a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
			return AddUnsigned(RotateLeft(a, s), b);
		}

		function ConvertToWordArray(string) {
			var lWordCount;
			var lMessageLength = string.length;
			var lNumberOfWords_temp1=lMessageLength + 8;
			var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
			var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
			var lWordArray=Array(lNumberOfWords-1);
			var lBytePosition = 0;
			var lByteCount = 0;
			while ( lByteCount < lMessageLength ) {
				lWordCount = (lByteCount-(lByteCount % 4))/4;
				lBytePosition = (lByteCount % 4)*8;
				lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
				lByteCount++;
			}
			lWordCount = (lByteCount-(lByteCount % 4))/4;
			lBytePosition = (lByteCount % 4)*8;
			lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
			lWordArray[lNumberOfWords-2] = lMessageLength<<3;
			lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
			return lWordArray;
		}

		function WordToHex(lValue) {
			var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
			for (lCount = 0;lCount<=3;lCount++) {
				lByte = (lValue>>>(lCount*8)) & 255;
				WordToHexValue_temp = "0" + lByte.toString(16);
				WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
			}
			return WordToHexValue;
		}

		function Utf8Encode(string) {
			string = string.replace(/\r\n/g,"\n");
			var utftext = "";

			for (var n = 0; n < string.length; n++) {

				var c = string.charCodeAt(n);

				if (c < 128) {
					utftext += String.fromCharCode(c);
				}
				else if((c > 127) && (c < 2048)) {
					utftext += String.fromCharCode((c >> 6) | 192);
					utftext += String.fromCharCode((c & 63) | 128);
				}
				else {
					utftext += String.fromCharCode((c >> 12) | 224);
					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
					utftext += String.fromCharCode((c & 63) | 128);
				}

			}

			return utftext;
		}

		var x=Array(),
		k,AA,BB,CC,DD,a,b,c,d,
		S11=7, S12=12, S13=17, S14=22,
		S21=5, S22=9 , S23=14, S24=20,
		S31=4, S32=11, S33=16, S34=23,
		S41=6, S42=10, S43=15, S44=21;

		string = Utf8Encode(string);

		x = ConvertToWordArray(string);

		a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

		for (k=0;k<x.length;k+=16) {
			AA=a; BB=b; CC=c; DD=d;
			a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
			d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
			c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
			b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
			a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
			d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
			c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
			b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
			a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
			d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
			c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
			b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
			a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
			d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
			c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
			b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
			a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
			d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
			c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
			b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
			a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
			d=GG(d,a,b,c,x[k+10],S22,0x2441453);
			c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
			b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
			a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
			d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
			c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
			b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
			a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
			d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
			c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
			b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
			a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
			d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
			c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
			b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
			a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
			d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
			c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
			b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
			a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
			d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
			c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
			b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
			a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
			d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
			c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
			b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
			a=II(a,b,c,d,x[k+0], S41,0xF4292244);
			d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
			c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
			b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
			a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
			d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
			c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
			b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
			a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
			d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
			c=II(c,d,a,b,x[k+6], S43,0xA3014314);
			b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
			a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
			d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
			c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
			b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
			a=AddUnsigned(a,AA);
			b=AddUnsigned(b,BB);
			c=AddUnsigned(c,CC);
			d=AddUnsigned(d,DD);
		}

		var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);

		return temp.toLowerCase();
	};




	Sp.sha1 = function() {
		var msg = this;

		function rotate_left(n,s) {
			var t4 = ( n<<s ) | (n>>>(32-s));
			return t4;
		}

		function lsb_hex(val) {
			var str="", i, vh, vl;

			for( i=0; i<=6; i+=2 ) {
				vh = (val>>>(i*4+4)) & 0x0f;
				vl = (val>>>(i*4)) & 0x0f;
				str += vh.toString(16) + vl.toString(16);
			}
			return str;
		}

		function cvt_hex(val) {
			var str="";
			var i;
			var v;

			for( i=7; i>=0; i-- ) {
				v = (val>>>(i*4))&0x0f;
				str += v.toString(16);
			}
			return str;
		}


		function Utf8Encode(string) {
			string = string.replace(/\r\n/g,"\n");
			var utftext = "";

			for (var n = 0; n < string.length; n++) {

				var c = string.charCodeAt(n);

				if (c < 128) {
					utftext += String.fromCharCode(c);
				}
				else if((c > 127) && (c < 2048)) {
					utftext += String.fromCharCode((c >> 6) | 192);
					utftext += String.fromCharCode((c & 63) | 128);
				}
				else {
					utftext += String.fromCharCode((c >> 12) | 224);
					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
					utftext += String.fromCharCode((c & 63) | 128);
				}

			}

			return utftext;
		}

		var blockstart,
		i, j,
		W = [80],
		H0 = 0x67452301,
		H1 = 0xEFCDAB89,
		H2 = 0x98BADCFE,
		H3 = 0x10325476,
		H4 = 0xC3D2E1F0,
		A, B, C, D, E,
		temp;

		msg = Utf8Encode(msg);

		var msg_len = msg.length;

		var word_array = [];
		for( i=0; i<msg_len-3; i+=4 ) {
			j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
			msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
			word_array.push( j );
		}

		switch( msg_len % 4 ) {
			case 0:
				i = 0x080000000;
			break;
			case 1:
				i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
			break;

			case 2:
				i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
			break;

			case 3:
				i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
			break;
		}

		word_array.push( i );

		while( (word_array.length % 16) != 14 ) word_array.push( 0 );

		word_array.push( msg_len>>>29 );
		word_array.push( (msg_len<<3)&0x0ffffffff );


		for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {

			for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
			for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);

			A = H0;
			B = H1;
			C = H2;
			D = H3;
			E = H4;

			for( i= 0; i<=19; i++ ) {
				temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
				E = D;
				D = C;
				C = rotate_left(B,30);
				B = A;
				A = temp;
			}

			for( i=20; i<=39; i++ ) {
				temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
				E = D;
				D = C;
				C = rotate_left(B,30);
				B = A;
				A = temp;
			}

			for( i=40; i<=59; i++ ) {
				temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
				E = D;
				D = C;
				C = rotate_left(B,30);
				B = A;
				A = temp;
			}

			for( i=60; i<=79; i++ ) {
				temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
				E = D;
				D = C;
				C = rotate_left(B,30);
				B = A;
				A = temp;
			}

			H0 = (H0 + A) & 0x0ffffffff;
			H1 = (H1 + B) & 0x0ffffffff;
			H2 = (H2 + C) & 0x0ffffffff;
			H3 = (H3 + D) & 0x0ffffffff;
			H4 = (H4 + E) & 0x0ffffffff;

		}

		temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);

		return temp.toLowerCase();

	};


	Sp.sha256 = function() {
		var s = this;

		var chrsz   = 8;
		var hexcase = 0;

		function safe_add (x, y) {
			var lsw = (x & 0xFFFF) + (y & 0xFFFF);
			var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
			return (msw << 16) | (lsw & 0xFFFF);
		}

		function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
		function R (X, n) { return ( X >>> n ); }
		function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
		function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
		function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
		function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
		function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
		function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }

		function core_sha256 (m, l) {
			var K = [0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2],
			HASH = [0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19],
			W = [64],
			a, b, c, d, e, f, g, h, i, j,
			T1, T2;

			m[l >> 5] |= 0x80 << (24 - l % 32);
			m[((l + 64 >> 9) << 4) + 15] = l;

			for(i = 0; i < m.length; i += 16) {
				a = HASH[0];
				b = HASH[1];
				c = HASH[2];
				d = HASH[3];
				e = HASH[4];
				f = HASH[5];
				g = HASH[6];
				h = HASH[7];

				for (j = 0; j<64; j++) {
					if (j < 16) W[j] = m[j + i];
					else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);

					T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
					T2 = safe_add(Sigma0256(a), Maj(a, b, c));

					h = g;
					g = f;
					f = e;
					e = safe_add(d, T1);
					d = c;
					c = b;
					b = a;
					a = safe_add(T1, T2);
				}

				HASH[0] = safe_add(a, HASH[0]);
				HASH[1] = safe_add(b, HASH[1]);
				HASH[2] = safe_add(c, HASH[2]);
				HASH[3] = safe_add(d, HASH[3]);
				HASH[4] = safe_add(e, HASH[4]);
				HASH[5] = safe_add(f, HASH[5]);
				HASH[6] = safe_add(g, HASH[6]);
				HASH[7] = safe_add(h, HASH[7]);
			}
			return HASH;
		}

		function str2binb (str) {
			var bin = Array();
			var mask = (1 << chrsz) - 1;
			for(var i = 0; i < str.length * chrsz; i += chrsz) {
				bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
			}
			return bin;
		}

		function Utf8Encode(string) {
			string = string.replace(/\r\n/g,"\n");
			var utftext = "";

			for (var n = 0; n < string.length; n++) {

				var c = string.charCodeAt(n);

				if (c < 128) {
					utftext += String.fromCharCode(c);
				}
				else if((c > 127) && (c < 2048)) {
					utftext += String.fromCharCode((c >> 6) | 192);
					utftext += String.fromCharCode((c & 63) | 128);
				}
				else {
					utftext += String.fromCharCode((c >> 12) | 224);
					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
					utftext += String.fromCharCode((c & 63) | 128);
				}

			}

			return utftext;
		}

		function binb2hex (binarray) {
			var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
			var str = "";
			for(var i = 0; i < binarray.length * 4; i++) {
				str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
				hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
			}
			return str;
		}

		s = Utf8Encode(s);
		return binb2hex(core_sha256(str2binb(s), s.length * chrsz));

	};


	Sp.utf8encode = function() {
		var string = this.replace(/\r\n/g,"\n"), utftext = "", l = string.length, n, c, f = String.fromCharCode;
		for(n = 0; n < l; n++) {
			c = string.charCodeAt(n);
			if(c < 128) utftext += f(c);
			else if((c > 127) && (c < 2048)) utftext += f((c >> 6) | 192) + f((c & 63) | 128);
			else utftext += f((c >> 12) | 224) + f(((c >> 6) & 63) | 128) + f((c & 63) | 128);
		}
		return utftext;
	};

	Sp.utf8decode = function() {
		var utftext = this, string = "", l = utftext.length, i = 0, c = 0, c1 = 0, c2 = 0, f = String.fromCharCode;
		while(i < l) {
			c = utftext.charCodeAt(i);
			if(c < 128) {
				string += f(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += f(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += f(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	};

	Sp.urlEncode = function() {
		return escape(this.utf8encode());
	};

	Sp.urlDecode = function() {
		return (unescape(this)).utf8decode();
	};
})();
var Show = {
	_cache: [],
	types: {
		quicktime: 'movie mpg mpeg mov mp4 m4v',
		msvideo: 'wmv avi',
		flash: 'swf',
		flashvideo: 'flv',
		pdf: 'pdf',
		image: 'bmp gif jpeg jpg png',
		iframe: 'asp aspx cgi cfm htm html php pl php3 php4 php5 phtml rb rhtml shtml txt'
	},
	clean: function(o) {
		if (typeof o == 'string') {
			if(Url.isUrl(o))
				o = {
					url: o
				};
			else
				o = {
					content: o
				};
		}
		
		var ta = ['image', 'iframe', 'inline', 'ajax', 'quicktime', 'msvideo', 'flash', 'pdf'],
		t, ts = Show.types, i, e, u = o.url, cn = o.content, r = {}, w, h;
		
		if (u) {
			// Controllo se è un'url ad una pagina di social video
			if ((m = u.match(/youtube\.com\/watch\?v=(.+)/i))) 
				u = 'http://www.youtube.com/v/' + m[1];
			else if ((m = u.match(/metacafe\.com\/watch\/([^\/]+\/[^\/]+)/i))) 
				u = 'http://www.metacafe.com/fplayer/' + m[1] + '.swf';
			else if ((m = u.match(/google\.com\/videoplay\?docid=(.+)/i))) 
				u = 'http://video.google.com/googleplayer.swf?docId=' + m[1] + '&hl=en';
			else if ((m = u.match(/ifilm\.com\/video\/(.+)/i))) {
				u = "http://www.ifilm.com/efp";
				(o.flashvars || (o.flashvars = {})).flvbaseclip = m[1] + '&';
			}
			
			// Cerco di inserire informazioni in più per i social video
			var f = [[(/(youtube|dailymotion)/i), {
				type: 'flash',
				width: 425,
				height: 355
			}], [(/metacafe/i), {
				type: 'flash',
				width: 400,
				height: 345
			}], [(/ifilm/i), {
				type: 'flash',
				width: 448,
				height: 365
			}]];
			
			for (i = 0; i < 3; i++) {
				m = f[i];
				if (u.match(m[0])) {
					o = Object.extend(m[1], o);
					break;
				}
			}
		}
		
		t = o.type;
		w = o.width;
		h = o.height;
		
		if (!ta.has(t)) {
			// Se è definito un'url provo a determinare il tipo dall'estensione
			if (u) {
				t = null;
				
				if ((e = (new Url(u)).extension)) {
					for (i in ts) {
						if (ts[i].has(e)) {
							t = i;
							break;
						}
					}
				}
				if(!t)
					t = 'iframe';
			// Se è definito un contenuto allora è inline
			} else if(cn)
				t = 'inline';
			else
				return null;
				
		}

		switch(t) {
			case 'image':
				r.alt = o.alt || o.title || '';
				if (!w || !h) {
					var g = Load.image({
						url: u
					});
					w = w || g.width;
					h = h || g.height;
				}
			break;
			case 'iframe':
				r.scrolling = o.scrolling || 'auto';
				if(!w)
					w = h ? h / 3 * 4 : 640;
				if(!h)
					h = w / 4 * 3;
			break;
			case 'quicktime':
			case 'msvideo':
			case 'flash':
			case 'pdf':
				var c = o.controls, a = o.autostart;
				r.controls = c == undefined ? true : c;
				r.autostart = a == undefined ? true : a;
				r.bgcolor = o.bgcolor;
				r.params = o.params || {};
				r.flashvars = o.flashvars || {};
				if(!w)
					w = h ? h / 3 * 4 : 400;
				if(!h)
					h = w / 4 * 3;
			break;
		}
		
		r.url = u;
		r.content = cn;
		r.type = t;
		r.width = w;
		r.height = h;
		r.id = o.id || 'randomId_' + String.random();
		r.name = o.name || r.id;
		r.onload = o.onload;
		r.style = o.style || {};
		r.title = o.title || '';
		r.className = o.className || '';
		r.append = o.append;
		r.version = o.version;
		
		return r;
	},
	_implements: {
		insertObject: function(o, rt) {
			o = Show.clean(o);
			
			var u = o.url, tp = o.type, i = o.id, n = o.name, cl = o.className, oLo = o.onload || '', w = o.width, h = o.height, s = o.style, t = o.title, r;
			
			switch(tp) {
				case 'image':
					var a = {
						src: u,
						alt: o.alt,
						width: w,
						height: h,
						id: i,
						style: s
					};
					
					if(t)
						a.title = t;
						
					if(oLo)
						a.onload = oLo;
	
					r = D(['img', a], this);
				break;
				case 'iframe':
					s = Object.extend({borderWidth: '0px'}, s);
					
					if(oLo) {
						j = Show._cache.length;
						Show._cache[j] = oLo;
						oLo = ' onload="Show._cache[' + j + '].apply(I(\'' + i + '\'));this.onload=null;delete Show._cache[' + j + '];"';
					}
					
					this.innerHTML = (o.append ? this.innerHTML : '') +
						'<iframe src="' + o.url + '" width="' + w + '" height="' + h + '" id="' + i + '" name="' + n + '"' + (cl ? ' class="' + cl + "'" : '') +
						(t ? ' title="' + t + '"' : '') + ' scrolling="' + o.scrolling + '" frameborder="no"' + oLo + '></iframe>';
						
					r = I(i).setStyles(s);
					
				break;
				case 'quicktime':
				case 'msvideo':
				case 'flash':
				case 'pdf':
				
				
					var c = o.controls, a = o.autostart, b = o.bgcolor, pa = o.params, fv = o.flashvars, pr = '', j, v = o.version,
					gr = ' width="' + w + '" height="' + h + '" id="' + i + '" name="' + n + '"' + (cl ? ' class="' + cl + "'" : '') +
					(t ? ' title="' + t + '"' : '');
			
					/*if(oLo) {
						j = Show._cache.length;
						Show._cache[j] = oLo;
						oLo = ' onload="Show._cache[' + j + '].apply(I(\'' + i + '\'));this.onload=null;delete Show._cache[' + j + '];"';
					}*/
			
					// Ottengo i parametri
					for (j in pa) 
						pr += '<param name="' + j + '" value="' + pa[j] + '" />';
					pr += b ? '<param name="bgcolor" value="' + b + '" />' : '';
			
					switch (tp) {
						case 'flash':
						
							if(v && (v + '').compareVersion(Show.getFlashVersion()) < 0)
								return false;
							
							r = '<object type="application/x-shockwave-flash" data="' + u + '"' + gr + '>' +
								'<param name="movie" value="' + u + '" />' +
								'<param name="allowScriptAcess" value="sameDomain" />' +
								'<param name="quality" value="best" />' +
								'<param name="scale" value="noScale" />' +
								'<param name="salign" value="TL" />' +
								'<param name="wmode" value="transparent" />' +
								'<param name="flashvars" value="playerMode=embedded';

							// Ottengo le variabili per flash
							for (j in fv) 
								r += '&' + j + '=' + fv[j];
								
							r += '" />' +
								pr +
							'</object>';
						break;
						case 'msvideo':
							r =
							'<object type="video/x-ms-wmv" data="' + u + '"' + gr + '>' +
								'<param name="src" value="' + u + '" />' +
								'<param name="autostart" value="' + a + '" />' +
								'<param name="controller" value="' + c + '" />' +
								//'<param name="showcontrols" value="' + c + '" />' +
								//'<param name="autosize" value="true" />' +
								//'<param name="uimode" value="mini" />' +
								pr +
							'</object>';
						break;
						case 'quicktime':
							r =
							'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"' + gr + '>' +
								'<param name="src" value="' + u + '" />' +
								'<param name="controller" value="' + c + '" />' +
								'<param name="autoplay" value="' + a +'" />' +
								pr;
							if(!Agent.MSIE)
								r +=
								'<object type="video/quicktime" data="' + u + '"' + gr + '>' +
									'<param name="autoplay" value="' + a + '" />' +
									'<param name="controller" value="' + c + '" />' +
									pr +
								'</object>';
							r +=
							'</object>';
						break;
						case 'pdf':
							r =
							'<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000"' + gr + '>' +
								'<param name="src" value="' + u + '" />' +
								pr;
							if(!Agent.MSIE)
								r +=
								'<object type="application/pdf" data="' + u + '"' + gr + '>' +
									pr +
								'</object>';
							r +=
							'</object>';
						break;
					}
				
					this.innerHTML = (o.append ? this.innerHTML : '') + r;
					
					o = I(i).setStyles(s);
					
					if(oLo)
						oLo.apply(o);
				break;
			}
			
			return rt ? o : r;
			
		}
	},
	getFlashVersion: function(){
		var v = false, n = navigator, p = n.plugins, u = n.userAgent;
		if (p && n.mimeTypes.length) {
			var f = p['Shockwave Flash'];
			if (f && (f = f.description))
				v = f.replace(/([a-zA-Z]|\s)+/, '').replace(/(\s+r|\s+b[0-9]+)/, '.');
		} else {
			for (var i = 10, a; i >= 2; i--) {
				try {
					if ((a = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i))) {
						v = i + '.0';
						break;
					}
				} catch (e) {
				}
			}
			if (a)
				v = a.GetVariable('$version').split(' ')[1].replace(/[^0-9]+/g, '.');
		}
		return v;
	}
};

Element.implement(Show._implements);
delete Show._implements;
var Widgets = {};

Widgets.ProgressBar = Class({
	value: 0,
	element: null,
	__construct: function(o){
		var e = D(['div', {
			id: o.id || 'random_' + String.random(),
			className: 'widget progress-bar ' + (o.className || ''),
			style: {
				position: 'relative'
			}
		}, ['div', {
			className: 'progress-bar-slider',
			style: {
				position: 'absolute',
				top: '0px',
				left: '0px',
				width: '0%'
			}
		}], ['div', {
			className: 'progress-bar-cover',
			style: {
				position: 'absolute',
				top: '0px',
				left: '0px'
			}
		}]], o.into);
		e._ProgressBar = this;
		this.element = e;
		this.setValue(o.value);
	},
	setValue: function(v, o) {
		v = (v || 0).bound(0, 100);
		((o || (o = {})).styles || (o.styles = {})).width = ['%', 'actual',  v];
		o.stop = true;
		I(this.element.firstChild).morph(o);
		return v;
	}
});

Widgets.Slider = Class({
	element: null,
	disabled: false,
	properties: {},
	__construct: function(o) {
		var u = I(o.into), l = o.length || 100, n = o.min || 0, m = o.max || 100, s = o.starting || 0, g = o.steps,
		c = 'widget slider ' + (o.className || ''), p = I(o.input), vt = o.vertical, j = o.inverse,
		oSt = o.onstart, oMo= o.onmove, oCh = o.onchange, oFi = o.onfinish,
		w = vt ? 2 : l, h = vt ? l : 2,
		// Stili di default per la barra
		b = {
			width: '16px',
			height: '16px',
			background: '#FF0000',
			position: 'absolute',
			cursor: 'move'
		}, i, d;

		b[(vt && j ? 'bottom' : 'top')] = '0px';
		b[(vt && j ? 'marginBottom' : 'marginTop')] = '-7px';
		b[(!vt && j ? 'right' : 'left')] = '0px';
		b[(!vt && j ? 'marginRight' : 'marginLeft')] = '-7px';

		i = D(['div', {
			id: 'random_' + String.random(),
			style: b,
			className: 'slider-handle'
		}]);


		o = D(['div', {
			style: {
				width: w + 'px',
				height: h + 'px',
				background: '#FFCC00',
				position: 'relative'
			},
			className: c
		}, i]);

		this.element = o;

		u.append(o);

		var v = 0, t = 0, self = this;

		// Inserisco l'oggetto delle proprietà dello slider
		d = this.properties = {
			steps: g,
			value: v,
			lenght: l,
			min: n,
			max: m,
			onstart: oSt,
			onmove: oMo,
			onfinish: oFi,
			onchange: oCh,
			input: p,
			last: t
		};

		// Se è definito un elemento input
		if(p && isElement(p, 'input')) {
			p.onchange = function(){
				// Ottengo e mantengo il nuovo valore nei limiti impostati
				var x = (this.value = this.value.toInt().bound(n, m));

				// Ottengo il valore di posizionamento dello slider
				// e mantengo il valore della posizione nei limiti
				d.value = v = (((x - n) * l) / (m - n)).bound(0, l);

				// Imposto la nuova posizione dello slide a seconda se è verticale/inverso
				i.style[(vt ? (j ? 'bottom' : 'top') : (j ? 'right' : 'left'))] = v + 'px';

				if (oMo)
					oMo.call(i, x, t);

				if (oFi)
					oFi.call(i, x, t);

				if (oCh && t != x)
					oCh.call(i, x, t);

				d.last = t = v;
			};
		}

		i.makeDraggable({
			onstart: function(e) {
				// Controllo se il valore è nel range della barra
				// e assegno il nuovo valore all'oggetto contenitore
				d.value = v = v.bound(o, l);

				// Eseguo onstart se presente
				if(oSt)
					oSt.call(this, ((v * (m - n)) / l) + n, t);
						// Ottengo il range dello slide e calcolo il valore dello slide (x) solo se necessario
			},
			onmove: function(e, xD, yD) {
				// Ottengo tutte le variabili locali dall'oggetto
				var q = j ? -1 : 1, vv, gr, x;

				/* Tenendo conto della posizione verticale calcolo il nuovo valore
				 * Assegno il nuovo valore all'oggetto contenitore
				 * Lo assegno prima per tenere conto della posizione del mouse
				 * nel documento, ma al di fuori dello slide
				 */
				d.value = v = (v - ((vt ? yD : xD) * q)).toInt();

				// Controllo se il valore è nel range della barra
				vv = v.bound(0, l);

				gr = g ? self._nearestStep(vv, l, g) : [vv, ((vv * (m - n)) / l) + n];
				vv = gr[0];
				x = gr[1];

				// Imposto le posizioni tenendo conto di verticale/inverso
				this.style[(vt ? (j ? 'bottom' : 'top') : (j ? 'right' : 'left'))] = vv + 'px';

				// Eseguo onmove se presente
				if(oMo)
					oMo.call(this, x, t);
				// Se è presente un input setto il corrispondente valore
				if(p)
					p.value = x;
			},
			onfinish: function(e) {
				// Controllo se il valore è nel range della barra
				// Assegno il nuovo valore all'oggetto contenitore
				d.value = v = v.bound(0, l);

				// Ottengo il range dello slide e calcolo il valore dello slide
				var x = ((v * (m - n)) / l) + n;

				// Eseguo onfinish se presente
				if(oFi)
					oFi.call(this, x, t);

				// Eseguo onchange se presente e se il valore è cambiato
				if(oCh && t != x)
					oCh.call(this, x, t);

				// Conservo il nuovo valore per il confronto successivo come ultimo valore
				d.last = t = x;
			}
		});
		return o;
	},
	disable: function() {
		this.disabled = true;
		this.element.addClass('disabled');
	},
	enable: function() {
		this.disabled = false;
		this.element.removeClass('disabled');
	},
	_nearestStep: function(v, l, g){
		for (var gl = g.length - 1, gs = l / gl, hgs = gs / 2, ga = 0, i = 0; i <= gl; i++) {
			if (v >= (ga - hgs) && v <= (ga + hgs))
				//return (v - ga) < (gb - v) ? [ga.round(), g[i - 1]] : [gb.round(), g[i]];
				return [ga.round(), g[i]];
			ga += gs;
		}
		return [0, g[0]];
	}
});


Widgets.Button = Class({
	element: null,
	disabled: false,
	onclick: null,
	__construct: function(o, t) {
		var self = this, c;
		o = I(o);
		t = t || 'send';
		o.addClass('ui-button');
		Event.add(o, 'mousedown', function(){
			this.addClass('down');
		});
		Event.add(o, 'mouseup', function(){
			this.removeClass('down');
		});
		Event.add(o, 'mouseover', function(){
			this.addClass('over');
		});
		Event.add(o, 'mouseout', function(){
			this.removeClass('over');
		});
		Event.add(o, 'click', function(e){
			if(self.disabled)
				return Event.stop(e);
			if((c = self.onclick))
				c.call(o, e);
		});
		this.element = o;
		o._button = this;
	},
	disable: function() {
		this.disabled = true;
		this.element.addClass('disabled');
	},
	enable: function() {
		this.disabled = false;
		this.element.removeClass('disabled');
	}
});


Widgets.Messages = Class({
	messages: [],
	elements: [],
	length: 0,
	add: function(v, t) {
		if(typeof v == 'string') v = new UI.Message(v, t);
		this.messages.push(v);
		this.length++;
	},
	message: function(i) {
		return this.messages[i];
	},
	appendAll: function(p, o){
		if (o.removeOld)
			Widgets.Messages.removeFrom(p);
		for (var r = [], l = this.length, i = 0; i < l; i++)
			r[i] = this.elements[i].append(p, o);
		return r;
	}
});
Widgets.Messages.removeFrom = function(p) {
	C('ui-message', p).each(function(o){
		o.remove();
	});
};


Widgets.Message = Class({
	type: 'info',
	value: '',
	element: null,
	__construct: function(v, t) {
		this.set(v, t);
	},
	set: function(v, t) {
		this.value = v || '';
		this.type = t || 'info';
	},
	append: function(p, o) {
		o = o || {};
		var v = this.value || '', t = this.type || 'info', c = {
			className: 'widget message ' + t,
			style: o.style || {}
		}, n = o.onload;
		c = D(['div', c, v], p);
		if(n)
			n.call(c, i, v, t);
		this.element = c;
		return c;
	}
});


Widgets.DatePicker = Class({
	element: null,
	properties: null,
	year: null,
	month: null,
	__construct: function(o){
		var e = I(o.target), self = this;
		this.properties = o;
		Event.add(e, 'focus', function(e){
			self.show();
			this.blur();
		});
		Event.add(e, 'clickout', function(e){
			self.hide();
		});
		this.element = D(['div', {
			className: 'widget date-picker ' + (o.className || ''),
			style: {
				display: 'none',
				position: 'absolute'
			}
		}], T('body')[0]);
	},
	hide: function(){
		this.element.style.display = 'none';
	},
	show: function(o){
		o = o || this.properties;
		var el = I(o.target), n = new Date(),
			y = o.year || n.getFullYear(), m = (o.month || n.getMonth() + 1) - 1, d = o.day || n.getDate(),
			f = o.format || 'Y/m/d H:i:s', t = this.element, self = this;

		// Se il mese è minore di 0 (Prima di Gennaio)
		while (m < 0) {
			m += 12;
			y--;
		}
		// Se il mese è maggiore di 11 (Dopo di Dicembre)
		while (m > 11) {
			m -= 12;
			y++
		}

		this.year = y;
		this.month = m + 1;

		// Mese attuale, prossimo mese,
		var nd = new Date(y, m, 1), nm = new Date(y, m + 1, 1), ws = nd.getDay(),
		// Get the number of days in current month
		md = ((nm.getTime() - nd.getTime()) / 86400000).round() + 1, p = el.position({
			alignment: 3
		}), s = t.style;

		s.left = p[0] + 'px';
		s.top = p[1] + 'px';
		s.display = 'block';

		// Svuoto l'elemento contenitore
		t.replaceChilds(['ul', {
			className: 'year'
		}, ['li', {
			className: 'prev',
			onclick: function(e){
				self.show({
					target: el,
					year: (y - 1),
					month: (m + 1),
					day: d,
					format: f
				});
				return Event.stop(e);
			},
			onmouseover: function(){
				this.addClass('hover');
			},
			onmouseout: function(){
				this.removeClass('hover');
			}
		}, ['span', 'prev']], ['li', {
			className: 'now'
		}, y], ['li', {
			className: 'next',
			onclick: function(e){
				self.show({
					target: el,
					year: (y + 1),
					month: (m + 1),
					day: d,
					format: f
				});
				return Event.stop(e);
			},
			onmouseover: function(){
				this.addClass('hover');
			},
			onmouseout: function(){
				this.removeClass('hover');
			}
		}, ['span', 'next']]], ['ul', {
			className: 'month'
		}, ['li', {
			className: 'prev',
			onclick: function(e){
				self.show({
					target: el,
					year: y,
					month: m,
					day: d,
					format: f
				});
				return Event.stop(e);
			},
			onmouseover: function(){
				this.addClass('hover');
			},
			onmouseout: function(){
				this.removeClass('hover');
			}
		}, ['span', 'prev']], ['li', {
			className: 'now'
		}, m + 1], ['li', {
			className: 'next',
			onclick: function(e){
				self.show({
					target: el,
					year: y,
					month: (m + 2),
					day: d,
					format: f
				});
				return Event.stop(e);
			},
			onmouseover: function(){
				this.addClass('hover');
			},
			onmouseout: function(){
				this.removeClass('hover');
			}
		}, ['span', 'next']]], ['ul', {
			className: 'week'
		}, ['li', {
			className: 'su'
		}, 'S'], ['li', {
			className: 'mo'
		}, 'M'], ['li', {
			className: 'tu'
		}, 'T'], ['li', {
			className: 'we'
		}, 'W'], ['li', {
			className: 'th'
		}, 'T'], ['li', {
			className: 'fr'
		}, 'F'], ['li', {
			className: 'sa'
		}, 'S']]);


		// Fill the previous month days with space
		var w = ['ul', {
			className: 'week-row'
		}], i, j, cl;

		for (i = 0; i < ws; i++)
			w[w.length] = ['li', {
				className: 'empty'
			}, ['span', '-']];

		// Populate current month
		for (i = 1; i < md; i++) {

			cl = 'day';

			if ((i + ws) % 7 == 1) {
				t.append(w);
				w = ['ul', {
					className: 'week-row'
				}];
				cl += ' su';
			}

			if (i == d)
				cl += ' selected';

			w[w.length] = ['li', {
				className: cl,
				onclick: function(e){
					self._insertDate(el, f, this);
					self.hide();
					return Event.stop(e);
				},
				onmouseover: function(){
					this.addClass('hover');
				},
				onmouseout: function(){
					this.removeClass('hover');
				}
			}, i];
		}

		// Fill the next month days with space
		for (j = (42 - (md + ws)), i = 0; i <= j; i++)
			w[w.length] = ['li', {
				className: 'empty'
			}, ['span', '-']];

		t.append(w, ['div', {
			className: 'clear'
		}]);
	},
	_insertDate: function(e, f, g){
		var d = g.firstChild.nodeValue + '', m = this.month, yy = this.year,
		y = yy.zeroFill(2, true), mm = m.zeroFill(2), dd = parseInt(d, 10).zeroFill(2),
		t =  new Date(), hh = t.getHours().zeroFill(2), ii = t.getMinutes().zeroFill(2),
		ss = t.getSeconds().zeroFill(2);
		f = f.replace('Y', yy).replace('m', mm).replace('d', dd);
		f = f.replace('y', y).replace('n', m).replace('d', d);
		f = f.replace('H', hh).replace('i', ii).replace('s', ss);
		f = f.replace('h', (hh > 12 ? hh - 12 : hh));
		e.value = f;
	}
});
