/****************************
GridBox
Version: 1.0
@author Alvaro Talavera (alvarotala@gmail.com)
*****************************/

var GridBox = Class.create({
  
  initialize: function(speed, margin) {
	this.speed = speed;
	this.margin = margin;
	this.elements = $$('div.boxgrid');
	this.effect = new Array();
	
	this.set_listeners();
  },

  set_listeners: function() {
	var obj = this;
	this.elements.each(function(el) {		
		el.observe('mouseover', function(event){
		  obj.hover(el, 1);
		});
		
		el.observe('mouseout', function(event){
		  obj.hover(el, 0);
		});
	});
  },

  hover: function(el, show) {
	var id = el.previousSiblings().length;
	var a = el.down('DIV', 0);
	
	var direction = (show==1 ? '0px' : (this.margin + 'px'));
	if(this.effect[id] != undefined) {
		this.effect[id].cancel();
	}
	this.effect[id] = new Effect.Morph(a, { style: { marginTop: direction }, duration: this.speed });
  }

});