new function () {


function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

if ( getInternetExplorerVersion() == 6 )
	var isIE6 = true
else
	var isIE6 = false

//old ie6 detection
//var isIE6 = (typeof document.addEventListener != 'function');

var extend = function (object, parent, safe) {
	for (var i in parent) if (!safe || !(i in object)) {
		object[i] = parent[i];
	}
	return object;
};

var implement = function (object, parent, safe) {
	return extend(object.prototype, parent, safe);
};

var tagsRE = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
	commentsAndPhpTagsRE = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;

implement(String, {
	imageUrl: function(type) {
		var string = this;
		if (!string.match(/\.(?:png|gif|jpg|jpeg)$/)) {
			string += isIE6 ? '.gif' : '.png';
		}
		return (type ? string.replace(/\*/, type) : string) + '';
	},
	stripTags: function (allowed) {
		allowed = allowed ? (
			String(allowed || "")
				.toLowerCase()
				.match(/<[a-z][a-z0-9]*>/g)
			|| []).join('') : false;
		return this
			.replace(commentsAndPhpTagsRE, '')
			.replace(tagsRE, allowed ? function($0, $1){
				return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
			} : '');
	}
}, false);

// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
implement(Function, {
	bind : function( obj ) {
		var slice = [].slice,
			args = slice.call(arguments, 1),
			self = this,
			nop = function () {},
			bound = function () {
				return self.apply(
					this instanceof nop ? this : ( obj || {} ),
					args.concat( slice.call(arguments) )
				);
			};
		nop.prototype = self.prototype;
		bound.prototype = new nop();
		return bound;
	}
}, 'safe');

implement(Number, {
	equals: function (to, accuracy) {
		if (arguments.length === 1) accuracy = 8;
		return Number(this).toFixed(accuracy) == Number(to).toFixed(accuracy);
	},
	between: function (from, to, equals) {
		return this > from && this < to || (
			equals && (this == from || this == to)	
		);
	},
	toRange: function (from, to) {
		return Math.min(to, Math.max(from, this));
	}
}, 'safe');

extend(Object, {
	adopt: function (child, parent) {
		var c = function () {}, prototype = 'prototype';
		c[prototype] = parent[prototype];
		c[prototype].constructor = parent;
		return child[prototype] = new c();
	},
	extend: extend,
	implement: implement
}, false);

extend(Array, {
	range: function (from, to) {
		var array = [];
		for (;from <= to; from++) array.push(from);
		return array;
	},
	erase: function (array, item) {
		for (var i = array.length; i--;) if (item == array[i]) {
			array = array.slice(i, 1);
		}
		return array;
	},
	random : function (array) {
		return array[Math.floor(Math.random() * array.length)];
	},
	associate: function (values, keys) {
		var obj = {}, length = Math.min(values.length, keys.length);
		for (var i = 0; i < length; i++) obj[keys[i]] = values[i];
		return obj;
	},
	hardLoop: function (args) {
		var interval = setInterval(function () {
			if (!args.cond() || args.fn() === false) {
				clearInterval(interval);
				$.isFunction(args.ready) && args.ready();
			}
		}, 10);
		return function () { clearInterval(interval); };
	},
	hardEachBack: function (array, callback) {
		var i = array.length;
		return Array.hardLoop({
			cond: function () { return i--; }, fn: function () {
				callback(array[i]);
			}
		});
	}
}, false);

}();
