
/* * Array */Array.prototype.forEach = function(fn, bind){	for(var i=0, l=this.length; i<l; i++){		try{ fn.call(bind, this[i], i, this); }catch(e){}	}};Array.prototype.each = Array.prototype.forEach;/* * Strings */String.prototype.camelCase = function(){	return this.replace(/-\D/g, function(match){		return match.charAt(1).toUpperCase();	});};String.prototype.capitalize = function(){	return this.replace(/\b[a-z]/g, function(match){		return match.toUpperCase();	});};String.prototype.clean = function(){	return this.replace(/\s+/g, ' ').trim();};String.prototype.test = function(regex, params){	return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);};String.prototype.trim = function(){	return this.replace(/^\s+|\s+$/g, '');};/* * Functions */Function.prototype.bind = function(object){	var self = this;	return function(){		return self.apply(object, arguments);	}};Function.prototype.delay = function(delay, bind, args){	var self = this;	var returns = function() {		return args ? self.apply(bind || null, args) : self.apply(bind);	};	return setTimeout(returns, delay);};Function.prototype.periodical = function(periodical, bind, args){	var self = this;	var returns = function(){		return args ? self.apply(bind || null, args) : self.apply(bind);	};	return setInterval(returns, periodical);};/* * Elements */Element.prototype.set = function(property, value){	if(property=='html') return this.setHTML(value);	else if(property=='events') return this.addEvents(value);	else if(property=='styles' && this.setStyles) return this.setStyles(value);	else if(property=='class') property = 'className';	else if(property=='for') property = 'htmlFor';	this[property] = value;	return this;};Element.prototype.get = function(property){	if(property=='html') return this.getHTML();	else if(property=='class') property = 'className';	else if(property=='for') property = 'htmlFor';	return this[property];};Element.prototype.hasClass = function(className){	return ( (' '+this.className+' ').indexOf(' '+className+' ') > -1 );//	return this.className.contains(className, ' ');};Element.prototype.addClass = function(className){	if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();	return this;};Element.prototype.removeClass = function(className){	this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');	return this;};Element.prototype.toggleClass = function(className){	return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);};Element.prototype.show = function(delay) {	if (this.style.display == '' || this._showing) {	} else if (delay) {		var stopOpacity = this.getOpacity();		var steps = stopOpacity*20;		var timestep = delay/steps;		this.setOpacity(0).show();		this._showing = true;		for (var i = 1; i <= steps; i++) {			var opacity = i/20;			var d = i*timestep;			this.setOpacity.delay(d, this, [opacity]);		}		(function(){ this._showing = false; }).delay(d+1, this);	} else {		this.style.display = '';	}	return this;};Element.prototype.hide = function(delay){	if (this.style.display == 'none' || this._hiding) {	} else if (delay) {		var startOpacity = this.getOpacity();		var steps = startOpacity*20;		var timestep = delay/steps;		this._hiding = true;		for (var i = 1; i <= steps; i++) {			var opacity = startOpacity - (i/20);			var d = i*timestep;			this.setOpacity.delay(d, this, [opacity]);		}		(function(){			this._hiding = false;			this.hide().setOpacity(startOpacity);		}).delay(d+1, this);	} else {		this.style.display = 'none';	}	return this;};Element.prototype.toggle = function(delay){	if(this.style.display=='none')		this.show(delay);	else		this.hide(delay);	return this;};Element.prototype.setOpacity = function(opacity){	if(isIE()){		this.style.filter = (opacity==1) ? '' : 'alpha(opacity='+ opacity * 100 +')';	}	this.style.opacity = (opacity==1) ? '' : opacity;	return this;};Element.prototype.getOpacity = function(){	if (this.style.opacity && this.style.opacity.toString().length) {		return this.style.opacity;	 } else if (this.currentStyle && this.currentStyle.opacity && this.currentStyle.opacity.toString().length) {		return this.currentStyle.opacity;	} else if (window.getComputedStyle) {		return window.getComputedStyle(this, null).opacity;	} else {		return 1;	}};Element.prototype.setStyle = function(property, value){	switch (property){		case 'opacity': return this.setOpacity(value);		case 'float': property = isIE() ? 'styleFloat' : 'cssFloat';	}	property = property.camelCase();	this.style[property] = value;	return this;};Element.prototype.getStyle = function(property){	property = property.replace(/[A-Z]/g, function(match){		return '-'+ match.charAt(0).toLowerCase();	});	switch (property){		case 'opacity': return this.getOpacity();		case 'float': property = isIE() ? 'styleFloat' : 'cssFloat';	}	var camelProperty = property.camelCase();		if(typeof(this.style[camelProperty])!='undefined' && this.style[camelProperty].toString().length)		return this.style[camelProperty];	else if(this.currentStyle)		return this.currentStyle[camelProperty];	else if(window.getComputedStyle && window.getComputedStyle(this, null).getPropertyValue(property)!='undefined')		return window.getComputedStyle(this, null).getPropertyValue(property);	else if(window.getCascadedStyle)		return window.getCascadedStyle(this, null).getPropertyValue(property);};Element.prototype.setStyles = function(styles){	for(var style in styles){		this.setStyle(style, styles[style]);	}	return this;};Element.prototype.getStyles = function(){	var properties = [];	for(var i=0, argument; argument=arguments[i]; i++){		if(typeof(argument)=='string'){			properties.push(argument);		} else {			for(var j=0, arg; arg=argument[j]; j++){				properties.push(arg);			}		}	}	var result = {};	for(var i=0, property; property=properties[i]; i++){		result[property] = this.getStyle(property);	}	return result;};Element.prototype.getSize = function(){	return {x: this.offsetWidth, y: this.offsetHeight};};Element.prototype.getWidth = function(){	return this.getSize().x;};Element.prototype.getHeight = function(){	return this.getSize().y;};Element.prototype.getPosition = function(relative){	if((/^(?:body|html)$/i).test(this.tagName))		return {x:0, y:0};		relative = $(relative);		var node = this;	var posX = node.offsetLeft, posY = node.offsetTop;	while(node.offsetParent && node.offsetParent != document.body){		node = node.offsetParent;		posX += node.offsetLeft;		posY += node.offsetTop;	}	if(relative){		var relativePosition = relative.getPosition();		return {x: posX - relativePosition.x, y: posY - relativePosition.y};	}	return {x:posX, y:posY};};Element.prototype.scrollTo = function(x, y){	if((/^(?:body|html)$/i).test(this.tagName)){		this.window.scrollTo(x, y);	}else{		this.scrollLeft = x;		this.scrollTop = y;	}	return this;};Element.prototype.getScroll = function(){	if((/^(?:body|html)$/i).test(this.tagName))		return this.window.getScroll();	return {x: this.scrollLeft, y: this.scrollTop};};window.getScroll = document.getScroll = function(){	if(typeof window.pageYOffset != "undefined")		return {x: window.pageXOffset, y: window.pageYOffset};	if(typeof document.documentElement.scrollTop != "undefined" && document.documentElement.scrollTop > 0)		return {x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop};	if(typeof document.body.scrollTop != "undefined")		return {x: document.body.scrollLeft, y: document.body.scrollTop};};Element.prototype.setHTML = function(html){	this.innerHTML = html;	return this;};Element.prototype.getHTML = function(){	return this.innerHTML;};/* * Element.classList */if (typeof(document.createElement('p').classList)=='undefined'){	// ClassList	var ClassList = function(element){		this._element = element;				if (element.attachEvent){ // IE			function autoResetLength(){				if (event.propertyName != 'className') return;				this.classList.length = this.className.clean().split(' ').length;			}			element.addEvent('propertychange', autoResetLength);		}	};	ClassList.prototype = {		constructor: window.ClassList,		toString: function(){			return this._element.className.clean();		},		add: function (className){			this._element.className += ' ' + className;		},		contains: function(className){			return ( (' '+this._element.className.clean()+' ').indexOf(' '+className+' ') > -1 );		},		item: function(number){			return this._element.className.clean().split(/[\s]/)[number];		},		remove: function(className){			var reg = new RegExp('[\s]*'+className+'[\s]*');			this._element.className = this._element.className.replace(reg, ' ').clean();		},		toggle: function(className){			this.contains(className) ? this.remove(className) : this.add(className);		}	};	// Intégration aux Elements	if (Element.prototype.__defineGetter__){		Element.prototype._classList = null;		Element.prototype.__defineGetter__('classList', function(){			if (!this._classList)				this._classList = new ClassList(this);			return this._classList;		});		Element.prototype.__defineSetter__('classList', function(){});	}			// ClassList.length	ClassList.Length = function(classList){		this._element = classList._element;	};	ClassList.Length.prototype = {		constructor: window.ClassList.Length,		toString: function(){			return this._element.className.clean().split(' ').length;		}	};	// Intégration aux ClassLists	if (ClassList.prototype.__defineGetter__){		ClassList.prototype._length = null;		ClassList.prototype.__defineGetter__('length', function(){			if (!this._length)				this._length = new ClassList.Length(this);			return this._length;		});		ClassList.prototype.__defineSetter__('classList', function(){});	}}/* * Nodes */var Node = function(tagName, attributes){	attributes = attributes || {};	var node = document.createElement(tagName);	for(aName in attributes){		if (typeof(node.set)=='function'){			node.set(aName, attributes[aName]);		} else {			node[aName] = attributes[aName];		}	}	return node;};/*Element.prototype.adopt = function(){	Array.flatten(arguments).each(function(element){		element = document.id(element, true);		if (element) this.appendChild(element);	}, this);	return this;};*/Element.prototype._inserters = {	before: function(context, element){		if (element.parentNode) element.parentNode.insertBefore(context, element);	},	after: function(context, element){		if (!element.parentNode) return;		var next = element.nextSibling;		(next) ? element.parentNode.insertBefore(context, next) : element.parentNode.appendChild(context);	},	bottom: function(context, element){		element.appendChild(context);	},	top: function(context, element){		var first = element.firstChild;		(first) ? element.insertBefore(context, first) : element.appendChild(context);	}};Element.prototype._inserters.inside = Element.prototype._inserters.bottom;Element.prototype.inject = function(el ,where){	this._inserters[where || 'bottom'](this, $(el));	return this;};Element.prototype.grab = function(el ,where){	this._inserters[where || 'bottom']($(el), this);	return this;};Element.prototype.destroy = function(){	return this.parentNode.removeChild(this);};
