/*##### CROPPING - gf ######*/
/** Permet de recup la taille de l'image**/
var getSizeImg = function(src) {
var timg = $('<img>').attr('src', src).css({ position: 'absolute', top: '-1000px', left: '-1000px' }).appendTo('body');
var size = [ timg.get(0).offsetWidth, timg.get(0).offsetHeight ];
try { document.body.removeChild(timg[0]); }
  catch(e) {};
  return size;
};

/** Fonction de redimensionnement et de déplacement **/
$().ready(function(){
$('#resizeme_containment_div').resizable({

  containment: $('#resizeme_containment_div_wrapper'),
  //proxy: 'proxy',
  //ghost: true,
  //animate:true,
  handles: 'all',
  knobHandles: true,
  //transparent: true,
  aspectRatio: true,
  autohide: true,
  minWidth: 135,
  minHeight: 135,
  //maxHeight: 135,
  //maxWidth: 135,
  
  resize: function(e, ui) {

    this.style.backgroundPosition = '-' + (ui.instance.position.left) + 'px -' + (ui.instance.position.top) + 'px';
  
    $("#log-top").html(ui.instance.position.top+"px");
    $("#log-left").html(ui.instance.position.left+"px");
    $("#log-height").html(ui.instance.size.height+"px");
    $("#log-width").html(ui.instance.size.width+"px");
  },
  
  stop: function(e, ui) {
    this.style.backgroundPosition = '-' + (ui.instance.position.left) + 'px -' + (ui.instance.position.top) + 'px';
  }
})

  .draggable({
    cursor: 'move',
    containment: $('#resizeme_containment_div_wrapper'),
    drag: function(e, ui) {
      this.style.backgroundPosition = '-' + (ui.position.left) + 'px -' + (ui.position.top) + 'px';
    
      $("#log-top").html(ui.instance.position.top+"px");
      $("#log-left").html(ui.instance.position.left+"px");
    }
  });

  $('#resizeme_containment_wrap_image').css({ opacity: 0.5 });
  $("#log-height").html($('#resizeme_containment_div').height()+"px");
  $("#log-width").html($('#resizeme_containment_div').width()+"px");
});

function cropMyImage(image)
{
	var width = $("#log-width").html().replace("px", "");
	var height = $("#log-height").html().replace("px", "");
	var left = $("#log-left").html().replace("px", "");
	var top = $("#log-top").html().replace("px", "");
	$('#apercuMedaillon').html('<img width="35" height="35" src="/images/common/loading.gif" border="0"/>');
	setTimeout('$(\'#apercuMedaillon\').html(\'<img src="/imagesCrop.php?task=cropping&picture='+image+'&l='+left+'&t='+top+'&w='+width+'&h='+height+'" border="0" />\')', 500);
	$('#actionSave').html('<input class="croppingButton" type="submit" value="Sauver"/>');
}

