



var ZSlideShow = Class.create();

ZSlideShow.prototype = {
	
	initialize: function( oUl ) {
		var oSlideShow = this;
		
		oUl.style.listStyleType = 'none';
		oUl.style.position = 'relative';
		oUl.style.overflow = 'hidden';
		
		this.aImages = Array();
		this.iDisplayedIdx = 0;
		
		$A( oUl.childNodes ).each(
			function( oChild, iIdx ) {
				if ( oChild.tagName && oChild.tagName.match( /li/i ) ) {
					$A( oChild.childNodes ).each(
						function( oItemChild, iIdx ) {
							if ( oItemChild.tagName && oItemChild.tagName.match( /img/i ) ) {
								var oImg = oItemChild;
								if(oSlideShow.aImages.length == 0)
								{
									oImg.style.display = 'block';
								}
								else
								{
									oImg.style.display = 'none';
								}
								oImg.style.position = 'absolute';
								oImg.style.top = '0';
								oImg.style.left = '0';
								oSlideShow.aImages[oSlideShow.aImages.length] = oImg;
							}
						}
					)
				}
			}
		);
		

		var transition = function() {

			var oCurrentImage = oSlideShow.aImages[oSlideShow.iDisplayedIdx];
			var oNextImage = null;
//			alert( 'last image = ' + oSlideShow.aImages.length );
//			alert('Displayedldx = ' + oSlideShow.iDisplayedIdx);
			if ( oSlideShow.iDisplayedIdx < oSlideShow.aImages.length - 1 ) {
				
				oNextImage = oSlideShow.aImages[++oSlideShow.iDisplayedIdx];
//				alert('Next image = ' + oNextImage);
			} else {
//				alert('End of list ' +  oSlideShow.aImages[0]);
				oNextImage = oSlideShow.aImages[0];
				oSlideShow.iDisplayedIdx = 0;
			}
			
//			oNextImage.style.display = 'block';
			
			new Effect.Parallel(
				[ new Effect.Fade( oCurrentImage, { sync: true } ),
				  new Effect.Appear( oNextImage, { sync: true } ) ]
			);
		};
		
		new PeriodicalExecuter( transition, 3 );
	}
	
};

Event.observe(
	window,
	'load',
	function() {
		$A( document.getElementsByClassName( 'replace-with-zslideshow' ) ).each(
			function( oElem, iIdx ) {
				if ( oElem.tagName && oElem.tagName.match( /ul/i ) ) {
					new ZSlideShow( oElem );
				}
			}
		);
	},
	false
);
