/* 
 * jQuery Extended Library.
 * Copyright © 2009 All Rights Reserved.
 */
(function($){

	$.fn.enabled = function(flag)
	{
	    if (flag) {
	        return $(this).removeAttr('disabled');
	    } else {
	        return $(this).attr('disabled', 'disabled');
	    }
	};

	$.fn.readonly = function(flag)
	{
		if (flag) {
			return $(this).attr('readonly', 'readonly');
		} else {
			return $(this).removeAttr('readonly');
		}
	};

	$.fn.id = function()
	{
		return $(this).attr('id') || null;
	};

	$.fn.bg = function(url)
	{
		if (url == null) {
			var bg = $(this).css('background-image');
			bg = bg.replace(/^url\(("|)/,'');
			bg = bg.replace(/("|)\)$/,'');
			return bg;
		} else {
			$(this).css('background-image', 'url("' + url + '")');
		}
	};

	$.fn.clickpress = function(func)
	{
		$(this).click(function(){ return func(); });
		$(this).keypress(function(e){
			var keyCode;
			if (e.keyCode) keyCode = e.keyCode;
			else if (e.which) keyCode = e.which;
			if (keyCode != 13 && keyCode != 32) return true;
			return func();
		});
		return $(this);
	};

	$.overArray = function(a1, a2)
	{
		for (var i1 = 0; i1 < a1.length; i1++) {
			for (var i2 = 0; i2 < a2.length; i2++) {
				if (a1[i1] == a2[i2]) return true;
			}
		}
		return false;
	}

})(jQuery);
