$.noConflict();

if (typeof React == "undefined") this.React = {};

(function($){
	$.extend(true, React, {
		jQuery : $,
		cookies : {},
		base : '',
		initialized : false,
		
		init : function()
		{
			this.readCookies();
			this.base = $('head base').first().attr('href');
			this.path = this.parseUri(this.base).path;
	
			this._init(React);
		},
		
		_init : function (obj)
		{
			for (o in obj){
				if (typeof obj[o] == "object" && obj.constructor == Object)
					methods = this._init(obj[o]);
				else if (obj != React && o == 'init')
					obj[o]();
			}
		},
		
		readCookies : function(clearExistingCookies)
		{
			if (clearExistingCookies)
				React.cookies = {};
			
			jQuery.each(document.cookie.split(';'), React._readCookie);
		},
		
		_readCookie : function(k, v)
		{
			p = v.indexOf('=');
			cName = jQuery.trim(v.substring(0, p));
			cValue = v.substring(p+1);
			// Only use first cookie value
			if (React.cookies[cName] == undefined)
				React.cookies[cName] = cValue;
		},
		
		//parseUri 1.2.2
		//(c) Steven Levithan <stevenlevithan.com>
		//MIT License
		parseUri : function(str) {
			var	o   = this.parseUriOptions,
				m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
				uri = {},
				i   = 14;
	
			while (i--) uri[o.key[i]] = m[i] || "";
	
			uri[o.q.name] = {};
			uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
				if ($1) uri[o.q.name][$1] = $2;
			});
	
			return uri;
		},
		
		parseUriOptions : {
			strictMode: false,
			key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
			q:   {
				name:   "queryKey",
				parser: /(?:^|&)([^&=]*)=?([^&]*)/g
			},
			parser: {
				strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
				loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
			}
		}
	});
	
	$(jQuery.proxy(React.init, React));
})(jQuery);
