
function
UserPanel(container, data)
{
  if (data.ses_usr_id < 2) {
    this.div = container.firstChild;
    pbu.$(".lang_en", this.div)[0].href = "/ses/ses_lang_change.php?lang=en-GB&returnUrl="+urlencode(data.returnUrl);
    pbu.$(".lang_se", this.div)[0].href = "/ses/ses_lang_change.php?lang=sv-SE&returnUrl="+urlencode(data.returnUrl);
    container.appendChild(this.div);
    return;
  }

  pbu.$(container).empty();

  this.div = pbu.$("\
<div class='userpanel'><div class='inner'><div class='avatar'><a href=''><img alt='' /></a></div><div class='smalltext'></div>\
<div class='buttons1'><a href='' class='changelanguage lang_en'>Change language</a><a href='' class='changelanguage lang_se'>Change language</a><a href='/logout.php' class='rounded active'><span class='bl'></span><span class='bm'>Logga ut</span><span class='br'></span></a></div>\
<div class='username'><a href=''></a></div><div class='buttons2'>\
<a href='/?page=forum_topic_subscribe_list&amp;pagenr=0' class='forum rounded'><span class='bl'></span><span class='bm'><span class='icon header_forum'></span></span><span class='br'></span></a>\
<a href='/pm_list_inbox_page0.html' class='message rounded'><span class='bl'></span><span class='bm'><span class='icon header_message'></span></span><span class='br'></span></a>\
<a href='' class='guestbook rounded'><span class='bl'></span><span class='bm'><span class='icon header_guestbook'></span></span><span class='br'></span></a>\
</div></div></div>")[0];
  container.appendChild(this.div);
  this.applyUpdate(data);
}

UserPanel.prototype.applyUpdate = function(json) {
  pbu.$(".username a", this.div).text(json.ses_usr_nickname);
  pbu.$(".username a", this.div)[0].href = "/usr"+json.ses_usr_id;
  pbu.$(".avatar a", this.div)[0].href = "/usr"+json.ses_usr_id;
  pbu.$(".avatar img", this.div)[0].src = pbu.avatarUrl(json.ses_sex, json.ses_usr_avatar_pic_id);
  pbu.$("a.guestbook", this.div)[0].href = "/gb/gb_redirect.php?owner="+json.ses_usr_id+"&type=latest";
  pbu.$(".lang_en", this.div)[0].href = "/ses/ses_lang_change.php?lang=en-GB&returnUrl="+urlencode(json.returnUrl);
  pbu.$(".lang_se", this.div)[0].href = "/ses/ses_lang_change.php?lang=sv-SE&returnUrl="+urlencode(json.returnUrl);
  pbu.$(".header_forum", this.div).text("Forum");
  pbu.$(".header_message", this.div).text("Meddelanden");
  pbu.$(".header_guestbook", this.div).text("Gästbok");

  pbu.$("a.forum", this.div)[0].title=json.forum_title;
  pbu.$("a.message", this.div)[0].title=json.pm_title;
  pbu.$("a.guestbook", this.div)[0].title=json.gb_title;

  if (json.forum_topic_subscribe_news) {
    pbu.$(pbu.$(".header_forum", this.div).parent().parent()).addClass("active");
  }
  if (json.ses_pm_new) {
    pbu.$(pbu.$(".header_message", this.div).parent().parent()).addClass("active");
  }
  if (json.ses_gb_new) {
    pbu.$(pbu.$(".header_guestbook", this.div).parent().parent()).addClass("active");
  }
  if (json.ses_usr_vip_until) {
    pbu.$(".smalltext", this.div).html("<span class='premium'>&nbsp;</span> till "+json.ses_usr_vip_until);
  }
  else {
    pbu.$(".smalltext", this.div).text("inloggad som");
  }
}

