var is_cropping = 0;
var crop_data = false;

function getCoords(c)
{
	crop_data = c;
}

function initCrop()
{
	if(is_cropping == 0)
	{
		initPhoto();
		$('#toAnnotate').Jcrop({onSelect: getCoords});

		$(".photo_info").hide();
		$(".photo_links").hide();

		$("#info_btn").removeClass('active_popup');
		$("#links_btn").removeClass('active_popup');
		$("#notice_btn").removeClass('active_popup');
		$("#crop_btn").addClass('active_popup');

		is_cropping = 1;
		is_annotate = 0;
		links_opened = 0;
		info_opened = 0;
	}
	else
	{
		links_opened = 0;
		info_opened = 0;
		is_cropping = 0;
		$("#crop_btn").removeClass('active_popup');
		initAnnotate();
	}

}

function addCrop()
{
	$('html, body').animate({scrollTop: $("#copyright").offset().top}, 'slow');
	$("#comment_form_head").append('<div class="crop_added_icon" onclick="initAnnotate(); $(this).remove();"></div>');
}

function closeCropShow()
{
	initPhoto();

	$("#crop_show_top").remove();
	$("#crop_show_left").remove();
	$("#crop_show_right").remove();
	$("#crop_show_bottom").remove();
	$("#crop_show").remove();
}

function showCrop(x, y, width, height)
{
	closeCropShow();

	$('html, body').animate({scrollTop: $(".photo-bread-crump").offset().top}, 'slow');

	var top_offset = $("#toAnnotate").offset().top;
	var left_offset = $("#toAnnotate").offset().left;
	var page_height = $("body").height();
	var page_width = $("body").width();

	//crop show top
 	$("body").append('<div id="crop_show_top"></div>');
 	$("#crop_show_top").css('position', 'absolute');
 	$("#crop_show_top").css('opacity', '0.8');
 	$("#crop_show_top").css('background-color', 'Black');
 	$("#crop_show_top").css('z-index', 5000);
 	$("#crop_show_top").css('top', top_offset);
 	$("#crop_show_top").css('left', left_offset);
 	$("#crop_show_top").css('width', photo_width);
 	$("#crop_show_top").css('height', y);

 	//crop show left
 	$("body").append('<div id="crop_show_left"></div>');
 	$("#crop_show_left").css('position', 'absolute');
 	$("#crop_show_left").css('opacity', '0.8');
 	$("#crop_show_left").css('background-color', 'Black');
 	$("#crop_show_left").css('z-index', 5000);
 	$("#crop_show_left").css('top', top_offset + y);
 	$("#crop_show_left").css('left', left_offset);
 	$("#crop_show_left").css('width', x);
 	$("#crop_show_left").css('height', height + 1);

	//crop show
	$("body").append('<div id="crop_show"></div>');
 	$("#crop_show").css('position', 'absolute');
 	$("#crop_show").css('z-index', 5001);
 	$("#crop_show").css('top', top_offset + y);
 	$("#crop_show").css('left', left_offset + x);
 	$("#crop_show").css('width', width);
 	$("#crop_show").css('height', height);

	$("#crop_show").append('<div id="crop_show_close" onclick="closeCropShow(); initAnnotate();"></div>');
	$("#crop_show").css('border', '1px solid gray');

 	//crop show right
 	$("body").append('<div id="crop_show_right"></div>');
 	$("#crop_show_right").css('position', 'absolute');
 	$("#crop_show_right").css('opacity', '0.8');
 	$("#crop_show_right").css('background-color', 'Black');
 	$("#crop_show_right").css('z-index', 5000);
 	$("#crop_show_right").css('top', top_offset + y);
 	$("#crop_show_right").css('left', left_offset + x + width + 1);
 	$("#crop_show_right").css('width', photo_width - x - width);
 	$("#crop_show_right").css('height', height + 1);

 	//crop show bottom
 	$("body").append('<div id="crop_show_bottom"></div>');
 	$("#crop_show_bottom").css('position', 'absolute');
 	$("#crop_show_bottom").css('opacity', '0.8');
 	$("#crop_show_bottom").css('background-color', 'Black');
 	$("#crop_show_bottom").css('z-index', 5000);
 	$("#crop_show_bottom").css('top', top_offset + y + height + 1);
 	$("#crop_show_bottom").css('left', left_offset);
 	$("#crop_show_bottom").css('width', photo_width);
 	$("#crop_show_bottom").css('height', photo_height - y - height);
}
