var auto = false;
var forward = true;
var current = -1;
var max = 5;
var items = [];
var timer = null;

function autoForward() {
	forward = true;
	if(!auto) {
		auto = true;
		autoTimer();
	}
	$('newser_button_prev').className = "newser_button_prev";
	$('newser_button_next').className = "newser_button_next newser_button_next_on";
	$('newser_button_stop').className = "newser_button_stop";
	//alert("Switching.. " + forward);
}

function autoReverse() {
	forward = false;
	if (!auto) {
		auto = true;
		autoTimer();
	}

	$('newser_button_prev').className = "newser_button_prev newser_button_prev_on";
	$('newser_button_next').className = "newser_button_next";
	$('newser_button_stop').className = "newser_button_stop";
	//alert("Switching.. " + forward);
}


function autoTimer() {
	if (timer) clearTimeout(timer);
	if (!auto) return;
	timer = setTimeout("autoTimer()","5000");

	if (forward) nextSwitch();
	else prevSwitch();
}

function nextSwitch() {
	var next = current + 1;
	if (next >= max) next = 0;
	switchHighlight(next);
	switchNewsblock(next);
	current = next;
}
function prevSwitch() {
	var next = current-1;
	if (next < 0) next = max;
	switchHighlight(next);
	switchNewsblock(next);
	current = next;
}

function disableAuto()  {
	if (timer) clearTimeout(timer);
	auto = false;
	$('newser_button_prev').className = "newser_button_prev";
	$('newser_button_next').className = "newser_button_next";
	$('newser_button_stop').className = "newser_button_stop newser_button_stop_on";
}

function switchHighlight(id) {
	clearHighlight(id);
	if($('news_number_'+id) !=  null)
		$('news_number_'+id).className = "news_number numberOn";
}
function clearHighlight(id) {
	for(i = 0; i < max; i++) {
		if(i == id) continue;
		$('news_number_'+i).className = "news_number";
	}
}

function switchNewsblock(id) {
	hideNewsblocks();
	$('newser_content_'+id).style.display = "block";
}
function hideNewsblocks() {
	for(i = 0; i < max; i++) {
		$('newser_content_'+i).style.display = "none";
	}
}
function selectNewsblock(id) {
	switchHighlight(id);
	switchNewsblock(id);
	disableAuto();
}
