function LogoutNotifier(logoutId, notificationMinutes, timeout, url, clientId) {
    this.id = clientId;

    this.totalTime = timeout;

    this.logoutElement = document.getElementById(logoutId);

    var myTimeout = timeout - notificationMinutes;
    if (myTimeout <= 0) {
        myTimeout = 0;
    }

    this.notify = myTimeout;

    this.notificationMinutes = notificationMinutes;

    this.minutes = (myTimeout === 0) ? timeout : notificationMinutes;

    this.pingUrl = url;
    this.timerId = null;
    this.popupRendered = false;

    if (typeof LogoutNotifier.init === 'undefined') {

        LogoutNotifier.prototype.requestData = function (updateTime)
        {
            // initiate the AJAX request...
            var self = this;
            var rqstURL = self.pingUrl + "?update=" + updateTime;
            var ajaxRqst = new Ajax.Request(rqstURL, {
                method: 'post',
                asynchronous: true,
                onException: function (transport, e) {
                    alert(e);
                },
                onSuccess: function (transport) {
                    self.successFunc(transport);
                }
            });
        };

        LogoutNotifier.prototype.pollTimer = function () {
            var self = this;
            if (this.timerId !== null) {
                clearTimeout(this.timerId);
            }
            this.timerId  = setTimeout(function () {
                self.requestData(false);
            }, 5000);
        };

        LogoutNotifier.prototype.successFunc = function (transport) {
            var json = transport.responseText.evalJSON();
            var value = this.totalTime;
            var self = this;
            if (!json || !json.lastAccessedTime) {
                this.logoutElement.click();
            }
            value = (this.totalTime - Number(json.lastAccessedTime));
            if (isNaN(value) || value < 0) {
                this.logoutElement.click();
            } else if (value < this.minutes) {
                if (!this.popupRendered) {
                    PopupWindowController.showPopup(this.id, true);
                    this.popupRendered = true;
                }
                if (this.timerId !== null) {
                    clearTimeout(this.timerId);
                }
                this.timerId = setTimeout(function () {
                    self.pollTimer();
                }, 1000);
            } else if (value > this.minutes) {
                if (this.popupRendered) {
                    PopupWindowController.hidePopup(this.id);
                    this.popupRendered = false;
                }
                this.timerId  = setTimeout(function () {
                    self.requestData(false);
                }, value - this.minutes);
            }
        };

        LogoutNotifier.prototype.startTimer = function () {
            var self = this;
            this.timerId  = setTimeout(function () {
                self.requestData(false);
            }, this.notify);
        };

        LogoutNotifier.prototype.extendSession = function () {
            PopupWindowController.hidePopup(this.id);
            this.popupRendered = false;
            if (this.timerId !== null) {
                clearTimeout(this.timerId);
            }
            this.requestData(true);
            this.startTimer();
            return false;
        };

        LogoutNotifier.init = true;
    }
}

