//=======================================================\\
//                    Anderemedia.nl                     \\
//                   Copyright (c) 2003                  \\ 
//=======================================================\\

function init() {
 	if (!document.getElementById 
	 || !document.getElementsByTagName 
	 || !document.createElement 
	 || typeof document.getElementsByTagName("head")[0].innerHTML == "undefined"
	 || (window.showModalDialog && navigator.userAgent.toLowerCase().indexOf("mac") > -1)) {
	 	return;
	}
	
	setCanvas();
	window.onresize = setCanvas;

	document.getElementById("divPage").style.fontSize = Text.size + Text.unit;
	document.getElementById("divSizer").style.fontSize = Text.size + Text.unit;

	columns = Columns.splitText(document.getElementById('divContent').innerHTML, colWidth, colHeight);
	while (columns.length < 2) columns.push("<p>&nbsp;</p>");
	numCols = columns.length - 1;
		
	doColumnsAndLinks();
	
	colTitles = getColumnTitles();
	
	document.getElementById("divTitles").innerHTML = " browse slides";
	
	document.getElementById("divLoading").style.visibility = "hidden";

	scrollToChapter(chapter);

	setLocationBar();

	objIssueContents = new make("divIssueContents");
	objToggContents = new make("divContentsToggle");

	if(heading != "home" && issueName != "information") {
	objIssueContents.show();
	objToggContents.show();
	objIssueContents.moveTo(15 - objIssueContents.elm.offsetWidth, objIssueContents.elm.offsetTop);
	}
	
	killoutlines();
}

window.onload = init;

function setCanvas() {
	canvas = new getCanvas();
	var canvasLeft = (canvas.w - document.getElementById("divCanvas").offsetWidth) / 2;
	var canvasTop = (canvas.h - document.getElementById("divCanvas").offsetHeight) / 3;
	if (canvasLeft < 0) canvasLeft = 0;
	if (canvasTop < 0) canvasTop = 0;
	document.getElementById("divCanvas").style.left = canvasLeft + "px";
	document.getElementById("divCanvas").style.top = canvasTop + "px";
}


var Text = {
	size : parseInt(GetCookie("fontsize", 11)),
	unit : "px",
	
	doSize : function(num) {
		Text.size += num;
		if (Text.size < 1) Text.size = 1;
		SetCookie ("fontsize", Text.size, 24*365);
		document.getElementById("divPage").style.fontSize = Text.size + Text.unit;
		document.getElementById("divSizer").style.fontSize = Text.size + Text.unit;
		init();
		if (currentCol > columns.length - 2) {
			currentCol = columns.length - 2;
			objLink.moveTo(32 + currentCol*10, objLink.y);
			objSlider.moveTo(-currentCol*360, objSlider.y);
			setLocationBar();
		}
	}
}


function doColumnsAndLinks() {
	var tx = "";
	var links = '<img src="/pres/n5m/images/1x1.gif" height="1" width="31" alt="" />';
	for (var i=0; i<columns.length; i++) {
		tx += '<div id="divColumn' + i + '" style="position: absolute; top: 0px; left: ' + (i*(colWidth+colSpace)+colSpace) + 'px; width: ' + colWidth + 'px; height: ' + colHeight + 'px;">'
		tx += columns[i];
		tx += '</div>';
		links += '<a href="#" onclick="scrollTo('+i+'); return false;" onmouseover="showTitle('+i+'); window.status=\'\'; return true;" onmouseout="resetTitle(); window.status=\'\';"><img src="/pres/n5m/images/nav_square.gif" border="0" height="12" width="10" alt="" /></a>';
	}
	objSlider = new make("divPageSlider");
	objLink = new make("divLinkBlock");
	objSlider.elm.innerHTML = tx;
	
	var tempLinks = document.getElementById("divLinks");
	tempLinks.innerHTML = links;
	document.getElementById("divTitles").style.left = tempLinks.offsetLeft + tempLinks.offsetWidth + 1 + "px";
}


function getColumnTitles() {
	var headers = new Array();
	var titles = new Array();
	var img = null;
	
	for (var i = 0; i < 100; i++) {
		if (!document.getElementById("divColumn" + i)) break;
		
		for (var j = 1; j <= 6; j++) {
			headers = document.getElementById("divColumn" + i).getElementsByTagName("h" + j);
			if (!headers || headers.length == 0) continue;
			
			img = headers[0].getElementsByTagName("img")[0];
			
			if (img && img.title) {
				titles[i] = img.title.toLowerCase();
				break;
			}
			else if (img && img.alt) {
				titles[i] = img.alt.toLowerCase();
				break;
			}
			else {
				titles[i] = headers[0].innerHTML.toLowerCase();
				break;
			}
		}
		if (!titles[i] && i == 0) titles[i] = "navigate";
		if (!titles[i] && i != 0) titles[i] = titles[i-1];
	}
	return titles;
}


