/*
 * Name:		xFrame - DOM, animations, and ajax framework library
 * Author:		Sandro (XAndE) Lain
 * Copyright:	Sandro (XAndE) Lain - All rights reserved
 */

var xFrame = {
	version : 0.4,
	build : '070501'
};

// Funzione per gli id
function I(o, d) {
	if(!d || !d.getElementById) d = document;
	if(!o) return d;
	if(typeof o == 'string') return d.getElementById(o);
	if(o.nodeName || d.getElementById) return o;
	return null;
}
function T(t, e) {
	return Tools.toArray((I(e) || document).getElementsByTagName(t));
}

function C(c, o, t) {
	for(var a = T(t || '*', o), r = [], i = a.length - 1, j = 0; i >= 0 && (o = a[i]); i--) if(Dom.hasClassName(o, c)) r[j++] = o;
	return r;
}

function A(c, o, t) {
	for(var a = T(t || '*', o), r = [], i = a.length - 1, j = 0; i >= 0 && (o = a[i]); i--) if(Dom.hasAttribute(o, c)) r[j++] = o;
	return r;
}

/*
// Function to obtain a group of elements by a css-like path
function P(p, e) {
	var s = [I(e)], t = p.split(/[\s]+/i), l = t.length;
	for(var i = 0; i < l; i++) {
		//var m = t[i].match(/^(\*|[a-z][a-z0-9]*)?(#([a-z][a-z0-9_-]*))?((\.[a-z][a-z0-9_-]*)+)?$/i),
		var m = t[i].match(/^(\*|[a-z][a-z0-9]*)?(\#([a-z][a-z0-9_-]*))?((\.[a-z][a-z0-9_-]*)+)?(\[([a-z]+)((~|\^|\$|\*)?=?([^\]]*))\])?$/i),
		g = s.length;
		if(m) {
			var r = null, rn = [], rd = [], rc = [], ra = [], n = m[1], d = m[3], c = m[4], a = m[6], j;
			if(n) {
				for(j = 0; j < g; j++) rn = rn.concat(T(n, s[j]));
				r = rn;
			}
			if(d) {
				for(j = 0; j < g; j++) {
					var f = s[j].getElementById(d);
					if(f) rd.push(f);
				}
				r = (r) ? r.intersect(rd) : r = rd;
			}
			if(c) {
				for(j = 0; j < g; j++) rc = rc.concat(C(c, s[j]));
				r = (r) ? r.intersect(rc) : r = rc;
			}
			if(a) {
				for(j = 0; j < g; j++) ra = ra.concat(A(a, s[j]));
				r = (r) ? r.intersect(ra) : r = ra;
			}
			if(!r || r.length === 0) return null;
			s = r;
		} else return null;
	}
	return s.unique();
}
*/

// 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 = Dom.first(s[j], 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 = Dom.firstLetter(s[j], 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 = 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(Tools.toArray(s[j].childNodes));
				r = (r) ? r.intersect(c) : c;
				if(r.length === 0) return null;
			}

			if(!r) return null;
			s = r;
		}
	}
	return s.unique();
}

if(!window.$) {
	$ = I;
}

