window.addEvent('domready', function() {
	if ($('casestudy_rotation_container')) {
		//
		// Begin case study rotation code
		//

		var el_box = $('casestudy_rotation_container');
		var itemInfo = $$('.casestudy_rotation_item');
		var items = new Array();
		var n;

		// Read in each item
		n = 0;
		itemInfo.each(function(item) {
			items[n++] = item.innerHTML;
		});

		// Rotate through items
		var rotateItems = function(n) {
			el_box.effects({duration: 600}).start({'opacity': 0}).chain(function(n) {
				el_box.setHTML(items[n % items.length]);
				setTimeout(function() {
					el_box.effects({duration: 875}).start({'opacity': 1});
				}, 250);
			}.pass(n));
			setTimeout(function() { rotateItems(++n); }, 7000);
		}

		el_box.setHTML(items[0]);
		if (items.length > 1)
			setTimeout(function() { rotateItems(1); }, 7000);
	}
});
