//<![CDATA[	
var x1 = 0;
var y1 = 0;
var x2 = 100;
var y2 = 100;
var width = 100;
var height = 100;
var cropperimg = undefined;

function onEndCrop( coords, dimensions ) {
    var imgCrop = $('testImage');
    if (imgCrop.getHeight() < 100 || imgCrop.getWidth() < 100) {
        x1 = 0;
        y1 = 0;
        x2 = imgCrop.getWidth();
        y2 = imgCrop.getHeight();
        width = imgCrop.getWidth();
        height = imgCrop.getHeight();
    }else{
        x1 = coords.x1;
        y1 = coords.y1;
        x2 = coords.x2;
        y2 = coords.y2;
        width = dimensions.width;
        height = dimensions.height;
    }
}
		
// example with a preview of crop results, must have minimumm dimensions
isInitCropper = undefined;
function initCropper(width,height) {
    var imgCrop = $('testImage');
    if (imgCrop.getHeight() < 100 || imgCrop.getWidth() < 100) {
        x1 = 0;
        y1 = 0;
        x2 = imgCrop.getWidth();
        y2 = imgCrop.getHeight();
        width = imgCrop.getWidth();
        height = imgCrop.getHeight();
        $("previewArea").style.display = 'none';
    } else {
        $("previewArea").style.display =  'inline';
        
        cropperimg = new Cropper.ImgWithPreview(
            'testImage',
            {
                minWidth: 130,
                minHeight: 130,
                ratioDim: {
                    x: 130,
                    y: 130
                },
                displayOnInit: true,
                onEndCrop: onEndCrop,
                previewWrap: 'previewArea'
            }
            );
        isInitCropper = true;
    }
};
		
		
/*
		if( typeof(dump) != 'function' ) {
			Debug.init(true, '/');
			
			function dump( msg ) {
				// Debug.raise( msg );
			};
		} else dump( '---------------------------------------\n' );
		*/

function saveAvatar(){

    var opt = {
        method: 'post',
        postBody: 'photoid='+photoidtmp + '&x1='+ x1 + '&y1='+ y1 + '&x2='+ x2 + '&y2='+ y2 + '&width='+ width + '&height='+ height,
        onSuccess: function(t) {
            if(t.responseText=="OK"){
                window.location.reload();
            }else{
                alert("Can't set to avatar");
            }
        },
        onFailure: function(t) {
            alert("Error Can't set to avatar");
        }
    }
    new Ajax.Request('/photo/save_avatar_from_photo', opt);
}
//]]>