/*-------------------------------------------------------------------------------

	Namespace: u
	Utility methods

-------------------------------------------------------------------------------*/

adobe.u = {
/*-------------------------------------------------------------------------------

	Function: nonEvent
	Non propagating event

	Parameters:
	event - Event instance
	
	Returned Value:
	None
	
	Example:
>	Event.observe("foo", "click", adobe.u.nonEvent);

-------------------------------------------------------------------------------*/
	nonEvent: function (event) {
		return event.stop();
	},
/*-------------------------------------------------------------------------------

	Function: pixelate
	Append "px" to a number

	Parameters:
	integer - integer
	
	Returned Value:
	string
	
	Example:
>	adobe.u.pixelate(1);

-------------------------------------------------------------------------------*/
	pixelate: function(integer) {
		return parseInt(integer)+"px";
	},
/*-------------------------------------------------------------------------------

	Function: getSearchParam
	Get a value defined in the uri search parameter by it's id or all parameters in a hash.

	Parameters:
	id(optional) - string
	
	Returned Value:
	string or hash
	
	Example:
>	adobe.u.getSearchParam("foo");

-------------------------------------------------------------------------------*/
	getSearchParam: (function() {
		var _loadedParams;
		return function(id) {
			var params = _loadedParams || 
			(_loadedParams = window.location.search.toQueryParams());
			return (id) ? params[id] : params;
		}
	})(),
/*-------------------------------------------------------------------------------

	Function: freshenLocation
	Create a location string that would force a browser to check cache.

	Parameters:
	uri - string
	param (optional) - string

	Returned Value:
	string

	Example:
>	adobe.u.freshenLocation("/path"[, "myParam"])

-------------------------------------------------------------------------------*/
	freshenLocation: function(uri, param) {
		var query = "?",
		param = param || "time",
		i = uri.indexOf(query),
		time = query + param + "=" + new Date().getTime();
		
		if(i==-1) {
			return (uri + time);
		} else {
			var parts = adobe.u.unfreshenLocation(uri, param).split("?");
			return parts.join(time + ((parts[parts.length-1] == "") ? "" : "&"));
		}
	},
/*-------------------------------------------------------------------------------

	Function: unfreshenLocation
	Remove the query set by <freshenLocation> from a uri string
	
	Parameters:
	uri - string
	param (optional) - string
	
	Returned Value:
	string
	
	Example:	
>	adobe.u.unfreshenLocation("/path"[, "myParam"])


-------------------------------------------------------------------------------*/
	unfreshenLocation: function(uri, param) {
		var expression = new RegExp("([\\?&]?)"+(param||"time")+"=\\d*&?", "g");
		return uri.replace(expression, "$1");
	},
/*-------------------------------------------------------------------------------

	Function: revolve
	move the position of array items by specified number, wrapping items and keeping the length the same.

	Parameters:
	arr - Array instance
	integer - position or negative integer
	
	Returned Value:
	Array instance passed in
	
	Example:
>	adobe.u.revolve(["a","b","c"], -1)

-------------------------------------------------------------------------------*/
	revolve: function(arr, integer) {
		arr.unshift.apply(arr, arr.splice(integer, arr.length));
		return this;
	},
/*-------------------------------------------------------------------------------

	Function: toInt
	Convert a string to an integer

	Parameters:
	str - String instance
	
	Returned Value:
	integer

	Example:
>	adobe.u.toInt("1")

-------------------------------------------------------------------------------*/
	toInt: function(str) {
		return parseInt(str);
	}
};

/*-------------------------------------------------------------------------------

	Method: toInt

	Returned Value:
	integer

	Example:
>	("1").toInt();

-------------------------------------------------------------------------------*/

String.prototype.toInt = function() {
	return parseInt(this);
}

/*-------------------------------------------------------------------------------

	Method: pixelate
	Append "px" to a number

	Returned Value:
	string

	Example:
>	(1).pixelate();

-------------------------------------------------------------------------------*/

Number.prototype.pixelate = function() {
	return this + "px";
}

Object.extend(Array.prototype, {
	revolve: function(integer) {
		this.unshift.apply(this, this.splice(integer, this.length));
		return this;
	}
});
