YAHOO.namespace('anim');

YAHOO.anim.Swell = function(el, duration, easing) {
   if (el) { this.init(el, duration, easing); }
}

YAHOO.anim.Swell.prototype = {
   initial: {},
   expanded: {},
   
   zoomIn: function(e) {
      var el = this.getEl();
      var attributes = {
         width: { to: this.expanded.width },
         height: { to: this.expanded.height },
         left: { to: - (this.expanded.width / 4) },
         top: { to: - (this.expanded.height / 4) }
      };
      
      var anim = new YAHOO.util.Anim(el, attributes, this.duration, YAHOO.util.Easing.backOut);
      anim.animate();
      
      YAHOO.util.Event.addListener(el, 'mouseout', this.zoomOut, this, true);
      el.parentNode.parentNode.style.zIndex = 998;
   },
   
   zoomOut: function() {
      var el = this.getEl();
      
      var attributes = {
         width: { to: this.initial.width },
         height: { to: this.initial.height },
         left: { to: 0 },
         top: { to: 0 }
      };
      
      var anim = new YAHOO.util.Anim(el, attributes, this.duration, YAHOO.util.Easing.backOut);
      anim.animate();
      
      YAHOO.util.Event.removeListener(el, 'mouseout', this.zoomOut);
      el.parentNode.parentNode.style.zIndex = 1;
   },
   
   init: function(el, duration, easing) {
      // private
      el = YAHOO.util.Dom.get(el);
      var clone = el.cloneNode(true); // clone to extract sizes
      
      // privledged
      this.getEl = function() { return el; };
      
      // public
      this.duration = duration || 0.2;
      this.easing = easing || YAHOO.util.easeNone;
      
      this.initial = {
         width: parseInt(clone.style.width),
         height: parseInt(clone.style.height)
      };
      
      this.expanded = {
         width: clone.width,
         height: clone.height
      };
      YAHOO.util.Event.addListener(el, 'mouseover', this.zoomIn, this, true);  

      clone = null; // kill clone
   }
}
