/**
 **/
(function($)
{
	/**
	 */
	$.trimLeft = function(value, chars)
	{
		if (typeof chars == 'undefined') 
		{
			chars = "\n ";
		}
		
		while ((value.length > 0) &&
		(chars.indexOf(value.charAt(0)) >= 0)) 
		{
			value = value.substr(1, value.length - 1);
		}
		
		return value;
	};
	
	
	/**
	 */
	$.trimRight = function(value, chars)
	{
		if (typeof chars == 'undefined') 
		{
			chars = "\n ";
		}
		
		while ((value.length > 0) &&
		(chars.indexOf(value.charAt(value.length - 1)) >= 0)) 
		{
			value = value.substr(0, value.length - 1);
		}
		
		return value;
	};
	
	/**
	 * Replaces {variables} in text with items from variables.
	 * If a variable is not found it will be replaced with ''.
	 * If skipUnkownVariables is true variables which aren't not found are
	 * kept as they are.
	 */
	$.replaceVariables = function(text, variables, skipUnkownVariables)
	{
		variables = variables || {};
		var skip = skipUnkownVariables || false;
		var result = text;
		var regex = /\{(\w+)\}/g;
		var value;
		while ((part = regex.exec(text)) != null) 
		{
			value = variables[part[1]]; 
			if(typeof variables[part[1]] != 'undefined')
			{
				value = String(variables[part[1]]);
			}
			result = result.replace(part[0], value || ((skip) ? part[0] : ''));
		}
		return result;
	};
	
		
	/**
	 * Create a closure callback with the given scope
	 *
	 * @param {Object} scope
	 * @param {Function} fn
	 */
	$.makeCallback = function(scope, fn)
	{
		return function()
		{
			fn.apply(scope, arguments);
		};
	};
	
	/**
	 * Returns url-params
	 *
	 */
	$.getUrlVars = function(){
    	var vars = [], hash;
    	var hashes = window.location.href.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;
  	};
  
	/**
	 * Returns url-param for a given name
	 *
	 * @param {String} name
	 */
  	$.getUrlVar = function(name){
    	return $.getUrlVars()[name];
  	}
	
	
})(jQuery);

