(function(){
  
VisionneuseDestockage = function(items, midArea, thumbArea, reactivArea){ 
    this.items = items;
    this.currentItem = items[0];
    this.currentIndex = 0;
    this.midArea = $(midArea);
    this.thumbArea = $(thumbArea);
    this.nextIndex = 1;
    this.canMove = true;
    this.cursor = new VisionneuseCursor();
    this.reactivArea = $(reactivArea);
    
    this.initCanZoomIcon();
    this.initListeners();
  };
  
  
VisionneuseDestockage.prototype = {
  
  
  initCanZoomIcon : function(){
    if(this.currentItem.imgBig != ""){
      $("#can_zoom_icon").removeClass("noDisplay");
    }else{
      $("#can_zoom_icon").addClass("noDisplay");
    }
  },
  
    
  hideCanZoomIcon : function(){
      $("#can_zoom_icon").addClass("noDisplay");
  },
  
  
  
  initListeners : function(){
     var obj = this;
     
     this.thumbArea.each(function(index, elt){
       $(this).click(function(evt){
         if(obj.canMove){
         obj.canMove = false; 
           obj.nextIndex = index +1;
           obj.changeDiapoForElt.call(obj, $(this), obj);
         }
       });
     });
     
     /*
     obj.reactivArea.mouseenter(function(evt){
       var offset = {
         top:evt.layerY,
         left:evt.layerX
       }
       obj.cursor.Show(offset);
     });
     
     obj.reactivArea.mouseleave(function(evt){
       obj.cursor.hide();
     });
     
     obj.reactivArea.mousemove(function(evt){
        var offset = {
         top:evt.layerY,
         left:evt.layerX
       }
       obj.cursor.move(offset);
     });
     */
    
     this.reactivArea.click(function(evt){
       evt.preventDefault();
       
       if(obj.currentItem.imgBig == ""){
         return 0;
       }
       
       var cont = $('<div id="content_img">');
       var image_big = $('<img alt="" id="destockage_zoom" />');
       cont.append(image_big);
       
       MyLightBox.create({
         content:cont,
         parentElt:"image_lb",
         onOpenAction:{
           func_name:function(){obj.displayImage.call(obj)},
           args:obj
         },
         onClose:{
           func_name:function(){ obj.closeLb.call(obj)},
           args:obj
         }
       });
       
       MyLightBox.open();
     });
     
  },// end initListeners();
  
  
  displayImage : function(){
    var image = new Image();
    var tmpDate = new Date();
    var time = tmpDate.getTime();
    image.src = this.currentItem.imgBig+"?action="+time;
    var obj = this;
    
    image.onload = function(){
    //  $("#content_img").width(image.width);
      $("#destockage_zoom").attr("src", image.src);
      
      $("#destockage_zoom").hide();
      $("#destockage_zoom").fadeIn();
    };
  },
  
  closeLb : function(){
    MyLightBox.close(MyLightBox.destroy);
  },
  
  
  changeDiapoForElt : function(elt){
    this.hideCanZoomIcon();
    var obj = this;
    this.midArea.children().first().fadeOut(300, function(){
        var nextItem = obj.items[obj.nextIndex];
        obj.items[obj.nextIndex] =  obj.items[obj.currentIndex];
        obj.items[obj.currentIndex] = nextItem;
        obj.currentItem = obj.items[obj.currentIndex];
        
        $(this).attr("src", obj.currentItem.imgMid);
        elt.children().first().attr("src", obj.items[obj.nextIndex].imgMin);
        
        $(this).fadeIn(200, function(){
          obj.canMove = true;
          obj.initCanZoomIcon.call(obj);
        });
    });
  }
  
};
// end prototype


})();



/**
 * ??
 */
(function(){
  
VisionneuseDestockageItem =  function(imgMin, imgMid, imgBig){
    this.imgBig = imgBig;
    this.imgMid = imgMid;
    this.imgMin = imgMin;
    
  };
})();




/**
 * 
 */
 (function(){
 
  VisionneuseCursor = function(){
    
  };
  
  VisionneuseCursor.prototype = {


    show : function(offset){

    },

    hide : function(){

    },

    move : function(offset){

    },

    convertOffset : function(offset){

    }
  
  };

 })();

