/**
 * ViewMediaZoom
 */
var ViewMediaZoom = Class.create({
  /**
   * Init ViewMediaZoom
   */	
  initialize: function() {
	this.options = Object.extend({
	  elemContent : null
	}, arguments[0] || { });		

    this.contentFade = new EggFade({elemContent:this.options.elemContent});
	
	this.arrItems = new Array();
	this.nCurrItem = -1;
	this.bLocked = true;
	
    var elemItems = this.options.elemContent.select('.item');
    var item;	
    
    for (var nItem = 0; nItem < elemItems.length; nItem++) {
      item = new ViewMediaZoomItem({elemContent:elemItems[nItem]});    
      elemItems[nItem].observe('item:click', this.itemClick.bind(this));	  
      this.arrItems.push(item);
    }
  },

  getCurrItemPages: function() {
    return this.arrItems[this.nCurrItem].getNumPages();   
  },
  
  show: function(nItem) {
	this.bLocked = false;
	  
	if (this.nCurrItem != -1) {
	  this.arrItems[this.nCurrItem].hideNow();	
	}	
	this.nCurrItem = nItem;
	  
	this.options.elemContent.style.visibility = "visible";
	  
	this.contentFade.show();
    this.arrItems[this.nCurrItem].show();   
  },

  hide: function() {
	this.contentFade.hide();
  },

  showPrevious: function() {
	if (this.bLocked) {
	  return;
	}
	this.bLocked = true;
	
    this.arrItems[this.nCurrItem].showPrevious();     
    
	this.unlock.bind(this).delay(1);
  },

  showNext: function() {
	if (this.bLocked) {
	  return;
	}
	this.bLocked = true;
	  
	this.arrItems[this.nCurrItem].showNext();     	
	
	this.unlock.bind(this).delay(1);
  },

  unlock: function() {
	this.bLocked = false;
  },
  
  itemClick: function(evt) {
	// fire event
	this.options.elemContent.fire("viewzoom:click");	
  }
  
});
