
function seed () {
	return Math.floor(Math.random()*100000000);
}

function popup_image_ratio (image_id, c) {
	new Ajax.Request('/admin/ajax.php', {
		method:'get',
		parameters: {action: 'popup_image_ratio', file: image_id},
		onSuccess: function(response) {
			d = response.responseText.split(',');
			c.style.top = (d[0]) + "px";
		}
	});
}

var loading = '<img src="/images/action/loading.gif" alt="Loading..." />';
function popup_image_onclick (sender, image_id) {
	var y = (screen.width)/2;
	var x = (screen.height)/2;
	var c = $('popupImage');
	c.innerHTML = loading;
	c.style.display = "block";
	new Ajax.Request('/admin/ajax.php', {
		method:'get',
		parameters: {action: 'popup_image_ratio', file: image_id, sWidth: y, sHeight: x, seed: seed()},
		onSuccess: function(response) {
			d = response.responseText.split(',');
			c.style.top = d[3] - (d[2]-20) + "px";
			c.style.left = d[1] - (d[0]/2) + "px";
		}
	});
	
	new Ajax.Request('/admin/ajax.php', {
		method:'get',
		parameters: {action: 'start_popup_image', file: image_id, seed: seed()},
		onSuccess: function(response) {
			$("popupImage").innerHTML = response.responseText;
			$("popupImage").style.display = "block";
		}
	});
}

function btn_close_onclick (sender) {
	$('popupImage').style.display = "none";
}
