/*
 * Joom!Fish - Multi Lingual extention and translation manager for Joomla!
 * Copyright (C) 2003-2007 Think Network GmbH, Munich
 *
 * All rights reserved.  The Joom!Fish project is a set of extentions for
 * the content management system Joomla!. It enables Joomla!
 * to manage multi lingual sites especially in all dynamic information
 * which are stored in the database.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */

 jQuery.timer = function (interval, callback)

 {

 /**

  *

  * timer() provides a cleaner way to handle intervals  

  *

  *	@usage

  * $.timer(interval, callback);

  *

  *

  * @example

  * $.timer(1000, function (timer) {

  * 	alert("hello");

  * 	timer.stop();

  * });

  * @desc Show an alert box after 1 second and stop

  * 

  * @example

  * var second = false;

  *	$.timer(1000, function (timer) {

  *		if (!second) {

  *			alert('First time!');

  *			second = true;

  *			timer.reset(3000);

  *		}

  *		else {

  *			alert('Second time');

  *			timer.stop();

  *		}

  *	});

  * @desc Show an alert box after 1 second and show another after 3 seconds

  *

  * 

  */

	var interval = interval || 100;



	if (!callback)

		return false;

	

	_timer = function (interval, callback) {

		this.stop = function () {

			clearInterval(self.id);

		};

		

		this.internalCallback = function () {

			callback(self);

		};

		

		this.reset = function (val) {

			if (self.id)

				clearInterval(self.id);

			

			var val = val || 100;

			this.id = setInterval(this.internalCallback, val);

		};

		

		this.interval = interval;

		this.id = setInterval(this.internalCallback, this.interval);

		

		var self = this;

	};

	

	return new _timer(interval, callback);

 };