(function() {
	var views = [], prevIndex = 0, curIndex = 0, opacity = 0, pause = false;
	function updateAlpha() {
		if (opacity < 99) {
			opacity += 10;
			views[curIndex].style.filter = "alpha(opacity=" + opacity + ")";
			setTimeout(updateAlpha, 100);
		}
		else {
			views[curIndex].style.filter = "alpha(opacity=100)";
			finishTransition();
		}
	}
	function updateOpacity() {
		if (opacity < 0.99) {
			opacity += 0.1;
			views[curIndex].style.opacity = opacity;
			setTimeout(updateOpacity, 100);
		}
		else {
			views[curIndex].style.opacity = 1;
			finishTransition();
		}
	}
	function transition() {
		opacity = 0;
		views[prevIndex].style.zIndex = '1';
		if (views[curIndex].filters) {
			updateAlpha();
		}
		else {
			updateOpacity();
		}
		views[curIndex].style.display = 'block';
		views[curIndex].style.zIndex = '2';
	}
	function startTransition() {
		if (pause) {
			setTimeout(startTransition, 100);
		}
		else {
			prevIndex = curIndex;
			curIndex = (curIndex + 1) % views.length;
			transition();
		}
	}
	function finishTransition() {
		views[prevIndex].style.display = 'none';
		views[prevIndex].style.zIndex = '0';
		setTimeout(startTransition, 5000);
	}
	function load() {
		var vp, divs, i, l;
		vp = document.getElementById("homeTestimonials");
		if (vp && vp.getElementsByTagName) {
			divs = vp.getElementsByTagName('div');
			if (divs && divs.length > 1) {
				for (i = 0, l = divs.length; i < l; i++) {
					views[views.length] = divs[i];
				}
				vp.onmouseout = function() { pause = false; };
				vp.onmouseover = function() { pause = true; };
				setTimeout(startTransition, 5000);
			}
		}
	}
	if (document.getElementById) {
		MakinHey.event.addListener(window, 'load', load);
	}
} ());
