/*

Script: Showcase.js
  Showcase - A mootools based image gallery

Version: 0.1
Mootools: 1.1

Author
  Corey Wilson, <http://2catdesigns.com>
  
*/

Element.extend({
  hide: function(){
    this.setStyle("display", "none");
  },
  show: function(){
    this.setStyle("display", "block");
  }
});

var Showcase = new Class({
	options: {
	  pane_current: 0,
	  showcase_pane_class:'showcase-pane',
	  showcase_next_id:'showcase-next',
	  showcase_prev_id:'showcase-prev',
	  showcase_wrap_id:'showcase-window',
	  show_next_id:'showcase-nonext',
	  show_prev_id:'showcase-noprev'
	},
	
  initialize: function(options) {
	this.setOptions(options);
    
	this.pane_count = $ES('.' + this.options.showcase_pane_class).length - 1;
	this.pane_width = $ES('.' + this.options.showcase_pane_class)[0].getStyle('width').toInt();

    $(this.options.showcase_prev_id).addEvent('click', this.move.pass(-1, this));
    $(this.options.showcase_next_id).addEvent('click', this.move.pass(1, this));
	
	if (this.pane_count==0) { 
		$(this.options.show_prev_id).show();
		$(this.options.show_next_id).show();
		$(this.options.showcase_prev_id).hide(); 
		$(this.options.showcase_next_id).hide(); 
	} else {
		$(this.options.showcase_prev_id).hide();
		$(this.options.showcase_next_id).show();  
		$(this.options.show_prev_id).show();
		$(this.options.show_next_id).hide();
	}
  },

  move: function(direction) {
    this.move_to(this.options.pane_current + direction, direction);
  },

  move_to: function(pane_index,direction) {
    if(typeof this.slide != "undefined") this.slide.stop();
    this.slide = $(this.options.showcase_wrap_id).effect("left", {duration: 450, wait:false, transition: Fx.Transitions.linear});  //Fx.Transitions.Expo.easeOut
	
	if (direction == 1){
		this.slide.start((pane_index * this.pane_width * -1)+444, pane_index * this.pane_width * -1);
	} else if (direction == -1){
		this.slide.start((pane_index * this.pane_width * -1)-444, pane_index * this.pane_width * -1);
	}
	
	this.options.pane_current = pane_index;

	if (pane_index == 0 && this.pane_count!=0) { 
		$(this.options.showcase_prev_id).hide();
		$(this.options.showcase_next_id).show();
		$(this.options.show_prev_id).show();
		$(this.options.show_next_id).hide();
    } else if (this.pane_count==0) { 
		$(this.options.show_prev_id).show();
		$(this.options.show_next_id).show();
		$(this.options.showcase_prev_id).hide(); 
		$(this.options.showcase_next_id).hide(); 
	} else if (pane_index == this.pane_count) { 
		$(this.options.showcase_prev_id).show(); 
		$(this.options.show_prev_id).hide();
		$(this.options.showcase_next_id).hide(); 
		$(this.options.show_next_id).show();
    } 
	else { 
		$(this.options.showcase_prev_id).show(); 
		$(this.options.showcase_next_id).show(); 
		$(this.options.show_next_id).hide();
		$(this.options.show_prev_id).hide();
    }
  }

});

Showcase.implement(new Options);
