$.extend({
	_enc_div: null,
	htmlenc: function(val) {
		if (this._enc_div == null) this._enc_div = $('<div />');
		this._enc_div.text(val);
		return this._enc_div.html().replace("\n", "<br />");
	},
	htmldec: function(val) {
		if (this._enc_div == null) this._enc_div = $('<div />');
		this._enc_div.html(val);
		return this._enc_div.text();
	},
	preload_images: function(images, pointer, callback) {
		if (images.length > pointer) {
			$('<img />').load(function() {
				$.preload_images(images, pointer + 1, callback);
			}).attr('src', images[pointer]);
		} else {
			callback();
		}
	}
});

var lock = false;
/*
//extend standard classes
if (!Array.prototype.every) {
	Array.prototype.every = function(fun , thisp) {
		var len = this.length >>> 0;
		if (typeof fun != "function")
			throw new TypeError();

		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this && !fun.call(thisp, this[i], i, this))
				return false;
		}

		return true;
	};
}

if (!Array.prototype.some) {
	Array.prototype.some = function(fun , thisp) {
		var i = 0,
			len = this.length >>> 0;

		if (typeof fun != "function")
			throw new TypeError();

		var thisp = arguments[1];
		for (; i < len; i++) {
			if (i in this && fun.call(thisp, this[i], i, this))
				return true;
		}

		return false;
	};
}

if (!Array.prototype.filter) {
	Array.prototype.filter = function(fun , thisp) {
		var len = this.length >>> 0;
		if (typeof fun != "function")
			throw new TypeError();

		var res = [];
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this) {
				var val = this[i]; // in case fun mutates this
				if (fun.call(thisp, val, i, this))
					res.push(val);
			}
		}

		return res;
	};
}

if (!Array.prototype.map) {
	Array.prototype.map = function(fun , thisp) {
		var len = this.length >>> 0;
		if (typeof fun != "function")
			throw new TypeError();

		var res = new Array(len);
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this)
				res[i] = fun.call(thisp, this[i], i, this);
		}

		return res;
	};
}

if (!Array.prototype.forEach) {
	Array.prototype.forEach = function(fun , thisp) {
		var len = this.length >>> 0;
		if (typeof fun != "function")
			throw new TypeError();

		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this)
				fun.call(thisp, this[i], i, this);
		}
	};
}

if (!Array.prototype.lastIndexOf) {
	Array.prototype.lastIndexOf = function(elt , from) {
		var len = this.length;

		var from = Number(arguments[1]);
		if (isNaN(from)) {
			from = len - 1;
		} else {
			from = (from < 0) ? Math.ceil(from) : Math.floor(from);
			if (from < 0)
				from += len;
			else if (from >= len)
				from = len - 1;
		}

		for (; from > -1; from--) {
			if (from in this && this[from] === elt)
				return from;
		}
		return -1;
	};
}

if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(elt , from) {
		var len = this.length >>> 0;

		var from = Number(arguments[1]) || 0;
		from = (from < 0) ? Math.ceil(from) : Math.floor(from);
		if (from < 0)
			from += len;

		for (; from < len; from++) {
			if (from in this && this[from] === elt)
				return from;
		}
		return -1;
	};
}

if (!String.prototype.trim) {
	String.prototype.trim = function() {
		return this.replace(/(^\s*)|(\s*$)/g, '');
	}
}

if (!String.prototype.trimLeft) {
	String.prototype.trimLeft = function() {
		return this.replace(/(^\s*)/g, '');
	}
}

if (!String.prototype.trimRight) {
	String.prototype.trimRight = function() {
		return this.replace(/(\s*$)/g, '');
	}
}*/

$(function() {
	if (lock) return;
	lock = true;

	// setup the ajax event handler for processing indicator
	$('#ajax_communication_indicator').ajaxStart(function() {
		  $(this).show();
	}).ajaxStop(function() {
		  $(this).hide();
	});
});


