/*
mooSimpleSlide - Simple SlideShow Class
version: 0.3
copyright 2008 04 02 - Huug Helmink, Ace Group bv
 
 
mootools v.1.11 classes
Core: Core
Class: Class, Class.Extras
Native: Array, String, Function, Number, Element
Fx: Fx.Base, Fx.Style
 
 
Usage:
Usage:
  var mySlideShow = new mooSimpleSlide([images::array]);
    or
  var mySlideShow = new mooSimpleSlide([images::array],{period:[interval between images in ms::integer]});
  mySlideShow.displayImage();
*/
var mooSimpleSlide = new Class({
  options: {
    period: 0
  },
  initialize: function(imageArray,options) {
    // Check if imageArray is an array
	//alert(imageArray.length);
    if($type(imageArray) != 'array' || imageArray.length <= 1) return;
 
    this.images = imageArray;
    this.setOptions(options);
    this.active = 0;
    this.max = this.images.length;
 
    // Set styles so images will fade in and out nicely
    this.images.each(function(img, key) {
		if(key > 0){// don't set the first image to opacity 1 and display inline
			img.setStyles({
				'display': 'none',
				'position': 'absolute',
				'opacity': 0
			});
		}else{
			img.setStyles({
				'position': 'absolute'
			});
		}
    });

    //this.images[0].getParent().setStyle('position','relative');
 
    // If period options is set > 0, periodical display an image
    if(this.options.period > 0) this.displayImage.periodical(this.options.period,this);
  },
 
  displayImage: function() {
    var FxTransitionTime = this.options.period/5;
 
    // Hide image
    this.images[this.active].effect('opacity',{duration:FxTransitionTime,onComplete:function(item) {
      item.setStyle('display','none');
    }}).start(1,0);
 
    // Set next image or the first
    if(this.active < this.max-1) this.active++;
    else this.active = 0;
 
    // Show image
    this.images[this.active].effect('opacity',{duration:FxTransitionTime,onStart:function(item) {
      item.setStyle('display','inline');
    }}).start(0,1);
  }
});
mooSimpleSlide.implement(new Options);
