ie = document.all
loc = location.href
screenshot = parent.topdir + "screenshot.html?"
screenshots = new Array()
function mkPage(nr,prevPage,nextPage) {
	if (typeof(parent.pageArray) == "undefined") {
		parent.pageArray = new Object()
	}
	if (!parent.pageArray[nr]) parent.pageArray[nr] = 0
	window.prevPage = prevPage
	window.nextPage = nextPage
	window.nr = nr
	with (document.body.style) {
		font = "15px Times New Roman,serif"
		padding = "9 49 9 49"
	}
	var ifrWidth = (ie) ? parent.ifrWidth - 6 : parent.ifrWidth
	var ifrHeight = (ie) ? parent.ifrHeight - 6 : parent.ifrHeight
	var docWidth = document.body.offsetWidth
	var docHeight = document.body.offsetHeight
	if (docWidth > ifrWidth) ifrWidth = docWidth
	if (docHeight > ifrHeight) ifrHeight = docHeight
	
	var prev = document.createElement("span")
	document.body.appendChild(prev)
	if (prevPage) {
		prev.innerHTML = "previous"
		prev.onclick = function() {
			window.location = prevPage 
		}
	}
	with (prev.style) {
		position = "absolute"
		left = 3
		top = "2pt"
		color = "blue"
		textDecoration = "underline"
		cursor = "pointer"
	}
	
	var main = document.createElement("span")
	document.body.appendChild(main)
	main .innerHTML = "back to main"
	main.onclick = function() {
		parent.window.location = "../../main.html"
		
	}
	with (main.style) {
		position = "absolute"
		left = 70
		top = "2pt"
		color = "blue"
		textDecoration = "underline"
		cursor = "pointer"
	}
	
	var next = document.createElement("span")
	document.body.appendChild(next)
	if (nextPage) {
		next.innerHTML = "next"
		next.onclick = function() {
			window.location = nextPage 
		}
	}
	with (next.style) {
		position = "absolute"
		left =  ifrWidth - 2*next.offsetWidth
		top = "2pt"
		color = "blue"
		textDecoration = "underline"
		cursor = "pointer"
	}
	var pagenr = document.createElement("span")
	document.body.appendChild(pagenr)
	if (location.href.match("presentation")) {
		pagenr.innerHTML = "Presentation " + nr
	} else if (location.href.match("userguide")) {
		pagenr.innerHTML = "User's Guide " + nr
	} else {
		pagenr.innerHTML = nr
	}
	with (pagenr.style) {
		position = "absolute"
		left = (ifrWidth / 2) - (pagenr.offsetWidth / 2)
		top = "2pt"
	}
	document.onkeydown = function(e) {
		if (!e) var e = event
		if (e.keyCode == 33 && prevPage) window.location = prevPage
		else if (e.keyCode == 34 && nextPage) window.location = nextPage
		else if (e.keyCode == 39 || e.keyCode == 32 || e.keyCode == 40) {
			screenshots[currentLink].style.color = "blue"
			screenshots[currentLink].style.backgroundColor = "white"
			++currentLink
			if (currentLink >= screenshots.length) currentLink = 0
			screenshots[currentLink].style.color = "red"
			screenshots[currentLink].style.backgroundColor = "yellow"
			parent.pageArray[nr] = currentLink
		} else if (e.keyCode == 37 || e.keyCode == 38) {
			screenshots[currentLink].style.color = "blue"
			screenshots[currentLink].style.backgroundColor = "white"
			--currentLink
			if (currentLink < 0) currentLink = screenshots.length - 1
			screenshots[currentLink].style.color = "red"
			screenshots[currentLink].style.backgroundColor = "yellow"
			parent.pageArray[nr] = currentLink
		} else if (e.keyCode == 13) {
			window.location = screenshots[currentLink].img
		}
	}
}

function mkLink(img) {
	var link = document.createElement("span")
	document.body.appendChild(link)
	with (link.style) {
		cursor = "pointer"
		color = "blue"
		fontSize = "15"
		fontWeight = 900
	}
	link.innerHTML = "&rArr;"
	var dir = location.href.replace(/(.*)\/.*\.html/,"$1") + "/"
	link.img = screenshot + dir + img
	link.onclick = function() {
		screenshots[currentLink].style.color = "blue"
		screenshots[currentLink].style.backgroundColor = "white"
		window.location = this.img
//		window.open(this.img,"screenshots")
		currentLink = this.nr
		screenshots[currentLink].style.color = "red"
		screenshots[currentLink].style.backgroundColor = "yellow"
		parent.pageArray[window.nr] = currentLink
	}
	link.nr = screenshots.length
	screenshots[screenshots.length] = link
}

//examples_text_dir = "http://145.18.125.63/mapclient/examples/html_text/"
//examples_run_dir  = "http://145.18.125.63/mapclient/examples/"
examples_text_dir = parent.topdir + "examples/html_text/"
examples_run_dir  = parent.topdir + "examples/"

function mkRef(url,text) {
	var link = document.createElement("span")
	if (text && text != "norun") link.innerHTML = "&nbsp;" + text
	else link.innerHTML = "&nbsp;" + url
	with (link.style) {
		cursor = "pointer"
		color = "blue"
		textDecoration = "underline"
	}
	var runLink = false
	if ( ! url.match(/http:\/\//)) {
		if (parent.MSINSTALLED && text != "norun" && url != "userguide" && url != "refguide" && url != "examples" && typeof(examples_run_dir != "undefined")) {
			runLink = document.createElement("span")
			runLink.innerHTML = "&nbsp;&bull;&nbsp;"
			with (runLink.style) {
				cursor = "pointer"
				color = "blue"
			}
			var runurl = examples_run_dir + url
			runLink.onclick = function() {
				window.open(runurl,"examples_run")
			}
		}
		if (url == "examples.map") url = examples_text_dir + "examples.map.txt"
		else if (url == "examples.js") url = examples_text_dir + "examples.js.txt"
		else if (url == "zoom.js") url = examples_text_dir + "zoom.js.txt"
		else if (url == "window.js") url = examples_text_dir + "window.js.txt"
		else if (url =="userguide") url = "../../userguide/main.html"
		else if (url =="refguide") url = "../../refguide/main.html"
		else if (url =="examples") url = "../../examples/main.html"
		else url = examples_text_dir + url
		var window_to_open = "examples_txt"
	} else {
		var window_to_open = "general_link"
	}
	link.onclick = function() {
		window.open(url,window_to_open)
	}
	document.body.appendChild(link)
	if (runLink) document.body.appendChild(runLink)
}


window.onload = function() {
	var toc = parent.document.getElementsByTagName("iframe")[0]
	var links = toc.contentWindow.document.getElementsByTagName("a")
	for (var i = 0;i<links.length;i++) {
		var link = links[i]
		if (link.href == window.location) with (link.style) {
			color = "red"
			textDecoration = "underline"
		} else with (link.style) {
			color = "blue"
			textDecoration = "none"
		}
	}
	currentLink = parent.pageArray[window.nr]
	if (screenshots[currentLink]) with (screenshots[currentLink].style) {
		color = "red"
		backgroundColor = "yellow"
	}
	window.focus()
}