var Dom = {
	first: function(o, t) {
		o = I(o);
		var g = o.childNodes, i, c, l = g.length;
		if(!t && l > 0) return g[0];
		for(i = 0; i < l; i++) {
			c = g[i];
			if(c.nodeType == 1) return c;
		}
		return null;
	},
	last: function(o, t) {
		o = I(o);
		var g = o.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(o, t) {
		o = I(o);
		o = o.nextSibling;
		if(!t && o) return o;
		while(o && (o = o.nextSibling)) if(o.nodeType == 1) return o;
		return null;
	},
	prev: function(o, t) {
		o = I(o);
		o = o.previousSibling;
		if(!t && o) return o;
		while(o && (o = o.previousSibling)) if(o.nodeType == 1) return o;
		return null;
	},
	firstLetter: function(o, t) {
		o = I(o);
		var g = o.childNodes, l = g.length, i, c, p;
		for(i = 0; i < l; i++) {
			c = g[i]; p = c.nodeType;
			if(p == 1) {
				p = Dom.firstLetter(c, t);
				if(p) return p;
			} else if(p == 3) {
				p = c.nodeValue;
				if(!p.match(/^[\s]*$/gm)) {
					if(t) {
						if(p.length == 1 && !c.previousSibling && !c.nextSibling && c.parentNode.nodeName.toLowerCase() == 'span') return c.parentNode;
						return Dom.spanSubtext(c, 0, 1);
					}
					else return p.substr(0, 1);
				}
			}
		}
		return null;
	},
	spanSubtext: function(o, s, f) {
		if(o.nodeType != 3) throw new TypeError();
		var v = o.nodeValue, b = v.substring(s, f), r = Dom.create(['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.insertAfter.apply(null, a);
		Dom.removeElements(o);
		return r;
	},
	//### Class Name Functions
	// Function to check if an element has a class name
	hasClassName: function(o, s) {
		o = I(o).className;
		s = s.split(/[\.\s]+/gi).unique();
		for(var j = s.length - 1, e = null; j >= 0 && (e = s[j]); j--) {
			if(e) { // Rimosso  && e !== ''
				var g = new RegExp("(^|\\s)" + e + "(\\s|$)", 'gm');
				if(!g.test(o)) return false;
			}
		}
		return true;
	},
	// Function to add one o more classnames to an element
	addClassName: function(o, s) {
		o = I(o);
		Dom.removeClassName(o, s);
		s = s.split(/[\.\s]+/g).unique().join(' ');
		o.className += ' ' + s;
	},
	// Function to remove one or more classnames from an element
	removeClassName: function(o, s) {
		o = I(o);
		s = s.split(/[\.\s]+/gi).unique().join('|');
		var g = new RegExp("(^|\\s+)(" + s + ")(\\s+|$)", 'g');
		o.className = o.className.replace(g, ' ');
	},
	switchClassName: function() {
		var a = arguments, o = I(a[0]);
		for(var l = a.length, i = 1, e; i < l; i++) {
			e = a[i];
			if(Dom.hasClassName(o, e)) {
				Dom.removeClassName(o, e);
				e = (i == l - 1) ? a[1] : a[i+1];
				Dom.addClassName(o, e);
				return;
			}
		}
		Dom.addClassName(o, a[1]);
	},
	booClassName: function() {
		var a = arguments, o = I(a[0]);
		for(var i = a.length - 1, e; i > 0; i--) {
			e = a[i];
			if(Dom.hasClassName(o, e)) Dom.removeClassName(o, e);
			else Dom.addClassName(o, e);
		}
	},
	//### Class Name Functions
	// Function to remove elements
	removeElements: function() {
		for(var a = arguments, i = a.length - 1, o = null; i >= 0 && (o = I(a[i])); i--) o.parentNode.removeChild(o);
	},
	// Function to append multiple elements or insert html to a specified element
	appendChilds: function() {
		for(var a = arguments, l = a.length, o = I(a[0]), i = 1; i < l; i++) o.appendChild(Dom.create(a[i]));
	},
	// Function to insert a child before another
	insertBefore: function() {
		for(var a = arguments, l = a.length, o = I(a[0]), i = 1; i < l; i++) o.parentNode.insertBefore(Dom.create(a[i]), o);
	},
	// Function to insert a child after another
	insertAfter: function() {
		for(var a = arguments, o = I(a[0]), p = o.parentNode, n, i = a.length - 1, c, n; i > 0; i--) {
			c = Dom.create(a[i]);
			n = o.nextSibling;
			if(n) p.insertBefore(c, n); else p.appendChild(c);
		}
	},
	getChilds: function() {
		for(var a = arguments, r = [], i = a.length - 1, c = null, y = 0; i >= 0 && (c = I(a[i]).childNodes); i--)
			for(var j = c.length - 1; j >= 0; j--) r[y++] = c[j];
		return r;
	},
	// Obsoleta (solo se si vuole ottenere anche i figli di tipo non element)
	getDescendants: function() {
		for(var a = arguments, r = [], i = a.length - 1, c = null; i >= 0 && (c = I(a[i]).childNodes); i--)
			for(var j = c.length - 1, o = null; j >= 0 && (o = c[j]); j--)
				if(o.nodeType == 1) r = r.concat(o, Dom.getDescendants(o));
		return r;
	},
	// Function to delete all child nodes of an element
	removeChilds: function() {
		for(var a = arguments, i = a.length - 1, e = null; i >= 0 && (e = I(a[i])); i--) while(e.hasChildNodes()) e.removeChild(e.firstChild);
	},
	// Function to move all child nodes of an element to all other elements
	moveChilds: function() {
		var a = arguments, o = I(a[0]);
		while(o.hasChildNodes()) {
			for(i = a.length - 1; i > 0; i--) I(a[i]).appendChild(o.firstChild.cloneNode(true));
			o.removeChild(o.firstChild);
		}
	},
	replaceChilds: function() {
		var a = arguments;
		Dom.removeChilds.apply(null, [a[0]]);
		Dom.appendChilds.apply(null, a);
	},
	// Function to copy all child nodes of an element to all other elements
	copyChilds: function() {
		var a = Tools.toArray(arguments), c = I(a.shift()).cloneNode(true);
		Dom.moveChilds.apply(null, [c].concat(a));
	},
	// Function to copy a node into another
	copyNode: function() {
		for(var a = arguments, o = I(a[0]), i = a.length - 1; i > 0; i--) I(a[i]).appendChild(o.cloneNode(true));
	},
	getAttribute: function(o, a) {
		o = I(o);
		if(a == 'class' || a == 'className') return o.className;
		else return o.getAttribute(a);
	},
	getAttributes: function() {
		for(var a = arguments, o = I(a[0]), r = {}, i = a.length - 1, e = null; i > 0 && (e = a[i]); i--) r[e] = Dom.getAttribute(o, e);
		return r;
	},
	// Function to set multiple attributes to a specified element
	setAttributes: function(o, a) {
		o = I(o);
		for(var i in a) {
			var e = a[i];
			if(typeof e == 'function') {
				//Env.addEvent(o, i, e);
				o[i] = function() { e.apply(this, arguments); };
			}
			else if(i == 'class' || i == 'className') Dom.addClassName(o, e);
			else if(i == 'style') Dom.setStyles(o, e);
			else o.setAttribute(i, e);
		}
	},
	hasAttribute: function(o, c) {
		o = I(o); var e, v;
		if(typeof c == 'string') {
			var m = c.match(/^\[?([a-z]+)(\~|\^|\$|\*)?(\=([^\]]+))?\]?$/i); e = '';
			if(m) {
				var a = m[1];
				//s.replace(/(\\|\.|\(|\)|\[|\]|\^|\$)/gmi, '\\' + '\\1');
				if(m[3]) {
					var t = m[2], s = m[4];
					if(t) {
						if(t == '~') e = '(^|\\s)' + s + '(\\s|$)';
						else if(t == '^') e = '^' + s;
						else if(t == '$') e = s + '$';
						else if(t == '*') e = s;
					} else e = '^' + s + '$';
				}
				v = Dom.getAttribute(o, a);
				//alert(v + " > " + a + " " + t + " = " + s + " > " + e)
				e = new RegExp(e);
				if(v && v.match(e)) return true;
			}
			return false;
		} else {
			for(var j in c) {
				e = c[j];
				if(typeof e == 'string') e = new RegExp("^" + (e.replace('*', '(.*)')) + "$", 'gm');
				else if(e.constructor != RegExp) continue;
				v = (j == 'class' || j == 'className') ? o.className : o.getAttribute(j);
				if(!e.test(v)) return false;
			}
		}
		return true;
	},
	// Function to set the CSS style attribute to an element
	setStyles: function(o, s) {
		o = I(o); var z = o.style, e = Agent.MSIE;
		if(typeof s == 'string') {
			if(e) z.cssText = s; else o.setAttribute("style", s);
		} else if(typeof s == 'object') {
			var f = (e) ? 'styleFloat' : 'cssFloat';
			for(var i in s) {
				if(i == 'opacity') Dom.setOpacity(o, s[i]);
				else if(i == 'float') z[f] = s[i];
				else z[i] = s[i];
			}
		}
	},
	getStyle: function(o, s) {
		o = I(o); s = s.camelize();
		var z = o.style, c = o.currentStyle, k = document.defaultView;
		c = c ? c : (k ? k.getComputedStyle(o, '') : {});
		s = z[s] || c[s] || '';
		return s;
	},
	// Function to obtain the values of requested style properties
	getStyles: function() {
		var a = arguments, r = {}, o = I(a[0]), z = o.style, c = o.currentStyle, k = document.defaultView;
		c = c ? c : (k ? k.getComputedStyle(o, '') : {});
		for(var i = a.length - 1, e = null; i > 0 && (e = a[i].camelize()); i--) r[e] = z[e] || c[e] || '';
		return r;
	},
	switchStyle: function() {
		var a = arguments, o = I(a[0]), n = a[1], s = Dom.getStyle(o, n);
		if(n.toLowerCase().indexOf('color') > -1) s = Color.css2hex(s);
		for(var l = a.length, i = 2, e; i < l; i++) {
			e = a[i];
			if(e == s) {
				e = (i == l - 1) ? a[2] : a[i+1];
				o.style[n] = e;
				return;
			}
		}
		Dom.addClassName(o, a[2]);
	},
	setOpacity: function(i, o) {
		i = I(i); var s = i.style;
		o = parseFloat(o); o = (o < 0.01) ? 0 : ((o > 1) ? 1 : o);
		if(Agent.MSIE) s.filter = Dom.getStyles(i, 'filter').filter.replace(/alpha\([^\)]*\)/gi,'') + 'alpha(opacity=' + Math.round(o * 100) + ')';
		else if(o === 1 && Agent.Gecko) s.opacity = 0.99;
		else s.opacity = o;
	},
	getOpacity: function(i) {
		i = I(i); var o = 1, s = Dom.getStyles(i, 'filter', 'opacity');
		if(Agent.MSIE) {
			var e = s.filter.match(/alpha\([\s]*opacity=([0-9]+)[\s]*\)/i);
			if(e && e[1]) o = parseInt(e[1], 10) / 100;
		} else o = s.opacity;
		if(o !== 0 && (!o || o == NaN)) o = 1;
		return parseFloat(o);
	},
	// Corretto il bug con IE6 e position:absolute
	getRealHeight : function(i, v) {
		var o = I(i).cloneNode(true), r = 0, s = o.style, g = Dom.getStyles(o, 'paddingTop', 'paddingBottom');
		s.visibility = 'hidden'; s.display = 'block'; s.height = 'auto';
		if(Agent.isMSIE(6)) s.position = 'absolute';
		if(v) s.width = v + 'px'; Dom.insertBefore(i, o);
		r = o.clientHeight - Tools.cleanSize(g.paddingTop) - Tools.cleanSize(g.paddingBottom);
		Dom.removeElements(o);
		return r;
	},
	// Function to obtain a clone of the passed elements
	getClones: function() {
		for(var a = arguments, r = [], i = a.length - 1, o = null, j = 0; i >= 0 && (o = I(a[i])); i--) r[j++] = o.cloneNode(true);
		return r;
	},
	// Function to obtain a new Dom elements structure
	// Modification of graft() function by Sean M. Burke from interglacial.com
	create: function(t, o) {
		var r;
		if(!t && t !== '') return null;
		if(t.constructor == Number) t = t.toString();
		if(t.constructor == String) r = document.createTextNode(t);
		else if(t.constructor == Array) {
			var l = t.length;
			for(var i = 0; i < l; i++) {
				var e = t[i];
				if(e === undefined) return null;
				else if(i === 0 && e.constructor == String) {
					var m = e.match(/^(\*|[a-z][a-z0-9]*)?(#([a-z][a-z0-9_-]*))?((\.[a-z][a-z0-9_-]*)+)?$/i);
					if(m) {
						r = document.createElement(m[1]);
						if(m[2]) r.setAttribute('id', m[3]);
						if(m[4]) r.className = m[4].replace('.', ' ').trim();
					} else return null;
				} else if(e.constructor == Number || e.constructor == String
					|| e.constructor == Array || e.nodeType) Dom.create(e, r);
				else if(e.constructor == Object) Dom.setAttributes(r, e);
				else return null;
			}
		} else r = t;
		if(o) I(o).appendChild(r);
		return r;
	},
	getDocument: function(o) {
		o = I(o);
		var d = o.contentWindow || o.contentDocument || o.document, c = d.document;
		if(c) d = c;
		if(!d) d = document;
		return d;
	},
	getWindow: function(o) {
		o = I(o);
		var w = o.contentWindow || o;
		if(!w) w = window;
		return w;
	},
	parseCss: function(s) {
		for(var p = s.split(';'), r = {}, i = p.length - 1; i >= 0; i--) {
			var d = p[i].split(':'), n = d[0].trim().camelize();
			if(n) r[n] = d[1].trim();
		}
		return r;
	},
	insertText: function(o, t) {
		o = I(o); var n = o.nodeName;
		if(n) {
			n = n.toLowerCase();
			if(n == "input" || n == "select" || n == "option" || n == "textarea") o.value = t;
			else o.appendChild(document.createTextNode(t));
		}
	},
	getId: function(o, a) {
		if(typeof o == 'string') return o;
		if(o.nodeType == 1) {
			var i = o.getAttribute('id');
			if(i) return i; // Rimosso  && i != ''
			if(a) {
				var r = Tools.generateId();
				o.setAttribute('id', r);
				return r;
			}
		}
		return null;
	},
	body: function(d) {
		if(!d) d = document;
		return T('body', d)[0];
	},
	head: function(d) {
		if(!d) d = document;
		return T('head', d)[0];
	},
	_clean: function(a) {
		for(var r =[], j = 0, i = 0, l = a.length; i < l; i++) {
			var e = a[i];
			if(e) r[j++] = e;
		}
		return r;
	}
};

var Agent = {
	isMSIE: function(v) {
		if(!v) return (document.all && !window.opera) ? true : false;
		var e = new RegExp('MSIE ' + parseFloat(v, 10), 'g');
		if(e.test(navigator.userAgent)) return true;
		return false;
	},
	isGecko: function() {
		var u = navigator.userAgent;
		return (/Gecko/.test(u) && !(/Konqueror|Safari|KHTML/.test(u))) ? true : false;
	},
	isSafari: function() {
		return (/Safari/.test(navigator.userAgent)) ? true : false;
	},
	isNetscape: function(v) {
		if(!v) v = '';
		var e = new RegExp('(Netscape|NS)[0-9]*[ /]{0,1}' + v, 'g');
		if(e.test(navigator.userAgent)) return true;
		return false;
	},
	isFirefox: function(v) {
		if(!v) v = '';
		var e = new RegExp('(Firefox|Minefield)/' + v, 'g');
		if(e.test(navigator.userAgent)) return true;
		return false;
	},
	isOpera: function(v) {
		if(!v) return (window.opera) ? true : false;
		var e = new RegExp('Opera[ /]{0,1}' + v, 'g');
		if(e.test(navigator.userAgent)) return true;
		return false;
	}
};
//  // Old technique
Agent.MSIE = Agent.isMSIE();
Agent.Opera = Agent.isOpera();
Agent.Gecko = Agent.isGecko();
Agent.Firefox = Agent.isFirefox();


var Tools = {
	generateId: function() {
		return 'xf_random_id_' + Tools.randomString();
	},
	forEach: function(o, f, t, p) {
		if(typeof f != "function") throw new TypeError();
		if(typeof o == 'object' && p) for(var i in o) f.call(t, o[i], i, o);
		else {
			if(f.construnctor != Array) o = [o];
			o.forEach(f, t);
		}
	},
	// Function to convert an object list to an array
	toArray: function(a) {
		for(var r = [], i = a.length - 1; i >= 0; i--) r[i] = a[i];
		return r;
	},
	randomString: function(l) {
		var c = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz", g = c.length, r = '';
		if(!l) l = 8;
		for(var i = l; i > 0; i--) {
			var n = Math.floor(Math.random() * g);
			r += c.substring(n, n+1);
		}
		return r;
	},
	object: function(o, e, c) {
		var r = {}, i;
		if(c) for(i in o) r[i] = o[i];
		for(i in e) r[i] = e[i];
		return r;
	},
	cleanSize : function(s, a) {
		var v = 0, u = '', t = typeof s;
		if(t == 'number') v = s;
		else if(t == 'string') {
			var e = s.match(/(-?[0-9\.]*)(in|cm|mm|pt|pc|em|ex|px|%)?/i);
			if(e) {
				var v = parseFloat(e[1], 10), u = e[2];
				if(!v) v = 0; if(!u) u = '';
			}
		}
		return (a) ? [v, u] : v;
	},
	map: function(a, f, t) {
		if(typeof f != "function") throw new TypeError();
		for(var l = a.length, r = [], i = 0; i < l; i++) r = r.concat(f.call(t, a[i], i, a));
		return r;
	},
	filter: function(a, f, t) {
		if(typeof f != "function") throw new TypeError();
		for(var l = a.length, r = [], i = 0, o; i < l; i++) {
			o = a[i]; if(f.call(t, o, i, a)) r[r.length] = o;
		}
		return r;
	}
};

if(typeof String.prototype.trim === 'undefined') {
	String.prototype.trim = function() {
		return this.replace(/\s+$|^\s+/g,"");
	};
}
if(typeof String.prototype.camelize === 'undefined') {
	String.prototype.camelize = function() {
		var w = this, l = w.split('-');
		if(l.length == 1) return l[0];
		var c = w.indexOf('-') === 0 ? l[0].charAt(0).toUpperCase() + l[0].substring(1) : l[0];
		for(var i = l.length - 1; i > 0; i--) c = l[i].charAt(0).toUpperCase() + l[i].substring(1) + c;
		return c;
	};
}
String.prototype.empty = function(s) {
	return (this.length === 0 || (s && this.match(/^[\s]*$/gm))) ? true : false;
}

if(typeof Array.prototype.unique === 'undefined') {
	Array.prototype.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;
	};
}
if(typeof Array.prototype.indexOf === 'undefined') {
	Array.prototype.indexOf = function(v, b) {
		for(var i =+ b || 0, l = this.length; i < l; i++) if(this[i] === v) return i;
		return -1;
	};
}
if(typeof Array.prototype.forEach === 'undefined') {
	Array.prototype.forEach = function(f, t) {
		if(typeof f != "function") throw new TypeError();
		for(var i = 0; i < this.length; i++) if(i in this) f.call(t, this[i], i, this);
	};
}
Array.prototype.replace = function(f, p) {
	for(var r = [], i = this.length - 1; i >= 0 ; i--) r[i] = (this[i] === f) ? p : this[i];
	return r;
};
Array.prototype.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;
};
