/**
* @desc Allows you to perform an action every X amount of seconds
*
* @package Codereck UI
*
* @copyright © 2007 Ryan Zec
*
* @license Dual MIT/GPL
*/
(function($)
{
	//create the codereck scope
	$.cr = $.cr || {};

	//function to create new instance of a codereck beat
	$.create_beat = function(name, options, beat_function)
	{
		options.name = name;
		var beat_instance = new $.cr.beat(options, beat_function);
		$('body').data(name, beat_instance);
	}

	//function to delete an instance of the codereck beat
	$.delete_beat = function(name)
	{
		$('body').data(name).clear();
		$('body').removeData(name);
	}

	//codereck tab class
	$.cr.beat = function(options, beat_function)
	{
		this.beat_function = beat_function;

		this.options = $.extend(
		{
			name: null,
			delay: 1000
		},
		options);

		this.start();
	}

	$.extend($.cr.beat.prototype,
	{
		start: function()
		{
			this.options.timeout_object = setTimeout("$('body').data('" + this.options.name + "').beat();" , this.options.delay);
		},

		clear: function()
		{
			clearTimeout(this.options.timeout_object);
		},

		beat: function()
		{
			this.options.timeout_object = setTimeout("$('body').data('" + this.options.name + "').beat();" , this.options.delay);
			this.beat_function();
		}
	});
})(jQuery);