// require 'libs/prototype/prototype'
// require 'itools/core/objectStore'

function xTimeOut( xTimerID ) {
	xTimer = getObj( xTimerID );
	
	if ( xTimer ) {
		xTimer.onTimeOut.call( xTimer.caller );
	};
}

// Класс для упрощения работы с функциями window.setInterval и window.setTimeout.
// После истекания времени задержки, вызывается событие "onTimeOut"

XTimer = Class.create({

	// xtime - интервал задержки в милисекундах
	// loop - флаг цикличности таймера (default: true)
	
	initialize : function( xtime, loop ) {
		this.loopTimerID = null;	// для clearInterval
		if ( loop == null ) loop = true;
		
		this.xtime = xtime;
		this.loop = loop;
		this.caller = this;
		this.options = {}; // хеш параметров, которые нужно передать вовнутрь объекта
		
		this.oid = storeObj( this );
	},

	start : function() {
		if ( this.loop ) {
			this.loopTimerID = setInterval( "xTimeOut( '" + this.oid + "' )", this.xtime );
		} else {
			setTimeout( "xTimeOut( '" + this.oid + "' )", this.xtime );
		}
	},

	stop : function() {
		if ( this.loopTimerID ) {
			clearInterval( this.loopTimerID );
			this.loopTimerID = null;
		}
	},

	onTimeOut : function() {}
});
