﻿// -----------------------------------

// SimpleTimer.js
// IntroAjax.Timer component

///////////////////////////////////////////////////////////////////////////////

Type.registerNamespace('IntroAjax.Components');
    IntroAjax.Components.Timer = function IntroAjax$Components$Timer(userCallback) {
        this._interval = 10000;
        this._raiseTickDelegate = Function.createDelegate(this, this._raiseTick);
        this._userCallback = userCallback;
        this._timer = null;
    }
    function IntroAjax$Components$Timer$get_interval() {
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._interval;
    }
    function IntroAjax$Components$Timer$set_interval(value) {
        var e = Function._validateParams(arguments, [{name: "value", type: Number}]);
        if (e) throw e;

        this._interval = value;
    }
    function IntroAjax$Components$Timer$stop(){
       this._stopTimer();
    }
    function IntroAjax$Components$Timer$start(){
        this._startTimer();
    }
    function IntroAjax$Components$Timer$_raiseTick() {
        if (this._userCallback !== null)
            this._userCallback();
        this._startTimer();
    }
    function IntroAjax$Components$Timer$_startTimer() {
        this._timer = window.setTimeout(this._raiseTickDelegate, this.get_interval());
    }
    function IntroAjax$Components$Timer$_stopTimer() {
	    if (this._timer !== null) {
	 	    window.clearTimeout(this._timer);
		    this._timer = null;
       } 	
    }
    
    IntroAjax.Components.Timer.prototype = {
        get_interval:   IntroAjax$Components$Timer$get_interval,
        set_interval:   IntroAjax$Components$Timer$set_interval,
        stop:           IntroAjax$Components$Timer$stop,
        start:          IntroAjax$Components$Timer$start,
        _raiseTick:     IntroAjax$Components$Timer$_raiseTick,
        _startTimer:    IntroAjax$Components$Timer$_startTimer,
        _stopTimer:     IntroAjax$Components$Timer$_stopTimer
    }
    
IntroAjax.Components.Timer.registerClass('IntroAjax.Components.Timer');



