/**
// Copyright (C) 2008 - 2010 Mike Feng Jinglong
//
// This program is a commercial software; you cannot redistribute it
// and/or modify it without the explicit consent from the tagged.
//
// All title and copyright in and to the Product is owned by Mike Feng
// and is protected by international copyright laws and treaty provisions.
// Mike Feng retains all ownership rights in the Product.
// The copyright notice must be reproduced and included on any copy
// that is expressly permitted under this Agreement.
**/
var photoCrop = null;
function startCrop(id) {
	new Fx.Scroll(window).toElement($('photo-scroll-top'));
	if (cropping) return;
	if (tagging) doneTagging();
	cropping = true;
	$$('div[name=frame]').setStyle('z-index', '-1');
	$$('a[id=photo-container-anchor]').set('hrefb', $$('a[id=photo-container-anchor]').get('href'));
	$$('a[id=photo-container-anchor]').removeProperty('href');
	
	$('crop-info').show();
	$('crop-info').getElement('span').set('html', $('crop-info').getElement('input[type=hidden]').get('value'));
	photoCrop = new uvumiCropper('currentphoto', {
		mini: {
			x: 200,
			y: 200
		},
		handles:[	// drag handles to be added on the resizer's borders. Will create a handle for each array element. Can be a string ('top', 'left', 'bottom', 'rigth'), in which case the handle will be added in the middle of the corresponding segment, or a couple, in which case the handle will be added in the corresponding corner. You can create any combination from one to eight handles. If the array is empty or 'handles' = false, will be considered as not resizable.
			['top','left'],
			['top','right'],
			['bottom','left'],
			['bottom','right']
		],
		parameters: {
			'id': id
		},
		handleSize:10,
		serverScriptSave: sgurlraw+'&func=savecrop',
		onCropSuccess: function(json) {
			if ($('headerAvatarThumb'))
				$('headerAvatarThumb').src = json.headeravatar;
			if ($('commentAvatarThumb'))
				$('commentAvatarThumb').src = json.commentavatar;
			if (json.currentphoto && $('currentphoto'))
				$('currentphoto').set('src', json.currentphoto);
			if ($('comment-table')) {
				$('comment-table').getElements('.mycomment-thumb').each(function(el) {
					 el.src = json.commentavatar;
				});
			}
			if (json.hidecrop) $('crop-this-photo').destroy();
			cancelCropping();
			Sexy.info(json.message);
		}
	});
	$('crop-info').getElement('input[type=submit]').removeEvents('click');
	$('crop-info').getElement('input[type=submit]').addEvent('click', function() { doneCropping(); });
	$('crop-info').getElement('input[type=button]').removeEvents('click');
	$('crop-info').getElement('input[type=button]').addEvent('click', function() { cancelCropping(); });
}

function doneCropping() {
	photoCrop.cropSave();
}

function cancelCropping() {
	cropping = false;
	$('crop-info').hide();
	photoCrop.destroy();
	document.getElements('div[name=frame]').setStyle('z-index', '2');
	$$('a[id=photo-container-anchor]').set('href', $$('a[id=photo-container-anchor]').get('hrefb'));
	$$('a[id=photo-container-anchor]').removeProperty('hrefb');
}

