/*
mooSimpleSlide - Simple SlideShow Class
version: 0.4
copyright 2008 07 25 - Huug Helmink, Ace Group bv


mootools v.1.2 classes
Core: Core, Browser
Native: Array, Function, Number, String, Hash
Class: Class, Class.Extras
Element: Element, Element.Style
Fx: Fx, Fx.CSS, Fx.Tween


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({
  Implements: Options,
  options: {
    period: 0,
	starter:1
  },
  initialize: function(imageArray,options) {
    // Check if imageArray is an array
    if($type(imageArray) != 'array') 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) {
      img.setStyles({
        'display': 'none',
        'position':'absolute',
		'width':'100%'
      }).fade('hide');
    });
    
    // If period options is set > 0, periodical display an image
    if(this.options.period > 0) this.displayImage.periodical(this.options.period,this);
  },

  displayImage: function() {
	   if(this.options.starter > 0) {
			var FxTransitionTime = this.options.period/2;				
			
			// Hide image
			this.images[this.active].get('tween',{property:'opacity', duration:FxTransitionTime, onComplete:function(item) {
			  item.setStyle('display','none');
			}}).start(1,0);
			
			var dvNum =	jQuery("#dvNumbers");
			var img = 0;
			var actImage = this.active;					
				
			// Set next image or the first
			this.active < this.max - 1 ? this.active++ : this.active = 0;			

			// Show image
			this.images[this.active].get('tween',{property:'opacity', duration:FxTransitionTime, onStart:function(item) {
			item.setStyle('display','inline');
			jQuery("a", dvNum).each(function(){				
			jQuery(this).removeClass();
				if(img == actImage)
				{
					jQuery(this).addClass("active");
					ShowDivContent	(img);
				}					
				img++;
			});		
			}}).start(0,1);							
	   }
  },
  
  stop: function(){
		this.options.starter=0;		
		this.images[this.active].set('style','visibility: hidden;')
  }
});
