/*

Script: Showcase.js
  Showcase - A mootools based image gallery

Version: 0.3.1

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() {
  box = new MultiBox('mb', { useOverlay: true });
  sc = new Showcase();
  
  t = new Tooltip();
  t.show_it.delay(1000, t);
  t.hide_it.delay(6000, t);
});

Element.extend({
  hide: function(){
    this.setStyle("display", "none");
  },
  show: function(){
    this.setStyle("display", "block");
  }
});

var Showcase = new Class({

  pane_current : 0,
  
  initialize: function() {
    this.pane_count = $ES('.showcase-pane').length - 1;
    this.pane_width = $ES('.showcase-pane')[0].getStyle('width').toInt();
        
    $('showcase-play').addEvent('click', this.start_show.bind(this));
    $('showcase-prev').addEvent('click', this.move.pass(-1, this));
    $('showcase-next').addEvent('click', this.move.pass(1, this));
    
    $('showcase-prev').hide();
  },

  move: function(direction) {
    this.move_to(this.pane_current + direction);
  },

  move_to: function(pane_index) {
    if(typeof this.slide != 'undefined') this.slide.stop();    
    this.slide = $('showcase-window').effect('left', {duration: 950, wait:false, transition: Fx.Transitions.Quad.easeInOut}); 
    this.slide.start(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(); 
    }
  },

  toggle_button: function(id, value) {
    if(typeof this.fade != 'undefined') this.fade.stop();
    this.fade = new Fx.Style($(id), 'opacity').start(value);
  },
  
  start_show: function() {
    box.autoplay();
  } 

});


var Tooltip = new Class({ 

  initialize: function() {
    this.tip = $('gallery-tip');
    this.fade = this.tip.effect('opacity', {duration: 1100}); 
    this.slide = this.tip.effect('top', {duration: 950, transition: Fx.Transitions.Quad.easeIn}); 
    this.tip.setStyle('opacity', 0);
  },

  show_it: function() {
    this.tip.show();
    this.fade.start(1);
    this.slide.start(130);
  },

  hide_it: function() {
    this.fade.start(0);
    this.slide.start(180);
  }
});

/*
  show_tooltip: function() {
    var g = $('gallery-tip');

//    fade = new Fx.Style(g, 'opacity', {duration: 1000}).start(1);



    fade.start(0).delay(2000);
    slide.start(180).delay(2000);
  }
*/