window.addEvent('domready', function() {
	SqueezeBox.assign($$('a.equation_link'), {
		ajaxOptions: { method: 'get' },
		size: { x:400, y:250 }
	});
});

var jsonReq;
function preview() {
	$('preview_box').set('html', '<div style="text-align:center"><center><img src="images/loading.gif" alt="loading" /></center></div><br />');
	setVisible('preview_container', 1);
	if (! jsonReq) {
		jsonReq = new Request.JSON({
			url:'http://mathbin.net/preview.cgi',
			onComplete: function(results) {
				setVisible('preview_container', 0);
				if (results) {
					var theHtml = '';
					if (results.error) {
						theHtml = '<strong>ERROR</strong>: ' + results.error + '<br />';
					}
					if (results.body) {
						theHtml += results.body;
					}
					$('preview_box').set('html', theHtml);
				} else {
					$('preview_box').set('html', "<strong>ERROR</strong>: no value returned.");
				}
				SqueezeBox.fromElement($('preview_box'), {handler:'clone'});
			}
		});
	}
	jsonReq.cancel();
	jsonReq.get({'body':$('canvas').get('value')});
}

function tex_popup(link)
{
	return true;
}

function showPost(post_id)
{
	bodyDiv = post_id + "_body";
	linkDiv = post_id + "_link";
	setVisible(bodyDiv, 1);
	setVisible(linkDiv, 0);
}
function hideForm(post_id)
{
	bodyDiv = post_id + "_body";
	linkDiv = post_id + "_link";
	setVisible(bodyDiv, 0);
	setVisible(linkDiv, 1);
}
function setVisible(divID, state)
{
	if (state) {
		$(divID).setStyles({ 'visibility':'visible', 'display':"block" });
	} else {
		$(divID).setStyles({ 'visibility':'hidden', 'display':"none" });
	}
}

