
const OVER_NONE = 0;
const OVER_LEFT = 1;
const OVER_MID = 2;
const OVER_RIGHT = 3;

var rot_over_pos = OVER_NONE; //position de la souris au dessus de l'image
var rot_over_lastpos = OVER_NONE;

var rot_num_max = 7 //id de la dernière image, 8 par défaut

pos3D = new Array(8);
pos3D[0] = '0px 0 0 0px';
pos3D[1] = '0px 0 0 -300px';
pos3D[2] = '0px 0 0 -600px';
pos3D[3] = '0px 0 0 -900px';
pos3D[4] = '-300px 0 0 -900px';
pos3D[5] = '-300px 0 0 -600px';
pos3D[6] = '-300px 0 0 -300px';
pos3D[7] = '-300px 0 0 0px';

//ordre des photos :
// 0 1 2 3
// 7 6 5 4
//10px de bordure.

var rot_3D_pos = 0;  //mémorisation de la dernière image;


var dispar = new Array();
var appar = new Array();


//initialisation au besoin (nb d'images, 8 max)

function init_3dmanip(nb) {
  rot_num_max = nb-1;
}

function init_3d500() {
  pos3D = new Array(8);
  pos3D[0] = '0px 0 0 0px';
  pos3D[1] = '0px 0 0 -500px';
  pos3D[2] = '0px 0 0 -1000px';
  pos3D[3] = '0px 0 0 -1500px';
  pos3D[4] = '-500px 0 0 -1500px';
  pos3D[5] = '-500px 0 0 -1000px';
  pos3D[6] = '-500px 0 0 -500px';
  pos3D[7] = '-500px 0 0 0px';
}


//detection mouvements
function overleft() {
 rot_over_lastpos = rot_over_pos;
 rot_over_pos = OVER_LEFT;
 checkmove();
}

function overmid() {
 rot_over_lastpos = rot_over_pos;
 rot_over_pos = OVER_MID;
 checkmove();
}

function overright() {
 rot_over_lastpos = rot_over_pos;
 rot_over_pos = OVER_RIGHT;
 checkmove();
}

function overgone() {
 rot_over_lastpos = rot_over_pos;
 rot_over_pos = OVER_NONE;

}

//décision

function checkmove() {
  if (rot_over_lastpos == OVER_NONE) return;  //pas de mouvement
  var move = rot_over_pos - rot_over_lastpos;
  if(move < 0) brush3D(1);  //souris va vers la gauche, photo vers la droite
  if(move > 0) brush3D(-1); //souris va vers la droite, photo vers la gauche
}

//mouvement
function brush3D(way) {
  rot_3D_pos += way;
  if(rot_3D_pos > rot_num_max) rot_3D_pos = 0;
  if(rot_3D_pos < 0) rot_3D_pos = rot_num_max;
  newpos = pos3D[rot_3D_pos];
  
  document.getElementById('bijou_3d').style.margin = newpos;
}

function apparait(elemid,timeeffect) {
 var cur_opacity = 0;

 //e.stop();
 if(typeof(dispar[elemid])!='undefined') {
   dispar[elemid].cancel();
   cur_opacity = $(elemid).getOpacity();
 }
 appar[elemid] = new Effect.Opacity(elemid,{duration : timeeffect, from: cur_opacity, to: 1});

}

function disparait(elemid,timeeffect) {
 var cur_opacity = 1;

 //e.stop();
 if(typeof(appar[elemid])!='undefined') {
   appar[elemid].cancel();
   cur_opacity = $(elemid).getOpacity();
 }
 dispar[elemid] = new Effect.Opacity(elemid,{duration : timeeffect, from: cur_opacity, to: 0});
}


function viewdetail() {
    disparait('maskdetail',2);
    $('discover_detail').morph('width:700px; height:620px;' , { duration: 2.0 });
    disparait('discover_manipulate',1);
    disparait('discover_navigate_prev',1);
    disparait('discover_navigate_next',1);
    disparait('discover_model',2);
}

function hidedetail() {
    apparait('maskdetail',2);
    $('discover_detail').morph('width:250px; height:250px;',{ duration: 2.0 });
    apparait('discover_model',1);
    apparait('discover_manipulate',3);
    apparait('discover_navigate_prev',1);
    apparait('discover_navigate_next',0.5);

}
