var lhToggleOperStatus = false;
var lhToggleSound = 0;

Ajax.PeriodicalUpdater = Class.create();
Class.inherit( Ajax.PeriodicalUpdater, Ajax.Base, {

  initialize: function(_options) {
    this.setOptions(_options);
    this._options.onComplete = this.requestComplete.bind(this);
    this._options.onException = this.handleException.bind(this);
    this._options.onTimeout = this.handleTimeout.bind(this);
    this._options.timeout = (this._options.timeout || 7500);
    this.frequency = (this._options.frequency || 2);
    this.updater = {};
    this.update();
  },

  handleException: function(_request, ex) {
	if (this._options.handleError)
	  this._options.handleError("offline, reconnecting");
	this.stopUpdate();
	this.timer = setTimeout(this.update.bind(this), 1000);
  },

  handleTimeout: function(_request) {
	if (this._options.handleError)
	  this._options.handleError("timeout, reconnecting");
	this.stopUpdate();
	this.timer = setTimeout(this.update.bind(this), 7500);
  },

  stopUpdate: function() {
  	if( this.updater._options )
	    this.updater._options.onComplete = undefined;
    clearTimeout(this.timer);
  },

  update: function() {
    if( this._options.updateParams )
    	this._options.parameters = (this._options.updateParams)();
    this.updater = new Ajax.Request(this._options.url, this._options);
  },

  requestComplete: function(presponse) {
  	try {
        var xmlRoot = Ajax.getXml(presponse);
		if( xmlRoot ) {
	      (this._options.updateContent || Ajax.emptyFunction)( xmlRoot );
		} else {
		    if( this._options.handleError )
				this._options.handleError("reconnecting");
		}
	} catch(e) {
	}
    this.timer = setTimeout(this.update.bind(this), this.frequency * 1000);
  }
});

var HtmlGenerationUtils = {

  popupLink: function(link, title, wndid, inner, width, height,linkclass) {
  	return '<a href="'+link+'"'+(linkclass != null ? ' class="'+linkclass+'"' : '')+' target="_blank" title="'+title+'" onclick="this.newWindow = window.open(\''+link+'\', \''+
  			wndid+'\', \'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width='+width+',height='+height+',resizable=1\');this.newWindow.focus();this.newWindow.opener=window;return false;">'+
  			inner+'</a>';
  },

  generateOneRowTable: function(content) {
  	return '<table class="inner"><tr>' + content + '</tr></table>';
  },

  viewOpenCell: function(username,servlet,id,canview,canopen,ban,message,cantakenow) {
  		var cellsCount = 2;
  		var link = servlet+"?thread="+id;
 		var gen = '<td>';
 		if(canopen || canview ) {
			gen += HtmlGenerationUtils.popupLink( (cantakenow||!canview) ? link : link+"&viewonly=true", localized[canopen ? 0 : 1], "ImCenter"+id, username, 640, 480, null);
		} else {
			gen += '<a href="#">' + username + '</a>';
		}
		gen += '</td>';
		if( canopen ) {
			gen += '<td class="icon">';
			gen += HtmlGenerationUtils.popupLink( link, localized[0], "ImCenter"+id, '<img src="'+webimRoot+'/images/tbliclspeak.gif" width="15" height="15" border="0" alt="'+localized[0]+'">', 640, 480, null);
			gen += '</td>';
			cellsCount++;
		}
		if( canview ) {
			gen += '<td class="icon">';
			gen += HtmlGenerationUtils.popupLink( link+"&viewonly=true", localized[1], "ImCenter"+id, '<img src="'+webimRoot+'/images/tbliclread.gif" width="15" height="15" border="0" alt="'+localized[1]+'">', 640, 480, null);
			gen += '</td>';
			cellsCount++;
		}
		if( message != "" ) {
			gen += '</tr><tr><td class="firstmessage" colspan="'+cellsCount+'"><a href="javascript:void(0)" title="'+message+'" onclick="alert(this.title);return false;">';
			gen += message.length > 30 ? message.substring(0,30) + '...' : message;
			gen += '</a></td>';
		}
  		return HtmlGenerationUtils.generateOneRowTable(gen);
  },
  banCell: function(id,banid){
      return '<td class="icon">'+
          HtmlGenerationUtils.popupLink( webimRoot+'/operator/ban.php?'+(banid ? 'id='+banid : 'thread='+id), localized[2], "ban"+id, '<img src="'+webimRoot+'/images/ban.gif" width="15" height="15" border="0" alt="'+localized[2]+'">', 720, 480, null)+
          '</td>';
  },
  setcell: function(_table, row, id, pcontent) {
		var cell = CommonUtils.getCell( id, row, _table );
		if (cell) {
			cell.innerHTML = pcontent;
		}
	},
  setcellclass: function(_table, row, id, cl) {
		var cell = CommonUtils.getCell(id, row, _table);
		if (cell) {
			cell.className = cl;
		}
	}

};

