///////////////////////////////////
//         ajax im 3.41          //
//    AJAX Instant Messenger     //
//   Copyright (c) 2006-2008     //
//    http://www.ajaxim.com/     //
//   Do not remove this notice   //
///////////////////////////////////


/**
* Class to handle buddylist events
*
* @author Joshua Gross
**/

var myAccordion = null;

var Buddylist = {
	buddyListWin: null,  // buddy list window

	/**
	* Process the creation of the buddy list window
	*
	* @author Joshua Gross
	**/
	create: function() {
		Event.observe(window, 'resize', Buddylist.fixBuddyList);

		if(!$('bl')) {
			this.buddyListWin = new Window({id: 'bl', className: "dialog", width: 210, height: (Browser.height() - 60), zIndex: 100, resizable: true,  title: 'QuickieChat', draggable: true, closable: false, maximizable: false, detachable: false, minWidth: 205, minHeight: 150, showEffectOptions: {duration: 0}, hideEffectOptions: {duration: 0}});
			this.buddyListWin.setConstraint(true, {left: 0, right: 0, top: 0, bottom: 0});
		}

		this.buddyListWin.getContent().innerHTML = '<div id="blTopToolbar">' +
		(typeof(Status) != 'undefined' ? '<div id="statusSettings"><input type="text" id="customStatus" onkeypress="Status.processCustomAway(event);" style="display:none" onblur="if($(\'customStatus\').style.display != \'none\') { $(\'customStatus\').style.display = \'none\'; $(\'curStatus\').style.display = \'block\'; }" /><a href="#" id="curStatus" onclick="Status.toggleStatusList();return false;">' + Languages.get('available') + '</a></div>' : '') +
		'</div><div id="blContainer" style="overflow: hidden;"><div id="test-accordion" class="accordion">'+
	'<div class="accordion-toggle">'+Languages.get('buddyList')+'</div>'+
	'<div class="accordion-content"><ul id="buddylist" class="sortable box"><li style="display:none"></li></ul></div>'+
	'<div id="space">'+'</div>'+'<div class="accordion-toggle">'+Languages.get('newRoom')+'</div>'+
	'<div class="accordion-content"><div id="blRoomContainer"></div><div class="accordion-set"><img src="themes/default/choosechat.jpg" border="0" alt="'+Languages.get('chooseAChat')+'"/><br /></div><div class="accordion-textBlue">'+Languages.get('chooseAChat')+'</div><div></div></div></div></div><div id="blBottomToolbar"></div>';
		
		Event.observe(this.buddyListWin.getContent(), 'contextmenu', function() { return false; });

		$('bl_minimize').setStyle({left: (this.buddyListWin.getSize()['width'] - 21) + 'px'});

		this.sizeBuddyList();

		this.buddyListWin.showCenter(false, (((Browser.height()-40) / 2) - (this.buddyListWin.getSize()['height'] / 2)), (buddyListLoc == 0 ? 10 : (Browser.width() - this.buddyListWin.getSize()['width'] - 10)));
		this.buddyListWin.toFront();

		this.list = {};
		this.listObjects = {};
		this.blocked = {};
		
		if(!isRegistered){
			
			$('blTopToolbar').innerHTML = '<span class="toolbarButton">'+
							'<span class="toolbarButton">'+
								'<img id="imanyone" src="themes/'+theme+'/window/imanyone.png" class="toolbarButton" onclick="Dialogs.newIM();" alt="' + Languages.get('IMAnyoneButton') + '" title="' + Languages.get('IMAnyoneButton') + '" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" />' +
							'</span>' +
							'<span class="toolbarButton">'+
								'<img id="toggleaudio" src="themes/'+theme+'/window/audio_'+(audioNotify ? 'on' : 'off')+'.png" onclick="toggleAudio();" alt="' + Languages.get('toggleSoundButton') + '" title="' + Languages.get('toggleSoundButton') + '" />'+
							'</span>'+
							(typeof(Status) != 'undefined' ? '<div id="statusSettings"><input type="text" id="customStatus" onkeypress="Status.processCustomAway(event);" style="display:none" onblur="if($(\'customStatus\').style.display != \'none\') { $(\'customStatus\').style.display = \'none\'; $(\'curStatus\').style.display = \'block\'; }" /><a href="#" id="curStatus" onclick="Status.toggleStatusList();return false;">' + Languages.get('available') + '</a></div>' : '');
;
								
			$('buddylist').innerHTML = '<li class="groupTop">'+Languages.get('onlyEnabledForRegisteredUsers')+'</li>';
			
		}else{
			$('blTopToolbar').innerHTML = '<span class="toolbarButton">'+
							'<img id="addbuddy" src="themes/'+theme+'/window/addbuddy.png" class="toolbarButton" onclick="Dialogs.newBuddy();" alt="' + Languages.get('addBuddyButton') + '" title="' + Languages.get('addBuddyButton') + '" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" /></span>' +
							'<span class="toolbarButton toolbarSpacer"><img id="removebuddy" src="themes/'+theme+'/window/removebuddy.png" class="toolbarButton" onclick="Dialogs.removeBuddy();" alt="' + Languages.get('removeBuddyButton') + '" title="' + Languages.get('removeBuddyButton') + '" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" /></span>' +
							'<span class="toolbarButton"><img id="imanyone" src="themes/'+theme+'/window/imanyone.png" class="toolbarButton" onclick="Dialogs.newIM();" alt="' + Languages.get('IMAnyoneButton') + '" title="' + Languages.get('IMAnyoneButton') + '" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" onmousedown="buttonDown(this);" onmouseup="buttonNormal(this);" /></span>' +
							'<span class="toolbarButton"><img id="toggleaudio" src="themes/'+theme+'/window/audio_'+(audioNotify ? 'on' : 'off')+'.png" onclick="toggleAudio();" alt="' + Languages.get('toggleSoundButton') + '" title="' + Languages.get('toggleSoundButton') + '" /></span>'+
							(typeof(Status) != 'undefined' ? '<div id="statusSettings"><input type="text" id="customStatus" onkeypress="Status.processCustomAway(event);" style="display:none" onblur="if($(\'customStatus\').style.display != \'none\') { $(\'customStatus\').style.display = \'none\'; $(\'curStatus\').style.display = \'block\'; }" /><a href="#" id="curStatus" onclick="Status.toggleStatusList();return false;">' + Languages.get('available') + '</a></div>' : '');
							
		}
		
		
		Buddylist.initMenu();
		
		Element.setStyle($('blTopToolbar'), {
			
			zIndex: Windows.maxZIndex + 2000
			
		      });
		
	},

	/**
	* Destroy the buddy list window
	*
	* @author Joshua Gross
	**/
	
	destroy: function() {
		this.buddyListWin.destroy();
	},

	/**
	* Reposition buddylist
	*
	* @author Joshua Gross
	**/
	
	fixBuddyList: function() {
		if(Buddylist.buddyListWin.isVisible()) {
			Buddylist.buddyListWin.setSize(210, (Browser.height() - 60));
			Buddylist.buddyListWin.setLocation((((Browser.height()-40) / 2) - (Buddylist.buddyListWin.getSize()['height'] / 2)), (buddyListLoc == 0 ? 10 : (Browser.width() - Buddylist.buddyListWin.getSize()['width'] - 10)));
			Buddylist.sizeBuddyList();
		}
	},

	/**
	* Resize buddylist
	*
	* @author Joshua Gross
	**/
	
	sizeBuddyList: function() {
		$('blContainer').setStyle({width:  (this.buddyListWin.getSize()['width'] - 8) + 'px',
		height: (this.buddyListWin.getSize()['height'] - 95) + 'px'});
		
		
		$('blBottomToolbar').setStyle({width:  (this.buddyListWin.getSize()['width'] - 8) + 'px',
		top:    (this.buddyListWin.getSize()['height'] - 7) + 'px'});
		
		$('bl_minimize').setStyle({left: (this.buddyListWin.getSize()['width'] - 21) + 'px'});
		
		if(!isNull(myAccordion)){
			
			myAccordion.maxHeight = this.buddyListWin.getSize()['height']-130;
			
			myAccordion.reSizeMenu();
			
		}
		
	},

	/**
	* Add new buddy to the list
	*
	* @arguments
	*   username - user's username
	*   groupname - group the user is in
	*
	* @author Joshua Gross
	**/
	
	addNewBuddy: function(username, groupname) {
		
		if(isRegistered){
			
			username = username.toLowerCase();
			if(!inArray(Buddylist.list, username) && (!Buddylist.listObjects[username] || !$(Buddylist.listObjects[username].obj))) {
				
				if (username != user.toLowerCase()) {
					
					var xhConn = new XHConn();
					
					xhConn.connect(pingTo, "POST", "call=isuser&username="+username, function(xh) {
						
						if(xh.responseText == 'not_exists') {
							var el = $('newbuddy_error_msg');
							if(!isNull(el)){
								$('newbuddy_error_msg').innerHTML = Languages.get('noSuchUser');
							}
							
						} else {
							
							userArr = xh.responseText.split(',');
							
							if(userArr[1]=='none'){
								
								userArr[1]=null;
								
							}
							
							if(!inArray(Buddylist.list, username) && (!Buddylist.listObjects[username] || !$(Buddylist.listObjects[username].obj))) {
								if(!$(groupname.replace(/\s/, '_') + '_group')) {
									Buddylist.addGroup(groupname);
									Buddylist.list[groupname] = [];
								}
								
								Buddylist.addBuddy(username, 'Offline', 'none',userArr[1]);
								
								if(parseInt(userArr[0]) == 0) {
									Buddylist.moveBuddy(username, 'Offline');
									$(Buddylist.listObjects[username].img).src = 'themes/' + theme + '/offline.png';
								} else if(parseInt(userArr[0])  == 2) {
									Buddylist.moveBuddy(username, groupname);
									$(Buddylist.listObjects[username].img).src = 'themes/' + theme + '/away.png';
								} else {
									Buddylist.moveBuddy(username, groupname);
									$(Buddylist.listObjects[username].img).src = 'themes/' + theme + '/online.png';
								}
								
								Buddylist.list[groupname][username] = {'username': username, 'blocked': false, 'status': parseInt(userArr[0])};
								
								var xhConn = new XHConn();
								xhConn.connect(pingTo, "POST", "call=addbuddy&username="+username+'&group='+groupname, null);
								
								Windows.close('newBuddy');
							}
							
						}
						
					});
					
				} else {
					
					$('newbuddy_error_msg').innerHTML = Languages.get('addMyselfError');
					
				}
				
			} else {
				$('newbuddy_error_msg').innerHTML = Languages.get('alreadyOnBuddylist');
			}
			
		}
	},

	/**
	* Add buddy to the list
	*
	* @arguments
	*   username - username of the buddy we're adding
	*   groupname - the group the buddy is in
	*   buddyicon - the buddy's buddyiocn
	*
	* @author Joshua Gross
	* update Benjamin Hutchins
	**/
	
	addBuddy: function(username, groupname, buddyicon,profile_link) {
		
		if(!isNull(groupname)){
			
			if(!$(groupname.replace(/\s/, '_') + '_group')) this.addGroup(groupname);
			
			var groupList = $(groupname.replace(/\s/, '_') + '_group');
			
			var iconsrc = (buddyicon=='none'?defaultIcon:pathToIcons+username+'.'+buddyicon);
			
			var randId = Math.floor(Math.random()*1000000000);
			
			while($(randId + '_blItem'))
			
			randId = Math.floor(Math.random()*1000000000);
			
			//groupList.innerHTML += '<li id="'+randId+'_blItem" class="buddy'+(useIcons && showInList ? " buddyicon" : "")+'" onmousedown="Buddylist.clickBuddy(event, \''+username+'\');return false;" onselectstart="return false;" onmouseover="Buddylist.selectBuddy(this, \''+username+'\', true);" onmouseout="Buddylist.selectBuddy(this, \''+username+'\', false);" ondblclick="Buddylist.onBuddyDblClick();">' + (useIcons&&showInList?(defaultIcon==""&&buddyicon=='none'?'':'<img class="blIcon" src="'+iconsrc+'" alt="" id="'+randId+'_blIcon" />'):'') + '&nbsp;&nbsp;&nbsp;&nbsp;<img src="themes/' + theme + '/online.png" alt="" id="'+randId+'_blImg" />&nbsp;'+username+'</li>';
			
			groupList.innerHTML += '<li id="'+randId+'_blItem" class="buddy'+(useIcons && showInList ? " buddyicon" : "")+'" onmousedown="Buddylist.clickBuddy(event, \''+username+'\');return false;" onselectstart="return false;" onmouseover="Buddylist.selectBuddy(this, \''+username+'\', true);setData(\''+username+'\',\''+profile_link+'\',\'BuddyList\');" onmouseout="Buddylist.selectBuddy(this, \''+username+'\', false);" ondblclick="Buddylist.onBuddyDblClick();">' + (useIcons&&showInList?(defaultIcon==""&&buddyicon=='none'?'':'<img class="blIcon" src="'+iconsrc+'" alt="" id="'+randId+'_blIcon" />'):'') + '&nbsp;&nbsp;&nbsp;&nbsp;<img src="themes/' + theme + '/online.png" alt="" id="'+randId+'_blImg" />&nbsp;'+username+'</li>';
			
			Buddylist.listObjects[username] = {};
			Buddylist.listObjects[username].obj  = randId + '_blItem';
			Buddylist.listObjects[username].img  = randId + '_blImg';
			Buddylist.listObjects[username].icon = buddyicon;
			Buddylist.listObjects[username].group = groupname;
			
			$(Buddylist.listObjects[username].obj).setStyle({listStyleType: 'none'});
			
		}
	},

	/**
	* Move a buddy from one group to another
	*
	* @arguments
	*   username - username of the buddy we're moving
	*   groupname - new group name
	*
	* @author Joshua Gross
	**/
	moveBuddy: function(username, groupname) {
		if(groupname == null) return;
		if($(Buddylist.listObjects[username].obj).parentNode == $(groupname.replace(/\s/, '_') + '_group')) return;
		if(!$(groupname.replace(/\s/, '_') + '_group')) this.addGroup(groupname);
		
		var group = $(groupname.replace(/\s/, '_') + '_group')
		
		group.insertBefore($(Buddylist.listObjects[username].obj), null);
	},

	/**
	* Add a new group the buddylist window
	*
	* @arguments
	*   groupname - group to add
	*
	* @author Joshua Gross
	**/
	addGroup: function(groupname) {
		
		if(Languages.get(groupname)!=''){
			
			groupname_text = Languages.get(groupname);
			
		}else{
			
			groupname_text = groupname;
			
		}
		
		var bList = $('buddylist');
		
		bList.innerHTML = (groupname=='Offline' ? bList.innerHTML : '') + 
		'<li id="' + groupname.replace(/\s/, '_') + '_groupTop" class="groupTop" onmousedown="return false;" onselectstart="return false;" onclick="Buddylist.toggleGroup(\'' + groupname + '\');"><img id="' + groupname.replace(/\s/, '_') + '_groupArrow" src="themes/' + theme + '/window/arrow.png" />&nbsp;&nbsp;' + groupname_text +
		(groupname!='Offline' ? ' <a href="#" class="delLink" onclick="Dialogs.removeGroup(\'' + groupname + '\');return false;"><img src="themes/' + theme + '/window/smallx.png" style="border:0;" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);" /></a>' : '') + '</li>' + "\n" + '<ul id="' + groupname.replace(/\s/, '_') + '_group" class="group"></ul>' + (groupname!='Offline' ? bList.innerHTML : '');
		
	},

	/**
	* Remove buddy from the buddylist permanently
	*
	* @arguments
	*   username - buddy we're removin
	*
	* @author Joshua Gross
	**/
	deleteBuddy: function(username) {
		if(username.indexOf('_group') != -1) {
			this.deleteGroup(username.substring(0, username.length - 6));
			return;
		}
		
		var usernam = username;
		
		var ingroup = null;
		for (var group in this.list) {
			if(typeof(this.list[group][username]) !== 'undefined' && this.list[group][username].username == username) {
				ingroup = group;
				break;
			}
		}
		
		var buddyToRmv = $(Buddylist.listObjects[username].obj);
		
		if(typeof(buddyToRmv) !== 'undefined') {
			buddyToRmv.parentNode.removeChild(buddyToRmv);
			if(this.list[ingroup]) {
				this.list[ingroup][username] = null;
				
				var xhConn = new XHConn();
				xhConn.connect(pingTo, "POST", "call=removebuddy&username="+username, null);
				
			}
			Dialog.closeInfo();
		}
	},

	/**
	* Process the blocking of a buddy
	*
	* @arguments
	*   username - the buddy to be blocked
	*
	* @author Joshua Gross
	* @update Benjamin Hutchins
	**/
	blockBuddy: function(username) {
		var isBlocked = this.blocked.inArray(username);
		if(isBlocked) {
			for(var i=0; i<this.blocked.length; i++) {
				if(this.blocked[i] == username) this.blocked.splice(i, 1);
				break;
			}
		} else {
			this.blocked[this.blocked.length] = username;
		}
		
		var xhConn = new XHConn();
		xhConn.connect(pingTo, "POST", "call=blockbuddy&username="+username+(isBlocked ? '&status=' + (Status.state + 1) : ''), null);
		
		for (var group in this.list) {
			if(typeof(this.list[group][username]) !== 'undefined' && this.list[group][username].username == username) {
				this.list[group][username].blocked = (isBlocked ? false : true);
				$(Buddylist.listObjects[username].img).src = (!isBlocked ? 'themes/' + theme + '/blocked.png' : (Buddylist.list[group][username].status == 1 ? 'themes/' + theme + '/online.png' : (Buddylist.list[group][username].status >= 2 ? 'themes/' + theme + '/away.png' : 'themes/' + theme + '/offline.png')));
				if(!blockedBuddyStatus && isBlocked) {
					Buddylist.moveBuddy(username, Languages.get('offline'));
				}
				break;
			}
		}
	},

	/**
	* Remove a group from the buddylist permanently
	*
	* @arguments
	*   groupname - group to be removes
	*
	* @author Joshua Gross
	**/
	deleteGroup: function(groupname) {
		var groupNoSpaces = groupname.replace(/\s/, '_');
		var groupToRmv = $(groupNoSpaces+"_group");
		var groupTop   = $(groupNoSpaces+"_groupTop");

		if(typeof(groupToRmv) !== 'undefined') {
			groupToRmv.parentNode.removeChild(groupToRmv);
			groupTop.parentNode.removeChild(groupTop);

			for(var i=0;i<this.list[groupname].length;i++) {
				var buddyItem = $(Buddylist.listObjects[this.list[groupname][i].username].obj);
				if(typeof(buddyItem) !== 'undefined') buddyItem.parentNode.removeChild(buddyItem);
			}

			delete this.list[groupname];

			var xhConn = new XHConn();
			xhConn.connect(pingTo, "POST", "call=removegroup&group="+groupname, null);

			Dialog.closeInfo();
		} else {
			$('deletebuddy_error_msg').innerHTML = Languages.get('noSuchGroup');
			$('deletebuddy_error_msg').show();
			Dialog.win.updateHeight();
		}
	},

	/**
	* Toggle whether a group is collapsed or not.
	*
	* @arguments
	*   groupname - group to toggle
	*
	* @author Joshua Gross
	**/
	toggleGroup: function(groupname) {
		var groupList = $(groupname.replace(/\s/, '_') + '_group');
		var groupArrow = $(groupname.replace(/\s/, '_') + '_groupArrow');

		if(groupList.style.display != 'none') {
			groupList.hide();
			groupArrow.src = 'themes/' + theme + '/window/arrow_up.png';
		} else {
			groupList.show();
			groupArrow.src = 'themes/' + theme + '/window/arrow.png';
		}
	},

	/**
	* Proccess mouseover ad mouseout for list items
	*
	* @arguments
	*   sel - list element
	*   username - user being messed with
	*   selected - is the mouse over or out
	**/
	selectBuddy: function(sel, username, selected) {
		if(!isNull(sel)){
			if(selected === false) {
				if(curSelected != username) {
					try {
						Element.addClassName(sel, 'listNotSelected');
						Element.removeClassName(sel, 'listSelected');
						Element.removeClassName(sel, 'listHover');
					} catch(e) { }
				} else {
					Element.addClassName(sel, 'listSelected');
					Element.removeClassName(sel, 'listNotSelected');
					Element.removeClassName(sel, 'listHover');
				}
			} else {
				Element.addClassName(sel, 'listHover');
				Element.removeClassName(sel, 'listSelected');
				Element.removeClassName(sel, 'listNotSelected');
			}
		}
	},

	/**
	* Handle mouse clicks on a buddy in the buddylist
	*
	* @arguments
	*   event - passed by the browser
	*   username - the user that was clicked
	*
	* @author Joshua Gross
	* @update Benjamin Hutchins
	**/
	clickBuddy: function(event, username) {
		event = event || window.event;

		if (event.button == 2) {
			//Context.lastClicked = username;
		} else {

			//Context.lastClicked = null;

			if(curSelected.length > 0) {
				try {
					var el = $(Buddylist.listObjects[curSelected].obj);
					if(!isNull(el)){
						Element.addClassName(el, 'listNotSelected');
						Element.removeClassName(el, 'listSelected');
						Element.removeClassName(el, 'listHover');
					}
				} catch(e) { }
			}
			curSelected = username;
			var oel = $(Buddylist.listObjects[curSelected].obj);
			if(!isNull(oel)){
				Element.addClassName(oel, 'listSelected');
				Element.removeClassName(oel, 'listNotSelected');
				Element.removeClassName(oel, 'listHover');
			}
		}
		return false;
	},

	/**
	* Process double clicks, open the IM window
	*
	* @author Joshua Gross
	**/
	onBuddyDblClick: function() {
		
		if(!isNull(curSelected)){
			
			if(curSelected.length > 0) {
				
				var fetchHistory = true;
				
				if(typeof(IM.windows[curSelected]) == 'undefined') {
					
					IM.create(curSelected, curSelected);
					
					WinTools.posMe(false,IM.windows[curSelected]);
					
				} else {
					//this all should have fetched history
					if(IM.windows[curSelected].detached) {
						if(IM.windows[curSelected].popup.closed) {
							IM.windows[curSelected] = IM.windows[curSelected].old;
							IM.windows[curSelected].show();
							$(IM.windows[curSelected].getId()+'_rcvd').innerHTML = '';
						} else {
							fetchHistory = false;
							IM.windows[curSelected].popup.focus();
						}
					} else if(!IM.windows[curSelected].isVisible()) {
						$( IM.windows[curSelected].getId() + '_rcvd').innerHTML = '';
						IM.windows[curSelected].show();
						IM.windows[curSelected].toFront();
						setTimeout("scrollToBottom('" + IM.windows[curSelected].getId() + "_rcvd')", 125);
						setTimeout("$('" + IM.windows[curSelected].getId() + "_sendBox').focus();", 250);
					} else {
						fetchHistory = false;
						IM.windows[curSelected].toFront();
						setTimeout("$('" + IM.windows[curSelected].getId() + "_sendBox').focus();", 250);
					}
				}
				//get History
				if(fetchHistory == true){
					
					makeHistoryCall(0,curSelected);
					
				}
			}
			
		}
	},
	makeRoomList: function(rooms){
		
		//ripped myself from Chatlistroom 
		
		if(!isNull($('bl_newroom_room_list'))){
			
			$('bl_newroom_room_list').innerHTML = '<ul id="bl_join_room_ul" class="sortable box" style="padding: 0px; margin: 0px; "><li style="display:none;"></li>';
			
			if(!isNull(rooms) && !isNull(predefRooms)){
				
				if(rooms.length > 0 || predefRooms.length > 0) {
					
					for(var i=0; i<rooms.length; i++) {
						
						var hexmd5 = hex_md5(rooms[i]['room'].toLowerCase());
						
						if (!$('bl_chatroom_list_' + hexmd5)) {
						   
							$('bl_newroom_room_list').innerHTML += '<li id="bl_chatroom_list_' + hexmd5 + '" class="buddy" style="padding-left:1%;" onmousedown="ChatroomList.clickRoom(\'' + rooms[i]['room'] + '\');return false;" onmouseover="ChatroomList.selectRoom(this, \'' + rooms[i]['room'] + '\', true);" onmouseout="ChatroomList.selectRoom(this, \'' + rooms[i]['room'] + '\', false);" onDblClick="Chatroom.join(\'' + rooms[i]['room'] + '\');">' + rooms[i]['room'] + '<div id="users">'+rooms[i]['users']+'&nbsp;'+Languages.get('users')+'</div></li>';
						   
						}
					   
					}
					
					for(var i=0; i<predefRooms.length; i++) {
						
						var hexmd5 = hex_md5(predefRooms[i].toLowerCase());
						
						if (!$('bl_chatroom_list_' + hexmd5)) {
						   
							$('bl_newroom_room_list').innerHTML += '<div id="space2"></div><li id="bl_chatroom_list_ ' + hexmd5 + '" class="buddy" style="padding-left:1%;" onmousedown="ChatroomList.clickRoom(\'' + predefRooms[i] + '\');return false;" onmouseover="ChatroomList.selectRoom(this, \'' + predefRooms[i] + '\', true);" onmouseout="ChatroomList.selectRoom(this, \'' + predefRooms[i] + '\', false);" onDblClick="Chatroom.join(\'' + predefRooms[i] + '\');">' + predefRooms[i] + '<div id="users">0&nbsp;'+Languages.get('users')+'</div></li>';
						   
						}
					   
					}
				   
				} else {
				   
					$('bl_newroom_room_list').innerHTML += '<li class="buddy" style="margin: 2px 0px 0px 0px; padding: 0px; text-align: center;">' + Languages.get('noRoomsExist') + '</li>';
				   
				}
				
			}
			
			$('bl_newroom_room_list').innerHTML += '</ul>';
			
		}
		
	},
	
	initMenu: function(){
		
		/*var topAccordion = new accordion('blContainer', {
			classNames : {
				toggle : 'accordion_toggle',
				toggleActive : 'accordion_toggle_active',
				content : 'accordion_content'
			},
			defaultSize : {
				width : 202
			},
			direction : 'horizontal'
		});
		*/
		$('blRoomContainer').innerHTML = '<div class="dialog_info" background-color:#0066CC; style="font-size: 12px;padding:2px;width: 190px;"><p align="justify">' + Languages.get('newRoomPlease') + '</div> \
                                           <span id="newroom_error_msg" class="errorMsg">&nbsp;</span> \
                                           <div id="newroom_box" background-color:#0066CC; style="padding-left:0px;width:100%; font-size: 13px; color: #006699; font-weight: bold;font-family: Verdana, Arial, Helvetica, sans-serif;"> \
										   <div id="bl_newroom_room_list"></div> \
                                           </div> \
                                           <div id="newroom_buttons" >\
                                           <div style="display:block;margin-right:5px;padding-top:4px;" class="lang-roomname langinsert-replace">' + Languages.get('roomname') + ':</div><input type="text" style="width:150px;margin-left:0px;" id="roomname" name="roomname" onkeypress="handleInput(event, function() {Chatroom.join($(\'roomname\').value); }, function(){$(\'roomname\').value = $(\'roomname\').value.toLowerCase();})" /> \
                                           ' +
		ButtonCtl.create(Languages.get('joinRoom'), 'Chatroom.join($(\'roomname\').value);') +
		'</div>';
		
		myAccordion = new Accordion("test-accordion", 2);
		
		this.calcAccordionSizes();
		
	},
	
	calcAccordionSizes: function(){
		/*
		if(!isNull(myAccordion)){
			
			myAccordion.maxHeight = this.buddyListWin.getSize()['height']-150;
			
		}
		*/
		
	}
};
