// Periodical Executer
Object.extend(PeriodicalExecuter.prototype, {

	/**
	 * Restart function for PeriodicalExecuter
	 */
	restart: function() 
	{
		if (this.timer === null) 
		{
			this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
		}
	},
	
	_eoo: true
}); 

// Browser details
Prototype.Browser.Chrome = (navigator.userAgent.toLowerCase().indexOf('chrome') >- 1);
Prototype.Browser.IE6 = Prototype.Browser.IE && (parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5), 10) == 6);

/**
 * Extend all Prototype DOM-element with getClassData() and setClassData() methods
 */
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	object			options		specify if you're requesting an array, override the "glue"
	 * @return 	mixed_var 					null or string
	 */
	getClassData: function(element, key, options)
	{
		options = Object.extend({
			glue: '_',
			isArray: false,
			toInt: false
		}, options);
		element = $(element);
		
		key = key + options.glue;
		
		var data = null;
		if (options.isArray === true)
		{
			data = [];
		}
		
		element.classNames().each(function(className) {
			if (className.substr(0, key.length) === key) 
			{
				var value = className.replace(key, "");
				try
				{
					value = decodeURIComponent(value);
				}
				catch(ex)
				{
				}
				
				if (options.toInt)
				{
					value = parseInt(value, 10);
				}
				
				if (options.isArray)
				{
					data.push(value);
				}
				else
				{
					data = value;
				}
			}
		});
		
		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	object			options		override default "glue" param
	 * @param 	element						Returns the element itself to allow chaining
	 */
	setClassData: function(element, key, data, options)
	{
		options = Object.extend({
			glue: "_"
		}, options);
		
		element = $(element);

		var previousData = element.getClassData(key, { glue: options.glue });
		if (previousData)
		{
			previousData = encodeURIComponent(previousData);
			element.removeClassName(key + options.glue + previousData);
		}

		data = encodeURIComponent(data);
		element.addClassName(key + options.glue + data);
		
		return element;
	},
	
	_eoo: true
	
});