Ext.ux.UserMenu= function (config) {
	this.profileItem = new Ext.menu.Item({text: locStrings["user_profile"], handler: this.onProfileClick, scope: this});
	this.banItem = new Ext.menu.Item({text: locStrings["user_ban"], handler: this.onBanClick, scope: this});
	this.moderatorItem = new Ext.menu.Item({text: locStrings["user_add_moderator"], handler: this.onModeratorClick, scope: this});
	
	this.moderatorItem.setMode = function  (mode) {
		if (mode == "add")
			this.setText (locStrings["user_add_moderator"]);
		else
			this.setText (locStrings["user_del_moderator"]);			
		this.mode = mode;
	}
	
	config = {
		plain: true, 
		width: 220,
		cls: 'x-user-menu',
		shadow: false,
		items: [
			{text: locStrings["user_to"], handler: this.onSendToClick, scope: this},
			this.profileItem,
			this.banItem,
			this.moderatorItem
		]	
	};
	this.user = null;
	
	Ext.ux.UserMenu.superclass.constructor.call(this, config);
}

Ext.extend(Ext.ux.UserMenu, Ext.menu.Menu, {
	render: function () {
		Ext.ux.UserMenu.superclass.render.call(this);
		
		var obj = document.createElement("div");
		Ext.get(obj).setStyle('clear', 'both');  
		Ext.get(obj).setStyle('float', 'left');  
		Ext.get(obj).setStyle('height', '80px');  
		Ext.get(obj).setStyle('border-bottom', '1px solid #999');  
		//this.el.innerHTML = "<div style='border:1px solid red; float:left'>ASDASD</div>" + this.el.innerHTML;
		
		this.userInfoDiv = obj;
		
		//alert(this.el.childNodes.length);
		this.el.dom.insertBefore(obj,this.el.dom.childNodes[0]);
	},
		
	selectUser: function (user) {
		if (!user) {
			this.userInfoDiv.innerHTML = "Cannot find user info";
			return;
		}
		
		var channel = ChatApp.getCurrentChannel ();
		var userStatus = channel.getUserStatus (user);
		
		var usertitle = user.nick;
		var userinfos = new Array ();
		if (user.age && user.age >0 )
			userinfos.push(locStrings["user_age"] + ": "  + user.age );
		if (user.city)
			userinfos.push(locStrings["user_city"] + ": " + user.city );
		userinfos.push ("<img class='user-symbol' src='/pages/channel/img/" + userStatus.name + ".gif'>" + userStatus.title);
			
		var userinfo = userinfos.join("<BR>");
		this.userInfoDiv.className = "user-card " + user.gender;
		
		var picHTML = (user.id == CurrentUser.Id) ? ChatApp.myPicSuffix : "";
		this.userInfoDiv.innerHTML = "<div class='user-pic-wrap' style='float: left; display: block; '><img class='user-pic' src='/data/userpic.php?uid=" + user.id + "&size=60&gender=" + user.gender + picHTML + "'></div><div style='float: left; height: 80px; overflow: hidden; width: 157px'><div style='padding: 4px'><div class='usertitle'><a style='font-weight: bold' href='javascript:void(0)' onClick='ChatLayout.getUserMenu().onSendToClick()'>" + usertitle + "</a></div>" + userinfo + "</div></div>";
		this.user = user;
		
		if (this.user.isTemp)
			this.profileItem.hide ();
		else
			this.profileItem.show ();
		
		var canBan = false;
		if (channel.moderators[CurrentUser.Id] != null && channel.moderators[user.id] == null && channel.supermoders[user.id] == null)
			canBan = true;
		if (channel.supermoders && channel.supermoders[CurrentUser.Id] != null && channel.supermoders[user.id] == null)
			canBan = true;
		if (channel.supermoders && channel.supermoders[user.id] != null)
			canBan = false;
		if (canBan)
			this.banItem.show ();
		else
			this.banItem.hide ();
		
		var isAuthor = false;
		if(channel.authorId == CurrentUser.Id )
			isAuthor = true;
		
		if (isAuthor && user.id != CurrentUser.Id && !user.isTemp) {
			this.moderatorItem.show();
			if (channel.moderators[user.id])
				this.moderatorItem.setMode("del");
			else
				this.moderatorItem.setMode("add");
		} else {
			this.moderatorItem.hide ();
		}
	},
	
	onSendToClick: function () {
		ChatLayout.addMessageTarget(this.user);
		this.hide ();
	},
		
	onProfileClick: function () {
		ChatApp.getCurrentChannel().view.showUserInfo(this.user.id);
	},
		
	onBanClick: function () {
		ChatApp.getCurrentChannel().banUser(this.user.id);				
	},
		
	onModeratorClick: function() {	
		ChatApp.getCurrentChannel().setUserModerator(this.user.id, this.moderatorItem.mode);
	}
	
});

