
	function listen(event, elem, func) {
		if(elem == undefined) return;
	    if (elem.addEventListener)  // W3C DOM
	        elem.addEventListener(event,func,false);
	    else if (elem.attachEvent) { // IE DOM
	        var r = elem.attachEvent("on"+event, func);
			return r;
	    }else throw 'No es posible añadir evento';
	}
		
	$.fn.extend({
		findPos : function() {
			obj = $(this).get(0);
			var curleft = obj.offsetLeft || 0;
			var curtop = obj.offsetTop || 0;
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
			return {x:curleft, y:curtop};
		}
	});
	
	$.fn.extend({
		visible : function() {
			if($(this).css("display") == "block" || $(this).css("display") == "" || !$(this).attr("style")) return true;
			return false;
		}
	});
	
	
	// cross-browser opacity
	$.fn.extend({
		opacity : function(value) {
			$(this)
				.css("opacity", value)
				.css("-moz-opacity", value)
				.css("filter", "alpha(opacity = " + (value * 100) + ")")
				.css("zoom", "1"); // ie7
		}
	});
	
	// toggle
	$.fn.extend({
		toggleVisible : function() {
			if($(this).visible()) $(this).hide();
			else $(this).show();
		}
	});
	
	// check if element exists
	$.fn.extend({
		exists : function() {
			var obj = $(this).get(0);
			if(obj) return true;
			else return false;
		}
	});
	
	$.fn.replace = function() {
		var stack = [];
		return this.domManip(arguments, true, 1, function(a){
			this.parentNode.replaceChild( a, this );
			stack.push(a);
		}).pushStack( stack );
	};
	
	Array.prototype.inArray = function(element) {
		for(var i=0; i < this.length; i++){
			if(arguments.length > 1){
				if(this[i][arguments[1]] == element) return true;
			}else{
				if(this[i] == element) return true;
			}
		}
		return false;
	}
	
	Array.prototype.remove = function(s){
		for(var i = 0; i < this.length; i++){
			if(s == this[i]) this.splice(i, 1);
		}
	}
	
	Array.prototype.arrayElementIndex = function(element) {
		for(var i=0; i < this.length; i++){
			if(this[i] == element) return i;
		}
		return false;
	}
	