
LoggedOutChecker = function() {
	this.PHPSESSID;
	this.PHPSESSIDCHECK;
	this.queue;
}

LoggedOutChecker.prototype.initialize = function (sessid){
	this.PHPSESSIDCHECK = sessid;

	// Session for the AJAX checks, so we don't create a new one each time
	this.PHPSESSID = '';

	// Check once a minute for login status (60000)
	this.queue = this.checkStatus.periodical(60000, this);
}

LoggedOutChecker.prototype.checkStatus = function (){

	var params = {'action': 'ajax_logged_in_check','PHPSESSIDCHECK':this.PHPSESSIDCHECK};
	if(this.PHPSESSID) {
		params.PHPSESSID = this.PHPSESSID;
	}

	//This code will send a data object via a GET request and alert the retrieved data.
	var jsonRequest = new Request.JSON({url: "index.php",
		onSuccess: function(response){
			if(response && this.PHPSESSID !== undefined) {
				this.PHPSESSID = response.PHPSESSID.replace(/^\&PHPSESSID=+/,"");

    			if(response.logged_in == '0') {
					showPopWin('index.php?action=logged_out_warning',400,300,null);
					$clear(this.queue);
					if($('login_info_true')) {
						$('login_info_true').style.display = 'none';
					}
					if($('login_info_false')) {
						$('login_info_false').style.display = 'block';
					}
					if($('admin_menu_link')) {
						$('admin_menu_link').style.display = 'none';
					}
				}
			}
		}.bind(this)
	}).get(params);
}

