function win2unicode(str) {
   var charmap   = unescape(
      "%u0402%u0403%u201A%u0453%u201E%u2026%u2020%u2021%u20AC%u2030%u0409%u2039%u040A%u040C%u040B%u040F"+
      "%u0452%u2018%u2019%u201C%u201D%u2022%u2013%u2014%u0000%u2122%u0459%u203A%u045A%u045C%u045B%u045F"+
      "%u00A0%u040E%u045E%u0408%u00A4%u0490%u00A6%u00A7%u0401%u00A9%u0404%u00AB%u00AC%u00AD%u00AE%u0407"+
      "%u00B0%u00B1%u0406%u0456%u0491%u00B5%u00B6%u00B7%u0451%u2116%u0454%u00BB%u0458%u0405%u0455%u0457")
   var code2char = function(code) {
               if(code >= 0xC0 && code <= 0xFF) return String.fromCharCode(code - 0xC0 + 0x0410)
               if(code >= 0x80 && code <= 0xBF) return charmap.charAt(code - 0x80)
               return String.fromCharCode(code)
            }
   var res = ""
   for(var i = 0; i < str.length; i++) res = res + code2char(str.charCodeAt(i))
   return res
}
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = win2unicode(unescape(jQuery.trim(cookies[i])));
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
if ($.cookie('mail') && $.cookie('mail')!=null && $.cookie('username') && $.cookie('username')!=null && $.cookie('username')!=null) {
	var messages1 = ($.cookie('messages_on_move_inbox_not_red') == null?'0':$.cookie('messages_on_move_inbox_not_red'));
	var messages2 = ($.cookie('messages_on_move_inbox') == null?'0':$.cookie('messages_on_move_inbox'));

	document.write('<div class="cab cab3" onclick="showUserMenu(event);"><div class="cont"><div class="regeduser"><a href="#" onclick="return false;"><span>'+$.cookie('username')+'</span> <span class="mes"><b class=\"user_nm_n\">'+messages1+'</b> / '+messages2+'</span></a></div></div><div class="deco">&nbsp;</div>'+
			'<div id="usermenu" class="popup">'+
				'<ul>'+
				'<li><a href="http://move.su/user/">Профиль</a></li>'+
				'<li><a href="http://move.su/user/blog/">Мой блог</a></li>'+
				'<li><a href="http://move.su/user/items/">Объявления</a></li>'+
				'<li><a href="http://move.su/help/">Помощь по порталу</a></li>'+
				'<li class="inbox"><a href="http://move.su/user/messages/" class="mrk-msg-inbox">Сообщения</a></li>'+
				'			<li class="logout">'+
				'				<a class="mrk-logout" href="http://move.su/logout.php">Выйти</a>'+
				'			</li>'+
				'		</ul>'+
				'<div class="bot">&nbsp;</div>'+
			'</div>'+
			'</div>	');
	
	
	$(function() {
		$.ajax({
			url: '/ajax/num_of_messages.php',
			success: function(data) {
				$('.mes').html(data);
			}
		});
	});
}
else
	document.write('<div class="cab"><div class="cont"><div class="join"><a href="#" onclick="toggle_form(event, this,\'auth_form\');return false">Войти</a></div><div class="reg"><a href="http://move.su/register/">Регистрация</a></div></div><div class="deco">&nbsp;</div></div>');
