/*
jQuery Url Plugin
	* Version 1.1
	* 2010-04-09 00:31:00
	* 2009-03-22 19:30:05
	* URL: http://ajaxcssblog.com/jquery/url-read-get-variables/
	* Description: jQuery Url Plugin gives the ability to read GET parameters from the actual URL
	* Author: Matthias Jäggli
	* Changed by Rogerio Girodo Marques
	* Copyright: Copyright (c) 2009 Matthias Jäggli 
	* Licence: dual, MIT/GPLv2
*/
(function ($) {
	$.url = {};
	$.extend($.url, {
		_params: {},
		_location: '',
		init: function(){
			this.parse(document.location.href);
		},
		
		param: function(name,customHref){
			if(customHref) this.parse(customHref);
			return this._params[name] || null;
		},
		
		paramAll: function(customHref){
			if(customHref) this.parse(customHref);
			return this._params;
		},
		
		parse: function(cString) {
			
			var paramsRaw = "";
			this._params = {};
			
			try{
				this._location = cString.split("?", 2)[0] || null;
				paramsRaw = (cString.split("?", 2)[1] || "").split("#")[0].split("&") || [];
				for(var i = 0; i< paramsRaw.length; i++){
					var single = paramsRaw[i].split("=");
					if (single[0]) {
						//this._params[single[0]] = unescape(single[1]);
						this._params[single[0]] = unescape(single[1].replace(/\+/g, " ")); //for handle plus (+) signs
					}
				}
			}
			catch(e){
				//alert(e);
			}
		},
		
		doQueryString: function(customHref) {
			if(customHref) this.parse(customHref);
			var qs = '?';
			for(var p in this._params){
				qs = qs + p + '=' + this._params[p] + '&';
			}
			return qs.substr(0,qs.length-1);
		},
		
		getLocation: function(customHref){
			if(customHref) this.parse(customHref);
			return this._location;
		},

		setHref: function(customHref){
			this.parse(customHref);
		},

		setParam: function(name,value){
			this._params[name] = value;
		}
	});
	$.url.init();})(jQuery);
