$.extend({
  getUrlVars: function(url){
	if( typeof url == "undefined" )
	{
		url = window.location.href;
	}
	
	var vars = [], hash;
	var hashes = url.slice(window.location.href.indexOf('?') + 1).split('&');
	
	for(var i = 0; i < hashes.length; i++)
	{
	  hash = hashes[i].split('=');
	  vars.push(hash[0]);
	  vars[hash[0]] = hash[1];
	}
	return vars;
  }
  ,
  getUrlVar: function(name, url)
  {
	if( typeof url == "undefined" )
	{
		url = window.location.href;
	}
	  
	return $.getUrlVars(url)[name];
  }
  ,
  setUrlVar: function(name, val, url)
  {
	  if( typeof url == "undefined" )
	  {
		  url = window.location.href;
	  }
	  url = url.replace( new RegExp('([?]|&)' + name + "=.*?(?:&|$)"), "$1" );
	  
	  if( url.indexOf( "?" ) == -1 )
	  {
		  url += "?";
	  }
	  else if( url[url.length-1] != "&" )
	  {
		  url += "&";
	  }
	  
	  return url += name + "=" + val;
  }
  ,
  setUrlVars: function(hash, url){
	  
	  if( typeof url == "undefined" )
	  {
		  url = window.location.href;
	  }
	  
	  jQuery.each(
		  hash, function (name, val)
		  {
			  url = jQuery.setUrlVar( name, val, url );
		  }
	  );
	  
	  return url;
  }
});
