dojo.require('dojo.fx');
dojo.require('dojo.fx.easing');

dojo.addOnLoad(function(){

	/* Showcase carousel */
	var container = dojo.query('#showcase ul')[0];
	var pages = dojo.query('#showcase li');
	var currentpage = 0;
	var nextpage = 1;
	
	// Set container width
	//var containersize = dojo.style(container, 'width');
	dojo.style(container, 'width', 100*pages.length+'%'); // Doesn't work in IE8
	//dojo.style(container, 'width', containersize*pages.length + 'px'); // Use pixels instead
	
	
	// Change page
	var timer = setInterval(function(){
	
		// Get current positions
		var currentposition = dojo.style(container, 'left');
		var newposition = dojo.coords(pages[nextpage]).l;
		
		// Animate
		dojo.animateProperty({
			node: container,
			duration: 1000,
			easing: dojo.fx.easing.cubicInOut,
			properties: {
				left: {
					start: currentposition,
					end: -newposition,
					unitx: "px"
				}
			}
		}).play();
		
		// Update the indexes
		currentpage = nextpage;
		nextpage = currentpage < pages.length-1 ? currentpage+1 : 0;
		
	}, 12000);

});
