function flippy_toggle() {
  if (this.revealed)
    x = -220;
  else
    x = 0;

  if (!this.flipping) 
    new Effect.Move( this.container, { x:x, y:0, duration:this.duration, mode:'absolute', 
      beforeStart: flippy_start.bind(this), afterFinish: flippy_finish.bind(this) });
}

function flippy_finish() {
  this.flipping = false;
  this.revealed = !this.revealed;
  flippy_timer.bind(this)();
}

function flippy_start() {
  this.flipping = true;
}

function flippy_timer() {
  if (this.revealed) {
    window.clearTimeout(this.timer);
    this.timer = window.setTimeout( flippy_toggle.bind(this), this.timeout );
  }
}

function flippy_mouseover() {
  if (this.revealed)
    flippy_timer.bind(this)();
  else
    flippy_toggle.bind(this)();
}

function Flippy( element ) {
  this.duration = 0.25; // duration of the flip effect (default: 0.25s)
  this.flipping = false;
  this.element = $(element);
  this.container = this.element.childElements()[0];
  this.revealed = false;
  this.timer = null;
  this.timeout = 5000; // how long before the flippy times out (default: 5000ms)

  Event.observe( this.element, 'mouseover', flippy_mouseover.bindAsEventListener(this) );
}

