/**
 * Binds a function to a specific scope in which it will be executed
 * @param obj  The scope-object
 * @return A function-wrapper that will be call in the scope of obj
 */
Function.prototype.bind = function(obj) {
	var method = this,
		temp = function() {
			return method.apply(obj, arguments);
		};
	return temp;
}



//YUI Basic
var yDom = YAHOO.util.Dom;
var yEvent = YAHOO.util.Event;



//***************** EXTEND ARRAY ******************

//IndexOf
if( !YAHOO.lang.isFunction(Array.indexOf) ) {
	Array.prototype.indexOf = function(element) {
		for ( var i = 0; i < this.length; i++ ) {
			if( element==this[i] ) return i;
		}
		return -1;
	}
}



//Contains
Array.prototype.contains = function (element) {
	for ( var i = 0; i < this.length; i++ ) {
		if ( this[i]==element ) {
			return true;
		}
	}
	return false;
};



//Remove
Array.prototype.remove = function(element){
	for ( var i = 0; i < this.length; i++ ) {
		if( element==this[i] ) this.splice(i, 1);
	}
}



//Swap
Array.prototype.swap = function(a, b) {
	var tmp = this[a];
	this[a] = this[b];
	this[b] = tmp;
}



//***************** NODE EXTEND ******************

function swapNodes(a, b) {
	var aparent = a.parentNode;
	var asibling = a.nextSibling===b ? a : a.nextSibling;
	b.parentNode.insertBefore(a, b);
	aparent.insertBefore(b, asibling);
}



//***************** TRIM FUNKTIONEN ******************

function lTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function rTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim( value ) {
	return lTrim(rTrim(value));
}