$(function() {
	$('body').prepend('<div id="convert_panel" style="width: 100%; height: 100%; display:none;"><iframe id="convert_panel_content" src="" style="width: 100%; height: 100%; border: none;"></iframe></div>');

	add_convert_button();
});

function add_convert_button() {
	// already have the button
	if ($('#ubb_cmd_converthand').size() > 0)
		return;
	
		target_space = $('table.markup_panel tr:last');
	if (target_space.size() == 1) {
		target_space.before('<tr><td><div class="convert_hand" id="ubb_cmd_converthand" style="white-space: nowrap; cursor: default; text-align: center;"><span style="color: #00f; text-decoration: underline; cursor: pointer; font-weight: bold; font-size: 12px;">Paste Hand History</div></td></tr>');
	}
	else
	{
		target_space = $('form[name="replier"] table.t_inner tr td.alt-4 div.alt-2b');
		if (target_space.size() == 1) {
			target_space.before('<div style="width: 100%; text-align: center; background-color: #fff;"><div class="convert_hand" id="ubb_cmd_converthand" style="white-space: nowrap; cursor: default; text-align: center;"><span style="color: #00f; text-decoration: underline; cursor: pointer; font-weight: bold; font-size: 12px;">Paste Hand History</div></vid>');
		}
	}
	
	$('#ubb_cmd_converthand').click(convert_hand_click);
}

function convert_hand_click(e) {
	e.preventDefault();
	
	$('#convert_panel_content').attr('src', "http://pokertools.cardrunners.com/forum/cardrunners/");
	$('#convert_panel').modal({
		onOpen: function (dialog) {
			dialog.overlay.fadeIn('fast', function () {
				dialog.container.fadeIn('fast', function () {
					dialog.data.hide().fadeIn('fast');
				});
			});
		},
		onClose: function (dialog) {
			dialog.data.fadeOut('fast', function() {
				dialog.container.fadeOut('fast', function () {
					dialog.overlay.fadeOut('fast', function() {
						$.modal.close();
					});
				});
			});
		}
	});
}

