jQuery(document).ready(function(){
	jQuery(".slideshow").each(function(i){
		jQuery(this).attr('id',i);
		var counts=new Array();
		var sliderWidths=new Array();

		imgHeight = jQuery('img',this).attr('height');
		imgWidth = jQuery('img',this).attr('width');
		imgDuration = jQuery(this).attr('span');
		if (imgDuration==undefined)
		{
			imgDuration=3000;
		}
		counts[i] = jQuery('img',this).length;

	//make navigation

		jQuery(this).prepend('<div class="slideshownav"><div class="slideshowslider"></div></div>');
		
		sliderWidth=(imgWidth-200)/counts[i]
		navWidth=(imgWidth-200)
		navCenter=100;
		navBottom=(imgHeight-10);
		sliderWidths[i]=sliderWidth

		jQuery('.slideshowslider',this).css({'width' : sliderWidth+'px'});

		jQuery('.slideshownav',this).css({
			'margin-left' : navCenter+'px', 
			'margin-top' : navBottom+'px',
			'width' : navWidth+'px'
			});


	//format slideshow
		jQuery(this).css('height' , imgHeight);
		jQuery(this).children('a').css('position' , 'absolute');
		jQuery(this).children('a').fadeOut(0);

	//start rotation
		var index=new Array();
		var indexOut=new Array();
		index[i]=0
		indexOut[i]=-1
		
		jQuery('a:eq(' + index[i] + ')',this).fadeIn(0);
	//do rotation
		setInterval(function() {
			index[i]=index[i]+1
			indexOut[i]=indexOut[i]+1
			if (index[i]>(counts[i]-1)) {index[i]=0}
			if (indexOut[i]>(counts[i]-1)) {indexOut[i]=0}
			//alert(fadeLength[i])

			jQuery('.slideshowslider','#' + i).animate({left: index[i]*sliderWidths[i]},1000);
			//alert(count)
			jQuery('#'+i+' a:eq(' + index[i] + ')').fadeIn(1000);
			jQuery('#'+i+' a:eq(' + indexOut[i] + ')').delay(1000).fadeOut(1000);
		}, imgDuration);


	});
});
