var user_menu_id = 'main_user_menu';
var um_first_click = false;
var user_menu_obj;
var user_menu_height;
var um_stepping = 10;
var user_menu_startH = um_stepping;
var um_openTimer;

function show_user_menu(user_id, user_name, user_allow, event)
{
	hide_user_menu();

	um_first_click = true;

	var blank = blank_user_menu;
	user_menu_obj = document.getElementById(user_menu_id);

	if ( user_allow )
	{
		blank = blank.replace(/{USER_DLD}/g, '<tr><td class="um_row" onmouseover="this.className=\'um_row_hl\';" onmouseout="this.className=\'um_row\';" onclick="location.href=\'downloaded.php?uid={USER_ID}\';"><a class="um_link" href="downloaded.php?uid={USER_ID}">Скачанные торренты</a></td></tr>');
		blank = blank.replace(/{USER_UPL}/g, '<tr><td class="um_row" onmouseover="this.className=\'um_row_hl\';" onmouseout="this.className=\'um_row\';" onclick="location.href=\'history.php?uid={USER_ID}\';"><a class="um_link" href="history.php?uid={USER_ID}">Закачанные торренты</a></td></tr>');
	}
	else
	{
		blank = blank.replace(/{USER_DLD}/g, '');
		blank = blank.replace(/{USER_UPL}/g, '');
	}

	blank = blank.replace(/{USER_NAME_Q}/g, user_name.replace("'", "&#39;"));
	blank = blank.replace(/{USER_NAME}/g, user_name);
	blank = blank.replace(/{USER_ID}/g, '' + user_id);

	user_menu_obj.innerHTML = blank;

	size = getDivSize(user_menu_id);
	user_menu_height = size['height'];

	if ( document.all )
		w_width = document.body.clientWidth;
	else
		w_width = window.innerWidth;

	if ( (event.clientX + size['width']) > (w_width + document.body.scrollLeft) )
		user_menu_obj.style.left = w_width + document.body.scrollLeft - size['width'];
	else
		user_menu_obj.style.left = event.clientX + document.body.scrollLeft;

	user_menu_obj.style.top = event.clientY + document.body.scrollTop;

	user_menu_obj.style.height = user_menu_startH;

	user_menu_obj.style.display = 'inline';
	open_user_menu();
}

function open_user_menu()
{
	if ( (user_menu_startH - 10) <= user_menu_height )
	{
		user_menu_obj.style.height = user_menu_startH;

		user_menu_startH += um_stepping;
		um_openTimer = setTimeout('open_user_menu()', 0.5);
	}
	else
	{
		clearTimeout(um_openTimer)
	}
}

function hide_user_menu()
{
	if ( !um_first_click )
	{
		try{
			clearTimeout(um_openTimer)
			user_menu_startH = um_stepping;
			document.getElementById(user_menu_id).style.display = 'none';
		}catch(e){}
	}

	um_first_click = false;
}

addEvent(document, 'click', hide_user_menu);
