// initialization items - do not change
var sections = new Array();
var currentSection = 0;
var currentFontSize = 'standard';
var currentContrast = 'standard';
var currentLanguage = 'en';
var winHelp;


// application code - do not change

function AddSection(shortName, longTitle, htmlID) {
	
	var obj;
		
	obj = new Object();
	
	obj.name = shortName;
	obj.title = longTitle;
	obj.id = htmlID;

	sections.push(obj);

}

function OpenHelp(url) {

	// this function opens a small window with the help file in it.

	w = 500;
	h = 400;
	x = 0;

	if (screen) {
		x = screen.width - w - 100;
	}

	if (!winHelp || winHelp.closed) {
		winHelp = window.open(url, "help", "scrollbars,resizable,width=" + w + ",height=" + h + ",left=" + x + ",top=10");
	} else {
		winHelp.document.location = url;
	}

	winHelp.focus();

}


function PlaySound(file) {

	document.getElementById('soundFrame').src = 'sounds/' + file + '.wav';

}


function EnableSection(sectionIndex) {

	//if (!sectionIndex) {
	//	sectionIndex = currentSection;
	//}

	currentSection = sectionIndex;
	
	// hide all elements of these section elements
	
	for (var i = 0; i < sections.length; i++) {
	
		if (document.getElementById(sections[i].id + '-en')) {
			document.getElementById(sections[i].id + '-en').style.display = 'none';
		}
	
		if (document.getElementById(sections[i].id + '-es')) {
			document.getElementById(sections[i].id + '-es').style.display = 'none';
		}
	
	}
	
	// display the one section element we want
	
	if (document.getElementById(sections[currentSection].id + '-' + currentLanguage)) {
	
		document.getElementById(sections[currentSection].id + '-' + currentLanguage).style.display = 'block';

	} else {
	
		// default to english

		document.getElementById(sections[currentSection].id + '-en').style.display = 'block';
	
	}
		
	GenerateTopNavBar();

	GenerateBottomNavButtons();

}


function setActiveStyleSheet(title) {

	var i, a, main;

	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {

		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {

			a.disabled = true;

			if(a.getAttribute("title") == title) {

				a.disabled = false;
			}

		}

	}

}

function GenerateTopNavBar() {

	var content = '';

	content += eval('activityNavigationDescription_' + currentLanguage);

	for (var i = 0; i < sections.length; i++) {
	
		if (i != 0) {
		
			content += ' — ';
		
		}
	
		if (i == currentSection) {

			content += ' <strong>' + sections[i].name + '</strong> ';
		
		} else {
		
			content += ' <a href="" onclick="EnableSection(' + i + '); return false;" title="' + sections[i].title + '">' + sections[i].name + '</a> ';
		
		}
	
	}

	document.getElementById('top-navigation').innerHTML = content;

}

function ChangeContrast(option) {

	currentContrast = option;

	var stylesheet = currentFontSize + '-' + currentContrast;
	
	setActiveStyleSheet(stylesheet);

	GenerateToolBar();

}

function ChangeFontSize(option) {

	currentFontSize = option;

	var stylesheet = currentFontSize + '-' + currentContrast;
	
	setActiveStyleSheet(stylesheet);
	
	GenerateToolBar();

}


function ChangeLanguage(option) {

	currentLanguage = option;
	
	GenerateToolBar();

	EnableSection(currentSection);

}




function GenerateToolBar() {

	var content = '';
	
	if (currentFontSize == 'standard') {
	
		content += ' <input type="button" value="Bigger Text" onclick="ChangeFontSize(\'largetext\');"> ';
	
	} else {
	
		content += ' <input type="button" value="Smaller Text" onclick="ChangeFontSize(\'standard\');"> ';
	
	}

	if (currentContrast == 'standard') {
	
		content += ' <input type="button" value="High Contrast" onclick="ChangeContrast(\'highcontrast\');"> ';
	
	} else {
	
		content += ' <input type="button" value="Standard Contrast" onclick="ChangeContrast(\'standard\');"> ';
	
	}

	if (currentLanguage == 'en') {
	
		content += ' <input type="button" value="Español" onclick="ChangeLanguage(\'es\');"> ';
	
	} else {
	
		content += ' <input type="button" value="English" onclick="ChangeLanguage(\'en\');"> ';
	
	}

	document.getElementById('tools').innerHTML = content;

}

function GenerateBottomNavButtons() {

	var content = '';
	
	var prev = currentSection - 1;
	
	var next = currentSection + 1;
	
	if (prev < 0) {

		content += ' <input type="button" value="Prev" id="prevButton" disabled="disabled"> ';
	
	} else {
	
		content += ' <input type="button" value="Prev" id="prevButton" onclick="EnableSection(' + prev + ');"> ';
	
	}
	
	if (next > (sections.length - 1)) {
	
		content += ' <input type="button" value="Next" id="nextButton" disabled="disabled"> ';
	
	} else {
	
		content += ' <input type="button" value="Next" id="nextButton" onclick="EnableSection(' + next + ');"> ';
	
	}
	
	document.getElementById('bottom-navigation').innerHTML = content;

}



window.onload = function() {
	document.getElementById('top-navigation').style.display = 'block';
	document.getElementById('bottom-navigation').style.display = 'block';
	document.getElementById('tools').style.display = 'block';
	EnableSection(0);
	GenerateTopNavBar();
	GenerateToolBar();
	GenerateBottomNavButtons();
}
