;(function(){
  var urlNamba = 'http://talk.namba.kg/mini.php',buttonPosition = 'right', error = false, imgExt = 'png';

  if(typeof(NambaTalkDefine)=='object'){
    if(NambaTalkDefine.roomJID && NambaTalkDefine.roomJID.indexOf('namba.')>0){
      if(NambaTalkDefine.buttonPosition && NambaTalkDefine.buttonPosition.match(/(left|right)/i))buttonPosition = NambaTalkDefine.buttonPosition.toLowerCase();
      var head = document.getElementsByTagName('head')[0];
      var right_expression = '-nambaTalk.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) +';
      var css = '#nambaTalk {z-index:9999;cursor:pointer;position: fixed;'+buttonPosition+': 0px; top: 35%;_position: absolute;_right: auto; _top: auto;_left: expression( ( '+(buttonPosition=='right'? right_expression:'')+' ( ignoreParams2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + "px" );_top: expression( ( (-nambaTalk.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight )/2) + (nambaTalk.offsetHeight/2 + ( ignoreParams = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) )) + "px" );_height:auto;}';

      if (/WebKit|MSIE/i.test(navigator.userAgent)) {
        var style = document.createElement('style');
        style.type = 'text/css';
        if (style.styleSheet) {
          style.styleSheet.cssText = css;
        } else {
          style.innerText = css;
        }
        head.appendChild(style);
        imgExt = 'gif';
      } else {
        head.innerHTML += '<style type="text/css">' + css + '</style>';
      }
      document.writeln('<div id="nambaTalk"><img src="http://talk.namba.kg/ima/mini/'+buttonPosition+'.'+imgExt+'" alt="NambaTalk Open" /></div>');
      setTimeout(function(){
        var nambaTalk = document.getElementById('nambaTalk');
        nambaTalk.onclick = function(){
          var popW = 700, popH = 500,sw=screen.width,sh=screen.height;
          var leftW = parseInt(sw - popW)||0;
          var topW = parseInt(sh - popH)||0;
          window.open(urlNamba+"?jid="+NambaTalkDefine.roomJID,"chatRoom","menubar=no,scrollbars=yes,resizable=yes,width="+popW+",height="+popH+",toolbar=no,left="+(leftW>0? leftW/2:0)+",top="+(topW>0? topW/2:0));
        };
      }, 10);
    }else error = true;
  }else error = true;
  if(error == true){alert('Ошибка инициализации "NambaTalk"');}
})();