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);
	var obj = "but"+currentMasthead+"left"
	itemobj = document.getElementById(obj);
	
	mastheadposition(itemobj.id);
	
}

function mastprev() {
	currentMasthead--;
	if (currentMasthead <1) {
		currentMasthead = numberOfMastheads;
	}
	mastnav(currentMasthead);
	var obj = "but"+currentMasthead+"left"
		itemobj = document.getElementById(obj);
		
	mastheadposition(itemobj.id);
}			


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';
			document.getElementById("mast_a"+i).className='mast_a_selected';
			
		}
		else {
			itemobj.className='masthead_hidden';
			document.getElementById('mast_a'+i).className='mast_a_notselected';
		}
	}
	setMastTimeout();
}

function setMastTimeout() {
	mastTimeoutId = window.setTimeout("mastnext()",mastheadRotateTimeout);
}

setMastTimeout();
