// JavaScript Document

window.addEvent('domready',function() {
	/* settings */
	var showDuration = 3000;
	var container = $('cwc_slideshow_container');
	var container_iphone = $('cwc_slideshow_container_iphone');
	var images = container.getElements('img');
	var images_iphone = container_iphone.getElements('img');
	var currentIndex = 0;
	var currentIndex_iphone = 0;
	var interval;
	var interval_iphone;
	/* opacity and fade */
	images.each(function(img,i){ 
		if(i > 0) {
			img.set('opacity',0);
		}
	});
	images_iphone.each(function(img,i){ 
		if(i > 0) {
			img.set('opacity',0);
		}
	});
	
	/* worker */
	var show = function() {
		images[currentIndex].fade('out');
		images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
	};
	
	var show_iphone = function() {
		images_iphone[currentIndex_iphone].fade('out');
		images_iphone[currentIndex_iphone = currentIndex_iphone < images_iphone.length - 1 ? currentIndex_iphone+1 : 0].fade('in');	
	}
	/* start once the page is finished loading */
	window.addEvent('load',function(){
		interval = show.periodical(showDuration);
		interval_iphone = show_iphone.periodical(showDuration);
	});
});
