/*USAGE:
var x= new xTimer(displayTime,1); 
OR var x= new xTimer(displayTime); FOLLOWED BY x.interval=1;x.start();
function displayTime() executed every interval seconds
return "stop(); -will stop the timer
*/

function xTimer(callback, interval ) {  
    if (interval==undefined) interval=0;
    
    this.interval = interval;
    
    currentlyExecuting = false;
	timer=null;
	
    start=  function () {				
   			    if (timer) clearInterval(timer);
			    timer = setInterval(function(){
			      if (!currentlyExecuting) {
			      try {
			        currentlyExecuting = true;
			        eval(callback());
			      } finally {
			        currentlyExecuting = false;
			      }
			    }
			  }, interval * 1000);
			    
			  }
			;
			
    stop=  function () {    
			    if (!timer) return;
			    clearInterval(timer);
			    timer = null;			    
			  }
			;

    
  if (interval!==0) start();
  this.start=start;
  this.stop=stop;
  }


