// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function moveLeft(id,num){

  var leftX = $(id).getStyle("left");
  var cellWidth = $(id + '_1').getWidth() + 10;
  if(leftX){
    leftX = parseInt(leftX.sub(/px/,'')) - cellWidth;
  }else{
    leftX = -cellWidth;
  }
  leftX =  leftX - (leftX % cellWidth);
  if(leftX < (-cellWidth * num)){
    leftX = 0;

  }

  new Effect.Move($(id), { x: leftX, y: 0, mode: 'absolute',duration: 0.2 }); return false;

}

function change(imageId,height,width){
  aspect = width / height
  aspectImage = imageId.width / imageId.height;
  if (aspectImage < aspect)
    {        
      imageId.width = imageId.width * height / imageId.height;
      imageId.height = height
    }

  if  (aspectImage > aspect)
    {
      imageId.height = imageId.height * width / imageId.width ;
      imageId.width = width;
    }
  if  (aspectImage == aspect)
    {
      imageId.height = height
      imageId.width = width  ;      
    }
  a = width / 2;
  b = height / 2;
  c = imageId.width / 2;
  d = imageId.height / 2;
  imageId.style.marginTop = - (d - b) + "px";
  imageId.style.marginLeft = - (c - a) + "px";
}

function change_photo(imageId,height,width){
  aspect = width / height
  aspectImage = imageId.width / imageId.height;
  if (aspectImage < aspect)
    {
      imageId.width = height * aspectImage
      imageId.height = height;
    }
  if  (aspectImage > aspect)
    {        
      imageId.height = width / aspectImage
      imageId.width = width;
    }
  if  (aspectImage == aspect)
    {
      imageId.height = height
      imageId.width = width  ;      
    }
  a = width / 2;
  b = height / 2;
  c = imageId.width / 2;
  d = imageId.height / 2;
  imageId.style.marginTop = - (d - b) + "px";
  imageId.style.marginLeft = - (c - a) + "px";
}
