/*

Script: Showcase.js
  Showcase - A mootools based image gallery

Version: 0.4

License:
  Creative Commons Attribution 3.0 License. 
  To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/

Showcase Copyright:
  copyright (c) 2008 Corey Wilson, <http://2catdesigns.com>
  
*/

window.addEvent('domready', function() {
  sc = new Showcase();
});

Element.implement({
  hide: function(){
    this.setStyle("display", "none");
  },
  show: function(){
    this.setStyle("display", "block");
  }
});

var Showcase = new Class({

  pane_current : 0,

  initialize: function() {

    this.pane_count = $$('.showcase-pane').length - 1;
    this.pane_width = $$('.showcase-pane')[0].getStyle('width').toInt();

    ['showcase-prev', 'showcase-next'].each(function(button) {
      this.init_button(button);
    },this);

    $('showcase-prev').addEvent('click', this.move.pass(-1, this));
    $('showcase-next').addEvent('click', this.move.pass(1, this));
    
    $('showcase-prev').hide();

    this.slide = new Fx.Tween('showcase-window', {
      duration:800, 
      link:'ignore', 
      transition: Fx.Transitions.Cubic.easeOut, 
    });

    this.fade = new Fx.Tween
  },

  move: function(direction) {
    this.move_to(this.pane_current + direction);
  },

  move_to: function(pane_index) {
    this.slide.start('left', pane_index * this.pane_width * -1);

    this.pane_current = pane_index;

    if (pane_index == 0) { 
      $('showcase-prev').hide(); 
      $('showcase-next').show(); 
    
    } else if (pane_index == this.pane_count) { 
      $('showcase-prev').show(); 
      $('showcase-next').hide(); 
    
    } else { 
      $('showcase-prev').show(); 
      $('showcase-next').show(); 
    }
  },

  init_button: function(button) {
    $(button).setOpacity(0.4);
    $(button).onmouseover = this.toggle_button.pass([button, 0.9], this);
    $(button).onmouseout = this.toggle_button.pass([button, 0.4], this);
  },

  toggle_button: function(id, value) {
    this.fade = new Fx.Tween($(id), { duration: 250, link: 'ignore' }).start('opacity', value);
  }

});
