var contentMap = new Array();
var contentMapLoaded = false;
var featureContents = new Array();
var featureIndex=1;

function buildContentMap(xmlDoc) {
	var contents = xmlDoc.getElementsByTagName('content');
	var i;
	for(i=0;i<contents.length;i++)
		contentMap[contents[i].getAttribute('ref')] = contents[i].getAttribute('url');
	contentMapLoaded = true;
}

function init() {
	featureIndex=1;
	initFeatures();
	//importXML('ContentMap.xml',buildContentMap);	
}

function loadDictList(letter) {
	document.getElementById("dictlocation").value = letter;
	document.getElementById("dictform").submit();
}

function loadDictList2(letter) {
	loadDocument("dictionary/" + letter + "List.html", setDictContent);
}

function loadDictWord(word) {
	document.getElementById("dictlocation").value = word;
	document.getElementById("dictform").submit();
}

function loadDictWord2(word) {
	loadDocument("dictionary/" + word + ".html", setDictContent);
}

function setDictContent(content) {
	document.getElementById('dict_content').innerHTML = content;
}

function setMainContent(content) {
	document.getElementById('content').innerHTML = content;
	document.getElementById('content').style.height = 'auto';
}

function setFeatureContent(content) {
	document.getElementById('featurecontent').innerHTML = content;
	document.getElementById('featurecontent').style.height = 'auto';
}

function navMoveTo(ref) {
	document.getElementById('location').value = ref;
	document.getElementById('locationform').submit();
}

function navMoveTo2(ref) {
	var url;
	if (contentMapLoaded) {
		try {
			url = contentMap[ref];		
			loadDocument(url, setMainContent);
		} catch(ex) { setMainContent('Content Not Mapped or Not Available'); }						

	} else {
		setTimeout('navMoveTo("'+ref+'")',1000);
	}
}

function rotateFeature() {
	var url;
	try {
		if (featureContents.length >= 1) {
			url = featureContents[featureIndex];
			featureIndex = (featureIndex+1) % featureContents.length;
			loadDocument(url, setFeatureContent);
		}
	} catch(ex) { }						
	setTimeout('rotateFeature()',10000);
}

function dictMoveTo(ref, word) {
	var url;
	if (contentMapLoaded) {
		try {
			url = contentMap[ref];		
			loadDocumentSync(url, setMainContent);
			loadDictWord(word);
		} catch(ex) { setMainContent('Content Not Mapped or Not Available'); }						

	} else {
		setTimeout('navMoveTo("'+ref+'")',1000);
	}
}

function initFeatures() {
	featureContents.push('feature1.html');
	featureContents.push('feature2.html');
}