//var currentMain=Math.floor(Math.random()*4) + 1;
var currentMain = 0;
var timer = null;
var addList = new Array(1,3,4,5);

function advanceMain()
{

	var newMain = currentMain;

	document.getElementById("main_links_" + addList[currentMain]).style.display = 'none';
	if(newMain < (addList.length - 1))
	{
		newMain++;
	} else {
		newMain = 0;
	}
	
	changeToItem(addList[newMain]);
	currentMain = newMain;
//	document.getElementById("main_wrapper").style.background = 'url(images/main_' + currentMain + '.jpg)';
//	document.getElementById("main_links_" + currentMain).style.display = 'block';	
}

function changeMain(mainId)
{
	changeToItem(mainId);
	clearInterval(timer);
	return false;
}

function changeToItem(mainId) {

	document.getElementById("main_right_list_item_" + addList[currentMain]).className = '';
	document.getElementById("main_right_list_item_" + mainId).className = 'main_right_list_item_sel';
	
	document.getElementById("main_links_" + addList[currentMain]).style.display = 'none';
	currentMain = getPosition(mainId);
	document.getElementById("main_links_" + addList[currentMain]).style.display = 'block';
//	document.getElementById("main_wrapper").style.background = 'url(images/main_' + currentMain + '.jpg)';
}

function getPosition(mainId) {

	var i = 0;
	
	for (i = 0; i < addList.length; i++) {
		if (addList[i] == mainId) return i;
	}

	return -1;
}

function startTimer() {
	timer = setInterval ( "advanceMain()", 7500 );// JavaScript Document
}