Slideshow = new Class
({
	// Implementation
	Implements: [Options],

	// Options
	options:
	{
		switcher: 'div'
	},

	// Initialize
	initialize: function(options)
	{
		// Set options
		this.setOptions(options);

		// Objects
		this.switcher = this.options.slideshowElement.getElements(this.options.switcher);
		this.index = 0;
		this.imageBlur = null;
		this.imageDark = null;

		// Set fade effect
		this.switcher.set('morph', {duration: 3000, transition: this.options.slideshowFxTransition});

		// Resume or pause slideshow on mouseenter and mouseleave event of slideshow container
		this.options.navigationElement.addEvents
		({
			mouseenter: function() { slideshow.stop(); },
			mouseleave: function() { slideshow.start(); }
		});

		// Start slideshow
		this.start();
    },

	/*
	 * Start
	 */
	start: function()
	{
		// Create a periodical interval of showing slides
		this.interval = this.show.periodical(this.options.slideshowFxDuration, this);
	},

	/*
	 * Stop
	 * Clears an interval
	 */
	stop: function() { $clear(this.interval); },

	/*
	 * Show slide
	 */
	show: function(counter)
	{
		// Fade out current slide and make current navigation link unactive
		this.switcher[this.index].morph({'opacity': [1, 0]});

		// Get new slide index
		this.index = ($defined(counter) ? counter : (this.index < this.switcher.length - 1 ? this.index + 1 : 0));

		// Blured images
		this.imageBlur = this.switcher[this.index].getChildren('img').getProperty('src').toString().replace('.jpg', '_blur.jpg');
	
		// Set blured
		$$('#header #navigation #expand div div.expand').each(function(item)
		{
			item.setStyle('background-image', 'url("' + this.imageBlur + '")');
		}.bind(this));

		// Fade in new slide and make new navigation link active
		this.switcher[this.index].morph({'opacity': [0, 1]});

	}
});

// Instance
window.addEvent('domready', function()
{
	slideshow = new Slideshow
	({
		navigationElement: $('navigation'),
		slideshowElement: $('jsSlideshowElement'),
		slideshowFxTransition: Fx.Transitions.Cubic.easeOut,
		slideshowFxDuration: 6000
	});
});
