// Winks an element out of existance, adds a wrapper element to accomplish the effect.
Fx.MyWink = Fx.Elements.extend({
  initialize: function(element, options) {
    this.element = $(element);
    this.wrapper = new Element('div', {'styles': {'overflow': 'hidden'}}).injectAfter(this.element).adopt(this.element);
    this.original_margins = this.element.getStyles('margin-top', 'margin-bottom');
    this.parent( [ this.element, this.wrapper ], options );
    this.open = true;
    this.next_open = null;
    this.addEvent( 'onComplete', function() {
      if( this.next_open != null )
        this.open = this.next_open;
      this.next_open = null;
    });
  },
  show: function() {
    this.open = true;
    return this.set({
      '0': {
        'margin-top': this.original_margins['margin-top'].toInt(),
        'margin-bottom': this.original_margins['margin-bottom'].toInt()
      },
      '1': {
        'height': this.element.offsetHeight + this.original_margins['margin-top'].toInt() + this.original_margins['margin-bottom'].toInt()
      }});
  },
  hide: function() {
    this.open = false;
    return this.set({
      '0': {
        'margin-top': -this.element.offsetHeight/2,
        'margin-bottom': -this.element.offsetHeight/2
      },
      '1': {
        'height': 0
      }});
  },
  slideIn: function() {
    this.next_open = false;
    return this.start({
      '0': {
        'margin-top': [ this.element.getStyle('margin-top').toInt(), -this.element.offsetHeight/2 ],
        'margin-bottom': [ this.element.getStyle('margin-bottom').toInt(), -this.element.offsetHeight/2 ]
      },
      '1': {
        'height': [ this.element.offsetHeight - this.element.getStyle('margin-top').toInt() - this.element.getStyle('margin-bottom').toInt(), 0 ]
      }});
  },
  slideOut: function() {
    this.next_open = true;
    return this.start({
      '0': {
        'margin-top': [ this.element.getStyle('margin-top').toInt(), this.original_margins['margin-top'].toInt() ],
        'margin-bottom': [ this.element.getStyle('margin-bottom').toInt(), this.original_margins['margin-bottom'].toInt() ]
      },
      '1': {
        'height': [
          this.wrapper.getStyle('height').toInt(),
          this.element.offsetHeight + this.original_margins['margin-top'].toInt() + this.original_margins['margin-bottom'].toInt() ]
      }});
  },
  toggle: function() {
    if( this.open )
      this.slideIn();
    else
      this.slideOut();
  }
});