Ajax.ThreadListUpdater = Class.create();
Class.inherit( Ajax.ThreadListUpdater, Ajax.Base, {

  initialize: function(_options) {
    this.setOptions(_options);
    this._options.updateParams = this.updateParams.bind(this);
    this._options.handleError = this.handleError.bind(this);
    this._options.updateContent = this.updateContent.bind(this);
    this._options.lastrevision = 0;
    this._options.lastsrvtime = 0;
    this.threadTimers = new Object();
	this.surfers = new Object();
    this.delta = 0;
	this.debug = false;
	this.browser = new BrowserInfo();
    this.t = this._options.table;
    this.surft = this._options.surftable;
	this.mont = this._options.montable;
    this.periodicalUpdater = new Ajax.PeriodicalUpdater(this._options);
	this.operstatus = null;
	this.soundmode = null;
  },

	logit: function(msg) {
		if (this.debug && window.console) {
			window.console.log(msg);
		}
	},
	updateParams: function() {
		var trq = '';
		var tsnd = '';
		if (lhToggleOperStatus) {
			lhToggleOperStatus = false;
			trq = '&toggle=1';
		}
		if (this.soundmode == null) {
			tsnd = '&tsnd=0';
		} else if (lhToggleSound > 0) {
			tsnd = '&tsnd='+lhToggleSound;
			lhToggleSound = 0;
		}
	  	return "company=" + this._options.company +
			"&since=" + this._options.lastrevision +
			"&stm=" + this._options.lastsrvtime +
			trq + tsnd;
	},
	setStatus: function(msg) {
        if (this._options.status) {
          this._options.status.innerHTML = msg;
        }
	},
	handleError: function(s) {
		this.setStatus( s );
	},
	monitor: function(node) {
		var viz = new Object();
		for (var i = 0; i < node.attributes.length; i++) {
			var attr = node.attributes[i];
			viz[attr.nodeName] = attr.nodeValue;
		}
		switch (node.tagName) {
			case 'thread':
				this.logit('monitor thread');
				if (viz['stateid'] == "closed") {
					this.threadTimers[viz['id']] = null;
					return 0;
				}
				if (this.threadTimers[viz['id']] == null) {
					this.threadTimers[viz['id']] = new Array(viz['vtime'], viz['modified'], viz['stateid']);
					if (viz['stateid'] == 'wait' || viz['stateid'] == 'prio') {
						return 1;
					}
				} else {
					this.threadTimers[viz['id']] = new Array(viz['vtime'], viz['modified'], viz['stateid']);
				}
				break;
			case 'surfer':
				this.logit('monitor surfer');
				if (this.surfers[viz['id']] == null) {
					this.surfers[viz['id']] = new Array(viz['lastentry'] * 1000, viz['lastmove'] * 1000, (new Date()).getTime());
					return 2;
				} else {
					var surfer = this.surfers[viz['id']];
					surfer[2] = (new Date()).getTime();
					this.surfers[viz['id']] = surfer;
				}
		}
		return 0;
	},

  updateThread: function(node) {
	var id, stateid, vstate, canview = false, canopen = false, canban = false, ban = null, banid = null;
	for( var i = 0; i < node.attributes.length; i++ ) {
		var attr = node.attributes[i];
		if( attr.nodeName == "id" )
			id = attr.nodeValue;
		else if( attr.nodeName == "stateid" )
			stateid = attr.nodeValue;
		else if( attr.nodeName == "state" )
			vstate = attr.nodeValue;
		else if( attr.nodeName == "canopen" )
			canopen = true;
		else if( attr.nodeName == "canview" )
			canview = true;
		else if( attr.nodeName == "canban" )
			canban = true;
		else if( attr.nodeName == "ban" )
			ban = attr.nodeValue;
		else if( attr.nodeName == "banid" )
			banid = attr.nodeValue;
	}

	var row = CommonUtils.getRow("thr"+id, this.t);
	if (stateid == "closed") {
		if (row) {
			this.t.deleteRow(row.rowIndex);
		}
		this.threadTimers[id] = null;
		return false;
	}

	var vname = NodeUtils.getNodeValue(node,"name");
	var vaddr = NodeUtils.getNodeValue(node,"addr");
	var vtime = NodeUtils.getNodeValue(node,"time");
	var agent = NodeUtils.getNodeValue(node,"agent");
	var modified = NodeUtils.getNodeValue(node,"modified");
	var message = NodeUtils.getNodeValue(node,"message");
	var etc = '<td>'+NodeUtils.getNodeValue(node,"useragent")+'</td>';

	if (ban != null) {
		etc = '<td>'+NodeUtils.getNodeValue(node,"reason")+'</td>';
	}

	if (canban) {
		etc += HtmlGenerationUtils.banCell(id,banid);
	}
	etc = HtmlGenerationUtils.generateOneRowTable(etc);
	var startRow = CommonUtils.getRow("t"+stateid, this.t);
	var endRow = CommonUtils.getRow("t"+stateid+"end", this.t);
	if (row != null && (row.rowIndex <= startRow.rowIndex || row.rowIndex >= endRow.rowIndex)) {
		this.t.deleteRow(row.rowIndex);
		this.threadTimers[id] = null;
		row = null;
	}
	if (row == null) {
		row = this.t.insertRow(startRow.rowIndex+1);
		row.className = (ban == "blocked" && stateid != "chat") ? "ban" : "in"+stateid;
		row.id = "thr"+id;
		this.threadTimers[id] = new Array(vtime,modified,stateid);
		CommonUtils.insertCell(row, "name", "visitor", null, null, HtmlGenerationUtils.viewOpenCell(vname,this._options.agentservl,id,canview,canopen,ban,message,stateid!='chat'));
		CommonUtils.insertCell(row, "contid", "visitor", "center", null, vaddr );
		CommonUtils.insertCell(row, "state", "visitor", "center", null, vstate );
		CommonUtils.insertCell(row, "op", "visitor", "center", null, agent );
		CommonUtils.insertCell(row, "time", "visitor", "center", null, this.getTimeSince(vtime) );
		CommonUtils.insertCell(row, "wait", "visitor", "center", null, (stateid!='chat' ? this.getTimeSince(modified) : '-') );
		CommonUtils.insertCell(row, "etc", "visitor", "center", null, etc );

		if( stateid == 'wait' || stateid == 'prio' )
			return true;
	} else {
		this.threadTimers[id] = new Array(vtime,modified,stateid);
		row.className = (ban == "blocked" && stateid != "chat") ? "ban" : "in"+stateid;
		HtmlGenerationUtils.setcell(this.t, row,"name",HtmlGenerationUtils.viewOpenCell(vname,this._options.agentservl,id,canview,canopen,ban,message,stateid!='chat'));
		HtmlGenerationUtils.setcell(this.t, row,"contid",vaddr);
		HtmlGenerationUtils.setcell(this.t, row,"state",vstate);
		HtmlGenerationUtils.setcell(this.t, row,"op",agent);
		HtmlGenerationUtils.setcell(this.t, row,"time",this.getTimeSince(vtime));
		HtmlGenerationUtils.setcell(this.t, row,"wait",(stateid!='chat' ? this.getTimeSince(modified) : '-'));
		HtmlGenerationUtils.setcell(this.t, row,"etc",etc);
	}
	return false;
  },

  updateSurfer: function(node) {
	var sid;
	for (var i = 0; i < node.attributes.length; i++) {
		var attr = node.attributes[i];
		if	(attr.nodeName == "id") {
			sid = attr.nodeValue;
			break;
		}
	}

	var addr = NodeUtils.getNodeValue(node,"addr");
	var bm = NodeUtils.getNodeValue(node,"bm");
	var bv = NodeUtils.getNodeValue(node,"bv");
	var bo = NodeUtils.getNodeValue(node,"bo");
	var page = NodeUtils.getNodeValue(node,"url");
	var pgcnt = NodeUtils.getNodeValue(node,"pgcnt");
	var lastmove = NodeUtils.getNodeValue(node,"lastmove") * 1000;
	var lastentry = NodeUtils.getNodeValue(node,"lastentry") * 1000;
	var link = page;
	var br = "<span class=\"break\">  &nbsp;</span>";
	switch (this.browser.make) {
		case 'Safari':
			page = page.replace(/([^ \?-]{50})/g, "$1"+br);
			break;
		case 'Chrome':
			page = page.replace(/([^ -]{50})/g, "$1"+br);
			break;
		case 'Firefox':
			page = page.replace(/([^ \?\/\&-]{50})/g, "$1<small> </small>");
			break;
		case 'Explorer':
			page = page.replace(/([^ \?]{50})/g, "$1<small> </small>");
			break;
		default:
			page = page.replace(/(\S{50})/g, "$1"+br);
	}
	var row = CommonUtils.getRow("surf"+sid, this.surft);
	var startRow = CommonUtils.getRow("tsurf", this.surft);
	var endRow = CommonUtils.getRow("tsurfend", this.surft);
	var instrRow = CommonUtils.getRow("instructions", this.surft);
	if (instrRow != null) {
		this.surft.deleteRow(instrRow.rowIndex);
	}
	if (row != null && (row.rowIndex <= startRow.rowIndex || row.rowIndex >= endRow.rowIndex)) {
		this.surft.deleteRow(row.rowIndex);
		this.surfers[sid] = null;
		row = null;
	}
	if (this.surfers[sid] == null) {
		this.surfers[sid] = new Array(lastentry, lastmove, (new Date()).getTime());
	}
	if (row == null) {
		row = this.surft.insertRow(startRow.rowIndex+1);
		row.className = "insurf";
		row.id = "surf" + sid;
		CommonUtils.insertCell(row, "addr", "visitor", "center", null, addr);
		CommonUtils.insertCell(row, "page", "page", "left", null, '<a href="'+link+'" target=_blank>'+page+'</a>');
		CommonUtils.insertCell(row, "pages", "visitor", "center", null, pgcnt);
		CommonUtils.insertCell(row, "time", "visitor", "center", null, this.getTimeSince(lastentry));
		CommonUtils.insertCell(row, "misc", "visitor", "center", null, bm + '&nbsp;' + bv + ' ' + bo);
		return true;
	} else {
		var surfer = this.surfers[sid];
		surfer[2] = (new Date()).getTime();
		this.surfers[sid] = surfer;
		HtmlGenerationUtils.setcell(this.surft, row, "time", this.getTimeSince(surfer[0]));
		if (addr != null && addr.length > 1) {
			HtmlGenerationUtils.setcell(this.surft, row, "addr", addr);
			HtmlGenerationUtils.setcell(this.surft, row, "page", '<a href="'+link+'" target=_blank>'+page+'</a>');
			HtmlGenerationUtils.setcell(this.surft, row, "pages", pgcnt);
			HtmlGenerationUtils.setcell(this.surft, row, "misc", bm + ' ' + bv + ' ' + bo);
		}
	}
	return false;
  },

  updateQueueMessages: function() {
  	function queueNotEmpty(t,id) {
		var startRow = $(id);
		var endRow = $(id+"end");
		if( startRow == null || endRow == null ) {
			return false;
		}
		return startRow.rowIndex+1 < endRow.rowIndex;
  	}
	var _status = $("statustd");
	if( _status) {
		var notempty = queueNotEmpty(this.t, "twait") || queueNotEmpty(this.t, "tprio") || queueNotEmpty(this.t, "tchat");
		_status.innerHTML = notempty ? "" : this._options.noclients;
		_status.height = notempty ? 5 : 30;
	}
  },

  getTimeSince: function(srvtime) {
	var secs = Math.floor(((new Date()).getTime()-srvtime-this.delta)/1000);
	var minutes = Math.floor(secs/60);
	var prefix = "";
	secs = secs % 60;
	if( secs < 10 )
		secs = "0" + secs;
	if( minutes >= 60 ) {
		var hours = Math.floor(minutes/60);
		minutes = minutes % 60;
		if( minutes < 10 )
			minutes = "0" + minutes;
		prefix = hours + ":";
	}

	return prefix + minutes+":"+secs;
  },

	updateTimers: function() {
	  for (var i in this.threadTimers) {
		  if (this.threadTimers[i] != null) {
			  var value = this.threadTimers[i];
			  var row = CommonUtils.getRow("thr"+i, this.t);
			  if( row != null ) {
				  function setcell(_table, row,id,pcontent) {
					  var cell = CommonUtils.getCell( id, row, _table );
					  if( cell )
						  cell.innerHTML = pcontent;
				  }
				  setcell(this.t, row,"time",this.getTimeSince(value[0]));
				  setcell(this.t, row,"wait",(value[2]!='chat' ? this.getTimeSince(value[1]) : '-'));
			  }
		  }
	  }
	},
	countChatters: function() {
		var w = 0;
		var c = 0;
		this.logit("countChatters()");
		for (var i in this.threadTimers) {
			if (/^\d+/.test(i)) {
				if (this.threadTimers[i] != null) {
					var value = this.threadTimers[i];
					if (value[2]!='chat') {
						++w;
					} else {
						++c;
					}
				}
			}
		}
		if (w > 0) {
			HtmlGenerationUtils.setcell(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrequests", '<a class="lhnonzero" href="/?cmd=lhmonitor">'+w+'</a>');
			HtmlGenerationUtils.setcell(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrqt", '<a class="lhnonzero" href="/?cmd=lhmonitor">chat&nbsp;requests:</a>');
			HtmlGenerationUtils.setcellclass(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrequests", "lhnonzero");
			HtmlGenerationUtils.setcellclass(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrqt", "lhnonzero");
		} else {
			HtmlGenerationUtils.setcell(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrequests", '0');
			HtmlGenerationUtils.setcell(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrqt", 'chat&nbsp;requests:');
			HtmlGenerationUtils.setcellclass(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrequests", "lhzero");
			HtmlGenerationUtils.setcellclass(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhrqt", "lhzero");
		}
		HtmlGenerationUtils.setcell(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhchats", c);
	},

	countSurfers: function() {
	  var n = 0;
	  for (var sid in this.surfers) {
		  if (/^\d+\.\d+$/.test(sid)) {
			  if (this.surfers[sid] != null) {
				  var surfer = this.surfers[sid];
				  var notseen = ((new Date()).getTime() - surfer[2]) / 1000;
				  if (notseen > 30) {
					  this.surfers[sid] = null;
				  } else {
					  ++n;
				  }
			  }
		  }
	  }
	  HtmlGenerationUtils.setcell(this.mont, CommonUtils.getRow("lhstats", this.mont),  "lhvisitors", n);
	},

	refreshSurfers: function() {
	  for (var sid in this.surfers) {
		  if (this.surfers[sid] != null) {
			  var surfer = this.surfers[sid];
			  var notseen = ((new Date()).getTime() - surfer[2]) / 1000;
			  var row = CommonUtils.getRow("surf"+sid, this.surft);
			  if (notseen > 30) {
				  this.surfers[sid] = null;
				  if (row != null) {
					  this.surft.deleteRow(row.rowIndex);
					  row = null;
				  }
			  }
		  }
	  }
	},

	setOperStatus: function(s) {
		if (this.operstatus != s) {
			this.operstatus = s;
			var os;
			if (s == 1) {
				os = '<span style="color:green">available</span>';
			} else {
				os = '<span style="color:red">not available</span>';
			}
			lhShowOperStat('you are <a href="#" onclick="lhToggleOperStatus=true; lhShowOperStat(\'updating...\'); return false;">'+os+'</a>&nbsp;');
		}
	},

	setSoundMode: function(sm) {
		if ((this.soundmode == null) || (this.soundmode != sm)) {
			this.soundmode = sm;
			this.logit('calling lhShowSound('+sm+')');
			lhShowSound(sm);
		}
	},

	updateContent: function(root) {
		var newAdded = false;
		var newSurfer = false;
		if (root.tagName == 'threads') {
			var _time = NodeUtils.getAttrValue(root, "time");
			var _revision = NodeUtils.getAttrValue(root, "revision");
			var _ost = NodeUtils.getAttrValue(root, "ost");
			var _snd = NodeUtils.getAttrValue(root, "snd");
			var firstrun = false;
			if (this._options.lastrevision == 0) {
				firstrun = true;
			}
			if (_time) {
				this.delta = (new Date()).getTime() - _time;
				this._options.lastsrvtime = Math.floor(_time / 1000);
			}
			if (_revision) {
				this._options.lastrevision = _revision;
			}
			this.logit('compact='+this._options.compact);
			for (var i = 0; i < root.childNodes.length; i++) {
				var node = root.childNodes[i];
				if (this._options.compact) {
					var ccode = this.monitor(node);
					if (!firstrun) {
						switch (ccode) {
							case 1:
								newAdded = true;
								break;
							case 2:
								newSurfer = true;
								break;
						}
					}
				} else {
					switch (node.tagName) {
						case 'thread':
							if (this.updateThread(node) && !firstrun) {
								newAdded = true;
							}
							break;
						case 'surfer':
							if (this.updateSurfer(node) && !firstrun) {
								newSurfer = true;
							}
							break;
					}
				}
			}
			this.setOperStatus(_ost);
			if (_snd != null) {
				this.setSoundMode(_snd);
			}
			if (this._options.compact) {
				this.countSurfers();
				this.countChatters();
			} else {
				this.updateQueueMessages();
				this.updateTimers();
				this.refreshSurfers();
				this.setStatus( "Up to date" );
			}
			if (newAdded) {
				window.focus();
				if ((this.soundmode & 2) != 0) {
					playSound(webimRoot+'/sounds/new_user.wav');
				}
			} else if (newSurfer) {
				this.logit('soundmode='+this.soundmode+', &1='+(this.soundmode & 1));
				if ((this.soundmode & 1) != 0) {
					playSound(webimRoot+'/sounds/new_surf.wav');
				}
			}
			if (firstrun) {
				var instrRow = CommonUtils.getRow("instructions", this.surft);
				if (instrRow != null) {
					instrRow.style.display = '';
				}
			}
		} else if( root.tagName == 'error' ) {
			this.setStatus(NodeUtils.getNodeValue(root,"descr") );
		} else {
			this.setStatus( "reconnecting" );
		}
	}
}
);

function lhShowOperStat(msg) {
	HtmlGenerationUtils.setcell($('lhbar'), CommonUtils.getRow("lhstats", $('lhbar')), 'lhstatus', msg);
}

var lhSoundMap = new Object();
lhSoundMap[1] = 'lhsndnewsurf';
lhSoundMap[2] = 'lhsndnewchat';
lhSoundMap[4] = 'lhsndnewmsg';

function lhPrintSoundControl(bit, val) {
	HtmlGenerationUtils.setcell($('lhbar'), CommonUtils.getRow("lhstats", $('lhbar')), lhSoundMap[bit], val);
}

function lhSoundControl(mode, bit) {
	return '<a href="#" onclick="lhToggleSound |= '+bit+'; lhPrintSoundControl('+bit+', \'***\'); return false;">'+(((mode & bit) != 0) ? 'on':'off')+'</a>&nbsp;';
}

function lhShowSound(snd) {
	lhPrintSoundControl(1, lhSoundControl(snd, 1));
	lhPrintSoundControl(2, lhSoundControl(snd, 2));
	lhPrintSoundControl(4, lhSoundControl(snd, 4));
}

function togglemenu() {
if($("sidebar") && $("wcontent") && $("togglemenu")) {
  if($("wcontent").className == "contentnomenu") {
    $("sidebar").style.display = "block";
    $("wcontent").className = "contentinner";
    $("togglemenu").innerHTML = localized[4];
  } else {
    $("sidebar").style.display = "none";
    $("wcontent").className = "contentnomenu"; 
    $("togglemenu").innerHTML = localized[3];
  }
}
}

Behaviour.register({
	'#togglemenu' : function(el) {
		el.onclick = function() {
			togglemenu();
		};
	}
});

var webimRoot = "";

EventHelper.register(window, 'onload', function(){
  webimRoot = updaterOptions.wroot;
  new Ajax.ThreadListUpdater(({table:$("threadlist"),surftable:$("surflist"),montable:$("lhbar"),status:$("connstatus")}).extend(updaterOptions || {}));
  if(!updaterOptions.havemenu) {
	  togglemenu();
  }	 
});

