if(typeof Whywoodworks == 'undefined') {
	var Whywoodworks = {};
}

Whywoodworks.Slideshow = Class.create();
Whywoodworks.Slideshow.prototype = {
	initialize: function(params) {

		var cssid='', speed=2000, width=0, height=0, imgwidth=0, imgheight=0; 

		if(typeof params.cssid == 'string') cssid = params.cssid;      
		if(typeof params.speed == 'number') speed=params.speed;
	   	if(typeof params.imgwidth== 'number') imgwidth=params.imgwidth;
		if(typeof params.imgheight== 'number') imgheight=params.imgheight;
		if(typeof params.width== 'number') width=params.width; else width=imgwidth;
		if(typeof params.height== 'number') height=params.height; else height=imgheight;

		if(cssid.length < 1) return;

		$(cssid).setStyle({'height': height});
		$(cssid).setStyle({'minHeight': height});

		var imgs = $$('#' + cssid + '> .slide img ');
		var slides = $$('#' + cssid + '> .slide');

		slides.each(function(slide){ if(imgwidth>0) slide.width  = imgwidth; if(imgheight>0) slide.height = imgheight; slide.hide(); });
		imgs.each(function(img){ if(imgwidth>0) img.width=imgwidth; if(imgheight>0) img.height=imgheight; });

		var index=0;

		Effect.Appear(slides[index++], { from: 0.0, to: 1.0 , duration: 1.0, queue: 'front'});

		setInterval(function(){
		    var previous = index-1;
			if(index==0) previous = slides.length-1;  
			Effect.Fade(slides[previous], { from: 1.0, to: 0.0 , duration: 1.0, queue: 'front' });
			Effect.Appear(slides[index], { from: 0.0, to: 1.0 , duration: 1.0, queue: 'end'});
			if(++index > slides.length-1) index=0;
		}, speed);
	}
}

Event.observe(document, 'dom:loaded', function() {
	$$('.www-slide > .slide').each(function(img){ img.hide(); });
});

/*
 * example
 *
 * <div class="www-slide" id="www-slide1">
 *   <div class='slide'><img src="http://www.whywoodworks.co.uk/media/catalog/product/f/i/file_4_11.gif" alt="" /></div>
 *   <div class='slide'><img src="http://www.whywoodworks.co.uk/media/catalog/product/f/i/file_2_114.gif" alt="" /></div>
 *   <div class='slide'><img src="http://www.whywoodworks.co.uk/media/catalog/product/f/i/file_3_80.gif" alt=""/></div> 
 *   <div class='slide'><img src="/media/catalog/product/p/i/pintoy.gif" alt="" /></div>
 * </div>
 *
 * <script type='text/javascript'>
 * //<![CDATA[
 * Event.observe(window,'load', function() {  
 *   new Whywoodworks.Slideshow({ 
 *     cssid: 'www-slide1',
 *     imgwidth: 100,
 *     imgheight: 100,
 *     speed: 1500
 *   });
 * });
 * //]]>
 * </script>
 */




