
/*
 * News Rotation
 * by Camilo Kawerín
 *
 */

var rotateSpeed = 6000;
var allNews = 6;
var pauseNews = false;

function rotateNews(dirNews) {
	currentNews = parseFloat(mainNews.className.replace("noticia", ""));
	currentNews = currentNews + dirNews;
	if (currentNews >= allNews) {
		currentNews = 0;
	} else if (currentNews < 0) {
		currentNews = allNews - 1;
	}
	mainNews.className = "noticia" + String(currentNews);
}

function initRotate() {
	if (!pauseNews) {
		rotateNews(1);
	}
}

function initNews() {
	mainNews = document.getElementById("noticias-nivel-uno");
	if (document.getElementById("controls")) {
		$("#controls .foward a").click(function() {
					rotateNews(1);
					return false;
				});
		$("#controls .rewind a").click(function() {
					rotateNews(-1);
					return false;
				});
		$("#controls .pause a").click(function() {
					if (!pauseNews) {
						pauseNews = true;
					} else {
						pauseNews = false;
					}
					return false;
				});
		setInterval("initRotate()", rotateSpeed);
	}
}


