//////////////////////////////////////////////////////////////////////
//																	//
//		Slideshow Script											//
//		Copyright 2010 - James Clarke, Adnet Communications			//
//		Requires Mootools 1.1 Library								//
//																	//
//////////////////////////////////////////////////////////////////////


window.addEvent('domready',function(){		
	
	var rateOfChange = 2000;
	var pause = 5000;								

	// create images, position absolute
	// create fx and hide
	// fade through images
	// at end, hide all and restart
	
	var imgSrcs = new Array(
			"/i/common/home/f3.jpg",
			"/i/common/home/f12.jpg",
			"/i/common/home/f10.jpg",
			"/i/common/home/f14.jpg",
			"/i/common/home/f11.jpg",
			"/i/common/home/f13.jpg",
			"/i/common/home/f15.jpg",
			"/i/common/home/f1.jpg"
   		 );
	
	$('photoimg').setStyle('position','absolute');
	
	imgSrcs.each(function(item){
		new Element('img',{'src':item, 'class':'slideshow'}).injectInside('photodiv');					  
	})

	var items = $('photodiv').getElements('img[class=slideshow]');
		
	var itemFx = new Array();
	
		items.each(function(item){
			item.setStyle('position','absolute');			
			itemFx.push( new Fx.Style(item,'opacity',{'duration':rateOfChange}).hide() );
		});
	
	var index = 0; 	
	var count = 0
	var last = 0;
	var inter = setInterval(advance,pause);
	
		function advance(){
			
			count++;
			items[index].setStyle('z-index',1000+count);
			itemFx[index].start(0,1);
			itemFx[last].set(0);
		
			if(index==itemFx.length-1){
				index = 0;
			}else{
				index++;
			}
			last = index;
			
		}

});
