/**
 * Adverts
 */
var Adverts = Class.create({
	/**
	 * Init Adverts
	 */
	initialize: function(adverts) {
		this.adverts = adverts;
	  
    var elemBtn;
		//init adverts	
		this.adverts.each(function(item, index) {
		  // init move transition
		  item.moveEffect = null;
		    
      elemBtn = item.down('.btn');
      if (elemBtn) {
        elemBtn.setOpacity(0);        
        elemBtn.style.visibility = "visible";
        elemBtn.observe('click', this.clickOverlay.bind(item));
        elemBtn.observe('mouseover', this.showOverlay.bind(item));
        elemBtn.observe('mouseout', this.hideOverlay.bind(item));

        item.down('.back').setOpacity(0.5);
        
        elemOverlay = item.down('.overlay');
        elemOverlay.style.display = "block";        
        // store text height
        item.nTextHeight = elemOverlay.down('.text').getHeight();        
      }
		}.bind(this)); 
	},

	clickOverlay: function(evt) {
	  window.location = this.readAttribute('href'); 
	},
	
	showOverlay: function(evt) {
    evt.element().setStyle({cursor:"pointer"});  
    // cancel transition
    if (this.moveEffect) {
      this.moveEffect.cancel();
    }        
    this.moveEffect = new Effect.Move(this.down('.overlay'), {duration:0.5, y:116 - this.nTextHeight + 40, mode:'absolute'});
  },

	hideOverlay: function(evt) {
    // cancel transition
    if (this.moveEffect) {
      this.moveEffect.cancel();
    }    
    this.moveEffect = new Effect.Move(this.down('.overlay'), {duration:0.5, y:116, mode:'absolute'});
  }
	
});
