function CreateSentToButton(labels)
{
	var sent_to_panel = $('<div class="filtered-list"></div>');
	var sent_to_input = $('<input type="text" />');
	var sent_to_list = $('<ul></ul>');
	$.each(labels, function(i, label)
	{
		sent_to_list.append($('<li>' + label + '</li>'));
	});

	$('li', sent_to_list).click(function() {alert($(this).text());});

	sent_to_panel.append(sent_to_input, sent_to_list);
	$('input', sent_to_panel).click(function(e){e.stopPropagation();});

	var sent_to_control = new FilteredList(sent_to_input, sent_to_list);

	sent_to_panel.append('<hr />');
	sent_to_panel.append($('<ul></ul>').append(
		$('<li>Спам</li>').click(function(a){alert('Sent to spam');}),
		$('<li>Корзина</li>').click(function(a){alert('Sent to trash');})
	));
	sent_to_panel.append('<hr />');
	sent_to_panel.append($('<ul></ul>').append(
		$('<li>Создать</li>').click(function(a){alert('Create label');}),
		$('<li>Управление ярлыками</li>').click(function(a){alert('Mange labels');})
	));

	var sent_to = PannelButton('Переместить в',
	{
		panel: sent_to_panel,
		panel_container: '#content-col',
		selfclick_close: false,
		onClose: function()
		{
			sent_to_control.reset_filter();
		}
	});

	return sent_to;
}


function CreateAddLabelButton(labels, options)
{
	var settings = $.extend(
		{
			h_align: 'right'
		}, options);

	var label_panel = $('<div class="filtered-list"></div>');
	var label_input = $('<input type="text" />');
	var label_list = $('<ul></ul>');
	$.each(labels, function(i, label)
	{
		label_list.append($('<li><input type="checkbox" value="' + label + '" /> ' + label + '</li>'));
	});

	$('li', label_list).click(function() {alert($('input', this).val());});

	label_panel.append(label_input, label_list);
	$('input', label_panel).click(function(e){e.stopPropagation();});
	var label_control = new FilteredList(label_input, label_list);

	label_panel.append('<hr />');
	var commands = $('<ul></ul>').append(
		$('<li>Создать</li>').click(function(a){alert('Create label');}),
		$('<li>Управление ярлыками</li>').click(function(a){alert('Mange labels');}),
		$('<li class="apply">Применить</li>').click(function(a){alert('Apply lables');}).hide()
	);
	label_panel.append(commands);

	var label = PannelButton('Ярлыки',
	{
		panel: label_panel,
		panel_container: '#content-col',
		h_align: settings.h_align,
		selfclick_close: false,
		onOpen: function()
		{
			$('input', label_list).change(function()
			{
				if ($('input:checked', label_list).length > 0)
				{
					$('li', commands).hide();
					$('li.apply', commands).show();
				}
				else
				{
					$('li', commands).show();
					$('li.apply', commands).hide();
				}
			});
		},
		onClose: function()
		{
			label_control.reset_filter();
		}
	});

	return label;
}

function CreateOtherButton()
{
	var other_panel = $('<div class="filtered-list"></div>');
	var other_list = $('<ul></ul>').append(
		$('<li>Отметить как непрочитанные</li>'),
		$('<li>Добавить в задачи</li>'),
		$('<li>Добавить пометку</li>'),
		$('<li>Снять пометку</li>'),
		$('<li>Добавить календарь</li>'),
		$('<li>Фильтровать похожие письма</li>'),
		$('<li>Игнорировать</li>')
	);
	$('li', other_list).click(function() {alert($(this).text());});

	other_panel.append(other_list);

	var other = PannelButton('Дополнительные действи',
	{
		panel: other_panel,
		panel_container: '#content-col'
	});

	return other;
}

function CreateMailFilters()
{
	var checker = $('<div class="mail-filters">Выбрать: </div>');
	checker.append($('<a href="#">Все</a>').click(function()
	{
		$('#inbox .mail-list tr input').attr('checked', 'checked');
	}), ', ');
	checker.append($('<a href="#">Ни одного</a>').click(function()
	{
		$('#inbox .mail-list tr input').attr('checked', '');
	}), ', ');
	checker.append($('<a href="#">Прочитанные</a>').click(function()
	{
		$('#inbox .mail-list tr:not(.unreaded) input').attr('checked', 'checked');
		$('#inbox .mail-list tr.unreaded input').attr('checked', '');
	}), ', ');
	checker.append($('<a href="#">Не прочитанные</a>').click(function()
	{
		$('#inbox .mail-list tr:not(.unreaded) input').attr('checked', '');
		$('#inbox .mail-list tr.unreaded input').attr('checked', 'checked');
	}), ', ');
	checker.append($('<a href="#">Помеченные</a>').click(function()
	{
		$('#inbox .mail-list .marker i:not(.mark-0)').parents('tr').find('input').attr('checked', 'checked');
		$('#inbox .mail-list .marker i.mark-0').parents('tr').find('input').attr('checked', '');
	}), ', ');
	checker.append($('<a href="#">Без пометок</a>').click(function()
	{
		$('#inbox .mail-list .marker i:not(.mark-0)').parents('tr').find('input').attr('checked', '');
		$('#inbox .mail-list .marker i.mark-0').parents('tr').find('input').attr('checked', 'checked');
	}), ' ');

	return checker;
}
