String.prototype.trim = function() {
	str = this.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

function disableSelection(target){
	if (typeof target.onselectstart!="undefined") //IE route
	 	target.onselectstart=function(){return false}
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
		 target.style.MozUserSelect="none"
	else //All other route (ie: Opera)
	 	target.onmousedown=function(){return false}
}


redefine = {
	extend:function (obj, classes){
		var o = $(obj);
		if(typeof(classes) == 'string')
			classes = classes.split(',');
		for(var j = classes.length - 1; j >= 0 ; j--){
			var c = classes[j].trim();
			var co = null;

			try{
				co = eval(c);
			}catch(e){}

			if(co){
				for (var t in co)
    				o[t] = co[t];
				for (var t in co.prototype){
    				if(j != 0 && t == 'initialize')
    					o['__initialize_' + j] = co.prototype[t];
    				else
    					o[t] = co.prototype[t];
    			}
			}
		}
		o.initialize();
		for(var j = 1; j < classes.length; j++){
			try{
				eval('o.__initialize_' + j + "();");
			}catch(e){}
		}
		return o;
	},
	include: function(path){
		new Ajax.Request(path, {method: 'get', asynchronous:false});
	},

	require: function(path){
		var success = false;
		new Ajax.Request(path, {
			method: 'get',
			asynchronous:false,
			onSuccess:function(transport){
				success = true;
				eval(transport.responseText);

			},
			onFailure:function(){
				success = false;
			}
		});
		if(!success)
			throw new Error('asdf');
		return success;
	},
	_loadURL: function(path){
		new Ajax.Request(path, {
  			method: 'get',
  			onSuccess: function(transport) {
	    		//var notice = $('notice');
	    		//if (transport.responseText.match(/href="http:\/\/prototypejs.org/))
	      		//	notice.update('Yeah! You are in the Top 10!').setStyle({ background: '#dfd' });
	   			//else
	      		//notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' });
  			}
		});
	},

	util:{
		_findJObjects:function (){
			return $$('*[jclass]');
		},
		_extendJObjects:function(){
			var jobjects = redefine.util._findJObjects();
			for(var i = 0; i < jobjects.length; i++){
				redefine.extend(jobjects[i], jobjects[i].getAttribute('jclass'))
			}
		}
	}
};

Event.observe(document, 'dom:loaded', function(){
	redefine.util._extendJObjects();
});
