// JavaScript Document

var numberOfMastheads = 10;
var currentMasthead = 1;
var mastheadRotateTimeoutSeconds = 12;
var mastTimeoutId = null;
mastheadRotateTimeout = mastheadRotateTimeoutSeconds*1000; 



function mastnext() {
	currentMasthead++;
	if (currentMasthead >numberOfMastheads) {
		currentMasthead = 1;
	}
	mastnav(currentMasthead);
}

function mastprev() {
	currentMasthead--;
	if (currentMasthead <1) {
		currentMasthead = numberOfMastheads;
	}
	mastnav(currentMasthead);
}			

function mastnav(showitem) {
	if (mastTimeoutId != null) {
		window.clearTimeout(mastTimeoutId);
	}
	if (showitem > numberOfMastheads) {
		showitem = numberOfMastheads;
	}
	currentMasthead = showitem;
	for (var i=1;i<=numberOfMastheads;i++) {
		obj = "masthead_"+i+"";
		itemobj = document.getElementById(obj);
		if (itemobj == null) {
			numberOfMastheads = i-1;
			// If we dont have as the desired masthead, display the last
			if (showitem > numberOfMastheads) {
				mastnav(numberOfMastheads);
			}			
			break;
		}
		else if (i == showitem) {
			itemobj.className='masthead_show';
		}
		else {
			itemobj.className='masthead_hidden';
		}
	}
	setMastTimeout();
}

function setMastTimeout() {
	mastTimeoutId = window.setTimeout("mastnext()",mastheadRotateTimeout);
}

setMastTimeout();
