(function($){

	$.gup = function(arg) {

		var r = {};
		
		// no arg, returns all url parameters
		if (!arg) {
			var regex = /[\?&#]([^\?&#=]+)(?:=([^&#]*))?/g;
			while ((matches = regex.exec(window.location.href)) != null) r[ matches[1] ] = matches[2] == null ? '' : matches[2];
			return r;
		}
		
		// returns specified param value
		if (typeof arg == 'string') {
			arg = arg.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
			var matches = new RegExp("[\\?&#]" + arg + "=([^&#]*)").exec(window.location.href);
			return matches == null ? '' : matches[1];
		}
		
		// returns specified params values
		else if (typeof arg == 'object' && arg.length) {
			$(arg).each(function(i, name) {
				r[ name ] = $.gup(name);
			});
			return r;
		}

		return '';
	}

})(jQuery);
