// JavaScript Document

var tabCt = 3;
var rollActive = true;
var rollInterval = 5000;
var activeTab = 1;
var firstInt = true;

// Ensure timeout effect happens
if (window.addEventListener) {
	window.addEventListener("load",rollTabs,false);
}
else if (window.attachEvent) {
	window.attachEvent("onload",rollTabs);
}
else {
	window.onload=rollTabs;	
}


// Switches active elements to the new given tab number
function switchActive (newTab) {
	
	// Get current active elements 
	var romainAct = document.getElementById('ro-main-' + activeTab);
	var rocapAct = document.getElementById('ro-cap-' + activeTab);
	var rotitleAct = document.getElementById('ro-title-' + activeTab);
	var rotabAct = document.getElementById('ro-tab-' + activeTab);
	
	// Get desired active elements 
	var romainNew = document.getElementById('ro-main-' + newTab);
	var rocapNew = document.getElementById('ro-cap-' + newTab);
	var rotitleNew = document.getElementById('ro-title-' + newTab);
	var rotabNew = document.getElementById('ro-tab-' + newTab);


	// If all objects found then re-assign active classes and new activetab 
	if (romainAct && rocapAct && rotitleAct && romainNew && rocapNew && rotitleNew) {
		romainAct.className = 'ro-main';
		rocapAct.className = 'ro-cap';
		rotitleAct.className = 'ro-title';
		rotabAct.className = 'ro-tab';
		
		romainNew.className = 'ro-main ro-main-active';
		rocapNew.className = 'ro-cap ro-cap-active';
		rotitleNew.className = 'ro-title ro-title-active';
		rotabNew.className = 'ro-tab ro-tab-active';

		activeTab = newTab;
	}
}


function selectActive (newTab) {
// Used when tab links are moused over, will toggle the active tabs 
	rollActive = false;
	switchActive(newTab);
}



function rollTabs () {

    var newTab = 1;
	
	if ((activeTab == tabCt) || firstInt) {
		newTab = 1;	
		firstInt = false;
	}
	else {
		newTab = activeTab + 1;	
	}
	
	if (rollActive) {
        switchActive(newTab);
        setTimeout("rollTabs()",rollInterval);
    }
	
}