function scrollToChapter(c) {
	chapter = c;
	var i = 0;
	while (colTitles[i] != chapter && i < colTitles.length) { i++; }
	if (i != colTitles.length) scrollTo(i);
	return false;
}


 function setLocationBar() {
 	if (currentCol != 0) chapter = colTitles[currentCol];
 	else chapter = "";
	
 	objLocation = new make("divLocation");
 	var strLocation = '&nbsp;&nbsp;&nbsp;&nbsp;<strong>';
 	if(issue=="none" || issue=="") {
 		strLocation += '<a href="/?title=' + heading;
 	} else if(!heading || heading=="home" ) {
 		var monthNo = issue.getMonth()+1;
 		if(monthNo < 10) monthNo = "0" + monthNo;
 		strLocation += '<a href="/?issue=' + issue.getFullYear() + "." + monthNo;
 	} else {
 		var monthNo = issue.getMonth()+1;
 		if(monthNo < 10) monthNo = "0" + monthNo;
 		strLocation += '<a href="/?issue=' + issue.getFullYear() + "." + monthNo + '&amp;title=' + heading;
 	}

 	if(chapter) strLocation  += '&chapter=' + chapter;
 	strLocation += '">Anderemedia</a>:';
 	strLocation += '</strong> &nbsp;' + issueName + ' &#187; ' + heading.replace(/\_/," ");
 	if(chapter) strLocation += ' &#187; ' + chapter.replace(/\_/," ");
	
 	objLocation.elm.innerHTML = strLocation;
}


function killoutlines() {
	var lnks = document.links ? document.links : document.getElementsByTagName ? document.getElementsByTagName("a") : null;
	if (lnks) {
		for (var m = 0; lnks[m]; m++) {
			lnks[m].onfocus = function(){ this.blur() };
		}
	}
}


function scrollTo(i) {
	if (columns.length > 2) {
		currentCol = i;
		if (currentCol < 0) currentCol = 0;
		if (currentCol >= numCols - 1) currentCol = numCols - 1;
		setPos();
	}
}


function scrollLeftArrow() {
	if (currentCol > 0) {
		currentCol--;
		setPos();
	}
}


function scrollRightArrow() {
	if (currentCol < numCols - 1) {
		currentCol++;
		setPos();
	}
}

function scrollRightbutton() {
	if (currentCol < numCols - 1) {
		currentCol++;
		setPos();
	}
}

function setPos() {
	objLink.timeSlide(32 + currentCol*10, objLink.y, 1500, -0.999, null, true);
	objSlider.timeSlide(-currentCol*(colWidth+colSpace), objSlider.y, 1500, -0.999, null, true);
	setLocationBar();
}


function showTitle(num) {
	document.getElementById("divTitles").innerHTML = ":&nbsp;" + colTitles[num];
}


function resetTitle() {
	document.getElementById("divTitles").innerHTML = ": browse slides";
}

	
var contentState = false;
function toggleContents() {
	if (contentState) {
		objIssueContents.timeSlide(15-objIssueContents.elm.offsetWidth, objIssueContents.elm.offsetTop, 1500, -0.999, null, true);
		objSiteContents.timeSlide(15, objSiteContents.elm.offsetTop, 1500, -0.999, null, true);
		contentState = false;
		document.getElementById("anchorArrow").innerHTML = "&#187;";
	}
	else {
		objIssueContents.timeSlide(15, objIssueContents.elm.offsetTop, 1500, -0.999, null, true);
		objSiteContents.timeSlide(0-objSiteContents.elm.offsetWidth, objSiteContents.elm.offsetTop, 1500, -0.999, null, true);
		contentState = true;
		document.getElementById("anchorArrow").innerHTML = "&#171;";
	}
}

precache("/pres/n5m/images/nav_text.gif");
precache("/pres/n5m/images/nav_square.gif");

var arrow_left_off = precache("/pres/n5m/images/arrow_left.gif");
var arrow_left_on = precache("/pres/n5m/images/arrow_left2.gif");
var arrow_right_off = precache("/pres/n5m/images/arrow_right.gif");
var arrow_right_on = precache("/pres/n5m/images/arrow_right2.gif");

