// JavaScript Document

function photoUpdate(page_module_id)
{
	loadModuleAdmin('default', 'photoAdmin', 'page_module_id='+page_module_id+'&imageFile='+$('#imageFile').val());
}

function tmp(post)
{
	// Loads the iframe's parent with the result.
	$('#photoUploadForm').parent().html(ajaxCall('admin-upload','photoAdmin',post));
}

function photoAdminInit(posts)
{
	var width = $(document).width();
	$('#mainMask').css('width', width);

	var height = $(document).height();
	$('#mainMask').css('height', height);
	
	$('#mainMask').click(function() {
		window.location.reload();
	});

	loadModuleAdmin('default', 'photoAdmin', posts);

	$('#mainMask').fadeTo(500, 0.6);
	$('#mainMask').fadeIn(500, function()
	{
		$('#mainContentEditor').css('width', '80%');
		$('#mainContentEditor').css('height', '80%');

		$('#mainContentEditor').css('top', ( $(window).height() - $('#mainContentEditor').height() ) / 2 + $(window).scrollTop() + 'px');
		$('#mainContentEditor').css('left', ( $(window).width() - $('#mainContentEditor').width() ) / 2 + $(window).scrollLeft() + 'px');
	});

	$('#mainContentEditor').show();
}

function setVals(posts) {
	var x1 = $('#x1').val();
	var y1 = $('#y1').val();
	var x2 = $('#x2').val();
	var y2 = $('#y2').val();
	var w = $('#w').val();
	var h = $('#h').val();
	
	if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h=="") {
		alert("You must make a selection first");
		return false;
	} else {
		$('.imgareaselect-outer').remove();
		$('.imgareaselect-selection').remove();
		$('.imgareaselect-border1').remove();
		$('.imgareaselect-border2').remove();
		$('#photoContainer').parent().html(ajaxCall('admin-preview', 'photoAdmin', posts+'&x1='+x1+'&y1='+y1+'&x2='+x2+'&y2='+y2+'&w='+w+'&h='+h));
		return true;
	}
}

function clearSelection()
{
	$('#jqSelectArea').remove();
	$('#jqSelectBorder1').remove();
	$('#jqSelectBorder2').remove();
	$('#jqSelectTop').remove();
	$('#jqSelectRight').remove();
	$('#jqSelectBottom').remove();
	$('#jqSelectLeft').remove();
}
