/**
 * Extend all Prototype DOM-element with getClassData() and setClassData() methods
 *
 * @author Jurriaan Persyn - http://www.jurriaanpersyn.com
 * @version 0.1
 */
Element.addMethods({
	/**
	 * Returns a string stored in the classnames of a DOM-element in the form of "$key$glue$data"
	 *
	 * @param DOM-element   element id or reference to a DOM-element
	 * @param string key the key of the classname
	 * @param	string glue optional, default "_"
	 * @return mixed_var null or string
	 */
	getClassData: function(element, key, glue)
	{
		element = $(element);
		if (!glue)
		{
			glue = "_";
		}
		key = key + glue;
		var data = null;
		element.classNames().each(function(className) {
			if (className.substr(0, key.length) === key)
			{
				data = className.replace(key, "");
			}
		});
		if (data)
		{
			data = decodeURIComponent(data);
		}
		return data;
	},
	/**
	 * Stores a string in the classnames of a DOM-element in the form of "$key$glue$data"
	 *
	 * @param DOM-element element id or reference to a DOM-element
	 * @param string key the key of the classname
	 * @param string data a string with some data
	 * @param	string glue optional, default "_"
	 * @param element Returns the element itself to allow chaining
	 */
	setClassData: function(element, key, data, glue)
	{
		if (!glue)
		{
			glue = "_";
		}
		element = $(element);
		var previousData = element.getClassData(key);
		if (previousData)
		{
			previousData = encodeURIComponent(previousData);
			element.removeClassName(key + glue + previousData);
		}
		data = encodeURIComponent(data);
		element.addClassName(key + glue + data);
		return element;
	},
	_eoo: true
});
