var tabs = new Array("c1","c2","c3","c4","c5");

function setupTabs() {
	attachEventListener(document.getElementById('tablink_c1'),'click',show1,false);
	attachEventListener(document.getElementById('tablink_c2'),'click',show2,false);
	attachEventListener(document.getElementById('tablink_c3'),'click',show3,false);
	attachEventListener(document.getElementById('tablink_c4'),'click',show4,false);
	attachEventListener(document.getElementById('tablink_c5'),'click',show5,false);
}

function setActive() {
	// These two lines for random
	var rand = Math.floor(Math.random()*5) + 1;
	showC(rand);

	// Manual setting
	//showC(activeTab);
}

function show1() { showC(1); }
function show2() { showC(2); }
function show3() { showC(3); }
function show4() { showC(4); }
function show5() { showC(5); }

function showC(tab) {
	clearTabs();

	document.getElementById('tab_c'+tab).className = 'active';
	document.getElementById('c'+tab).style.display = 'block';

	positionArrow(tab);
}

function positionArrow(tab) {
	var fcCoords = $('feature_content').getCoordinates();
	var fcTop = Math.floor(fcCoords['top']);
	var coords = $('tab_c'+tab).getCoordinates();
	var newy = Math.floor(((coords['height'] / 2) + coords['top']) - fcTop - 10)+'px';
	$('active_arrow').style.top = newy;
	$('active_arrow').style.display = 'block';
}

function clearTabs() {
	for(i=1;i<=tabs.length;i++) {
		document.getElementById('tab_c'+i).className = '';
		document.getElementById('c'+i).style.display = 'none';
	}
}

addLoadEvent(setupTabs);
addLoadEvent(setActive);