//******************************************************************************/
//																				/
// All parts of this file - including, but not limited to, images, layout, 		/
// code, and scripts - are copyright R.F.J. Vring (ArVee). 						/
// All code is (c) ArVee, 2005-2006 unless otherwise noted in the source code. 	/
// No parts may be used without the expressed, written consent of ArVee. 		/
// Partially or wholly reproducing portions of this file without written  		/
// consent is strictly prohibited.												/
//																				/
// (c) 2005, 2006 R.F.J. Vring (ArVee) (arvee_at_notebook@hotmail.com)			/
//																				/
//******************************************************************************/

var colors = [ '#544a4d', '#78383f', '#365747', '#4d2617', '#3d2636', '#404238' ];
var color_index = 0;
var nPORTFOLIO_TOPICS = 6;
var nPORTFOLIO_THUMBNAILS = 11;
var currentPortfolioNav = -1;
var currentPortfolioSubNav = -1;
var currentPortfolioPhoto = -1;
var currentPortfolioTopic = -1;
var portfolioDefault = null;        // Leave the default image page empty
var portfolio;                      // Will be filled when requested

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
function $(id) {
	return document.getElementById(id);
	}
//-------------------------------------------------------------------------------
// check if an element is empty in some way										-
//-------------------------------------------------------------------------------
function isEmpty(T) { 
	try {
		return (T === null || T === undefined || T === "" || T === NaN); 
		}
	catch (ex) {
		return true;
		}
	}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
function contains (s, t) {
	var e = s.split(" ");
	var i, j; for (i = 0, j = e.length; i < j; i++) {
		if (e[i] === t) {
			return true;
			}
		}
	return false;
	}
//-------------------------------------------------------------------------------
// fetch all elements of a specific type, that have the given classname			/
// sample:																		/
//		var a = getElementsByClassName('div','widget');							/
// returns:																		/
//		array of elements														/
//-------------------------------------------------------------------------------
function getElementsByClassName (type,name) {
	var result = [];
	var name1 = "";
	var name2 = " " + name.toLowerCase() + " ";
	var elements = document.getElementsByTagName(type);
	var element = null;
	var i, n; for (i = 0, n = elements.length; i < n; i++) {

		element = elements[i];
		
		if (isEmpty(element.className)) {
			continue;
			}

		name1 = element.className.toLowerCase();
		if (name1.indexOf(name) < 0) {
			continue;
			}

		name1 = " " + name1 + " ";
		if (name1.indexOf(name2) < 0) {
			continue;
			}

		result.push(element);
		}
	return result;
	}
//-------------------------------------------------------------------------------
// register an event handler on an event target									/
//		element: 	the element to register the handler for.					/
//		event:		event name													/
//		what:		event handler function										/
//		capture:	if true, useCapture indicates that the user wishes to 		/
//					initiate capture. After initiating capture, all events of 	/
//					the specified type will be dispatched to the registered 	/
//					EventListener before being dispatched to any EventTargets 	/
//					beneath them in the tree. Events which are bubbling upward 	/
//					through the tree will not trigger an EventListener 			/
//					designated to use capture.									/
//-------------------------------------------------------------------------------
function handleEvent (element, event, what, capture) {
	if (isEmpty(element['on' + event])) {
		element['on' + event] = function(){};
		}
	if (element.attachEvent) {
		element.attachEvent('on' + event, what);
		}
	else if (element.addEventListener) {
		element.addEventListener(event, what, isEmpty(capture) ? false : capture);
		}
	else {
		what();
		}
	}
//-------------------------------------------------------------------------------
// removal of event listeners from the event target								/
//-------------------------------------------------------------------------------
function unhandleEvent (element, event, what) {
	if (element.detachEvent) {
		element.detachEvent('on' + event, what);
		}
	else if (element.removeEventListener) {
		element.removeEventListener(event, what, false);
		}
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function cookieSet (name, value, days) {
	var expires = ""; 

	if (isEmpty(days)) {
		days = 999;
		}
		
	var date = new Date(); 
	date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 
	expires = "; expires=" + date.toGMTString(); 

	document.cookie = name + "=" + value + expires + "; path=/"; 
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function cookieGet (name) {

	var nameEQ = name + "="; 
	var ca = document.cookie.split(';'); 
	
	for (var i = 0; i < ca.length; i ++) {
		var c = ca[i]; 
		
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length); 
			}
		
		if (c.indexOf(nameEQ) === 0) {
			return c.substring(nameEQ.length, c.length); 
			}
		}
	
	return null; 
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function cookieExists (name) {
	var e = cookieGet(name);
	return (e === null) ? false : true;
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function cookieRemove (name) {
	createCookie(name, "", -1); 
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function getLeft (e) {
	var n = e.style.left;
	if (isEmpty(n)) {
		n = e.style.pixelLeft;
		}
	return parseInt(n,0);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function getAbsLeft (e) {
	var o = e.offsetLeft;
	while (isEmpty(e.offsetParent) === false) {
		e = e.offsetParent;
		o += e.offsetLeft;
		}
	return o;
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function getAbsTop(e) {
	var o = e.offsetTop;
	while (isEmpty(e.offsetParent) === false) {
		e = e.offsetParent;
		o += e.offsetTop;
		}
	return o;
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function getWidth(e) {
	return Math.max(
		parseInt(e.clientWidth,0), 
		parseInt(e.offsetWidth,0)
		);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function getHeight(e) {
	return Math.max(
		parseInt(e.clientHeight,0), 
		parseInt(e.offsetHeight,0)
		);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function clearContainer (e) {
	while (e.childNodes.length) {
		e.removeChild(
			e.firstChild
			);
		}
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function hilightarrow (what,where,yep) {
	$('arrow' + what + '_' + where + '_focus').style.display = yep ? 'block' : 'none';
	$('arrow' + what + '_' + where + '_normal').style.display = yep ? 'none' : 'block';
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function showbody() {
	document.getElementsByTagName('body')[0].className += " body";
	$('body_mask').style.visibility = 'visible';
	$('content_container').style.visibility = 'visible';
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function showfluiter() {
	var _fotoframe = $('fotoframe');
	var _footer = $('footer');
	if (getAbsTop(_footer) < (getAbsTop(_fotoframe) + getHeight(_fotoframe))) {
		_footer.style.visibility = 'hidden';
		}
	else if (isEmpty(_footer.style.display) || _footer.style.visibility != 'visible') {
		_footer.style.visibility = 'visible';
		}
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function colorize() {
	var blocks = getElementsByClassName('DIV', 'colorize');
	var i, n; for (i = 0, n = blocks.length; i < n; i++) {
		blocks[i].style.backgroundColor = colors[color_index];
		}
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function setColor (index) {
	if (index < 0) {
		index = colors.length - 1;
		}
	else if (index >= colors.length) {
		index = 0;
		}
	color_index = index;
	cookieSet('color_index', color_index);
	colorize();
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function prev_color () {
	setColor(color_index - 1);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function next_color () {
	setColor(color_index + 1);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function scrollSomethingLeft(container,maxItems) {
	var thumbnails = $(container).getElementsByTagName("A");
	if (contains(thumbnails[0].className,'visible')) {
		// already scrolled to the first thumbnail
		return;
		}
	var firstVisible = -1;
	var i, n; for (i = 0, n = thumbnails.length; i < n; i++) {
		if (firstVisible === -1 && contains(thumbnails[i].className,'invisible') === false) {
			firstVisible = i;
			}
		thumbnails[i].className = thumbnails[i].className.replace(/invisible/gi,"");
		thumbnails[i].className = thumbnails[i].className.replace(/visible/gi,"");
		thumbnails[i].className += (thumbnails[i].className.length ? ' invisible' : 'invisible');
		}
	firstVisible--;
	if (firstVisible < 0) {
		firstVisible = 0;
		}
	var lastThumbnail = firstVisible + (maxItems - 1);
	if (lastThumbnail >= thumbnails.length) {
		lastThumbnail = thumbnails.length - 1;
		}
	for (i = firstVisible; i < lastThumbnail; i++) {
		thumbnails[i].className = thumbnails[i].className.replace(/invisible/gi,"");
		thumbnails[i].className += (thumbnails[i].className.length ? ' visible' : 'visible');
		}
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function scrollSomethingRight(container,maxItems) {
	var thumbnails = $(container).getElementsByTagName("A");
	if (contains(thumbnails[thumbnails.length - 1].className,'visible')) {
		// already scrolled to the last thumbnail
		return;
		}
	var firstVisible = -1;
	var i, n; for (i = 0, n = thumbnails.length; i < n; i++) {
		if (firstVisible === -1 && contains(thumbnails[i].className,'invisible') === false) {
			firstVisible = i;
			}
		thumbnails[i].className = thumbnails[i].className.replace(/invisible/gi,"");
		thumbnails[i].className = thumbnails[i].className.replace(/visible/gi,"");
		thumbnails[i].className += (thumbnails[i].className.length ? ' invisible' : 'invisible');
		}
	var lastThumbnail = firstVisible + maxItems;
	if (lastThumbnail >= thumbnails.length) {
		lastThumbnail = thumbnails.length - 1;
		}
	firstVisible = lastThumbnail - (maxItems - 1);
	if (firstVisible < 0) {
		firstVisible = 0;
		}
	for (i = firstVisible; i <= lastThumbnail; i++) {
		thumbnails[i].className = thumbnails[i].className.replace(/invisible/gi,"");
		thumbnails[i].className += (thumbnails[i].className.length ? ' visible' : 'visible');
		}
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function scrollThumbnailsLeft(n) {
	scrollSomethingLeft('thumbnails',nPORTFOLIO_THUMBNAILS);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function scrollThumbnailsRight(n) {
	scrollSomethingRight('thumbnails',nPORTFOLIO_THUMBNAILS);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function scrollPortfolioTopicsLeft(n) {
	scrollSomethingLeft('portfolioTopics',nPORTFOLIO_TOPICS);
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function scrollPortfolioTopicsRight(n) {
	scrollSomethingRight('portfolioTopics',nPORTFOLIO_TOPICS);
	}
//------------------------------------------------------------------------------/	
// show the previous photo														/
//------------------------------------------------------------------------------/	
function prev_photo () {
	var thumbnails = $("thumbnails").getElementsByTagName("A");
	if (currentPortfolioPhoto == -1) {
		currentPortfolioPhoto = 0;
		}
	else {
		currentPortfolioPhoto--;
		}
	if (currentPortfolioPhoto < 0) {
		currentPortfolioPhoto = 0;
		}
	if (contains(thumbnails[currentPortfolioPhoto].className,'invisible')) {
		scrollThumbnailsLeft(1);
		}
	thumbnails[currentPortfolioPhoto].onclick();
	}
//------------------------------------------------------------------------------/	
// show the next photo															/
//------------------------------------------------------------------------------/	
function next_photo () {
	var thumbnails = $("thumbnails").getElementsByTagName("A");
	if (currentPortfolioPhoto == -1) {
		currentPortfolioPhoto = 0;
		}
	else {
		currentPortfolioPhoto++;
		}
	if (currentPortfolioPhoto >= thumbnails.length) {
		currentPortfolioPhoto = thumbnails.length - 1;
		}
	if (contains(thumbnails[currentPortfolioPhoto].className,'invisible')) {
		scrollThumbnailsRight(1);
		}
	thumbnails[currentPortfolioPhoto].onclick();
	}
//------------------------------------------------------------------------------/	
// show previous portfolio topic												/
//------------------------------------------------------------------------------/	
function prev_topic () {
	var portfolioTopics = $("portfolioTopics").getElementsByTagName("A");
	if (currentPortfolioTopic == -1) {
		currentPortfolioTopic = 0;
		}
	else {
		currentPortfolioTopic--;
		}
	if (currentPortfolioTopic < 0) {
		currentPortfolioTopic = 0;
		}
	if (contains(portfolioTopics[currentPortfolioTopic].className,'invisible')) {
		scrollPortfolioTopicsLeft(1);
		var i, j; for (i = 0, j = portfolioTopics.length; i < j; i++) {
			if (contains(portfolioTopics[i].className, 'visible')) {
				portfolioTopics[i].className = portfolioTopics[i].className.replace(/visible/gi,'');
				}
			}
		}
	portfolioTopics[currentPortfolioTopic].onclick();
	}
//------------------------------------------------------------------------------/	
// show next portfolio topic 													/
//------------------------------------------------------------------------------/	
function next_topic () {
	var portfolioTopics = $("portfolioTopics").getElementsByTagName("A");
	if (currentPortfolioTopic == -1) {
		currentPortfolioTopic = 0;
		}
	else {
		currentPortfolioTopic++;
		}
	if (currentPortfolioTopic >= portfolioTopics.length) {
		currentPortfolioTopic = portfolioTopics.length - 1;
		}
	if (contains(portfolioTopics[currentPortfolioTopic].className,'invisible')) {
		scrollPortfolioTopicsRight(1);
		var i, j; for (i = 0, j = portfolioTopics.length; i < j; i++) {
			if (contains(portfolioTopics[i].className, 'visible')) {
				portfolioTopics[i].className = portfolioTopics[i].className.replace(/visible/gi,'');
				}
			}
		}
	portfolioTopics[currentPortfolioTopic].onclick();
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function initialize() {
	if (cookieExists('color_index')) {
		color_index = parseInt(cookieGet('color_index'),0);
		color_index = parseInt(cookieGet('color_index'),0);
		}
	// attach navigational clicks to the menu buttons							/
	var navigatieLinks = $('navigatie').getElementsByTagName('A');
	var i, n; for (i = 0, n = navigatieLinks.length; i < n; i++) {
		handleEvent(
			navigatieLinks[i], 'click', 
			function(e) { 
				var target = isEmpty(e.target) ? e.srcElement : e.target;
				handleNav(target.parentNode.id);
				return false;
				}
			);	
		}
	//
	var barLinks = getElementsByClassName('DIV','bar');
	for (i = 0, n = barLinks.length; i < n; i++) {
		handleEvent(
			barLinks[i], 'click', 
			function(e) { 
				var target = isEmpty(e.target) ? e.srcElement : e.target;
				setColor(target.id.charCodeAt(0) - 97);
				return false;
				}
			);	
		}
	//
	var prevColor = $('prevColor');
		handleEvent(
			prevColor, 'click', 
			function(e) { 
				prev_color();
				return false;
				}
			);	
		handleEvent(
			prevColor, 'mouseover', 
			function(e) { 
				hilightarrow('',"left",true);
				}
			);	
		handleEvent(
			prevColor, 'mouseout', 
			function(e) { 
				hilightarrow('',"left",false);
				}
			);	
	//
	var nextColor = $('nextColor');
		handleEvent(
			nextColor, 'click', 
			function(e) { 
				next_color();
				return false;
				}
			);	
		handleEvent(
			nextColor, 'mouseover', 
			function(e) { 
				hilightarrow('',"right",true);
				}
			);	
		handleEvent(
			nextColor, 'mouseout', 
			function(e) { 
				hilightarrow('',"right",false);
				}
			);	
	//
	var prevPage = $('prevPage');
		handleEvent(
			prevPage, 'click', 
			function(e) { 
				prev_photo();
				return false;
				}
			);	
		handleEvent(
			prevPage, 'mouseover', 
			function(e) { 
				hilightarrow('1',"left",true);
				}
			);	
		handleEvent(
			prevPage, 'mouseout', 
			function(e) { 
				hilightarrow('1',"left",false);
				}
			);	
	//
	var nextPage = $('nextPage');
		handleEvent(
			nextPage, 'click', 
			function(e) { 
				next_photo();
				return false;
				}
			);	
		handleEvent(
			nextPage, 'mouseover', 
			function(e) { 
				hilightarrow('1',"right",true);
				}
			);	
		handleEvent(
			nextPage, 'mouseout', 
			function(e) { 
				hilightarrow('1',"right",false);
				}
			);	
	//
	var prevTopic = $('prevTopic');
		handleEvent(
			prevTopic, 'click', 
			function(e) { 
				prev_topic();
				return false;
				}
			);	
		handleEvent(
			prevTopic, 'mouseover', 
			function(e) { 
				hilightarrow('3',"left",true);
				}
			);	
		handleEvent(
			prevTopic, 'mouseout', 
			function(e) { 
				hilightarrow('3',"left",false);
				}
			);	
	//
	var nextTopic = $('nextTopic');
		handleEvent(
			nextTopic, 'click', 
			function(e) { 
				next_topic();
				return false;
				}
			);	
		handleEvent(
			nextTopic, 'mouseover', 
			function(e) { 
				hilightarrow('3',"right",true);
				}
			);	
		handleEvent(
			nextTopic, 'mouseout', 
			function(e) { 
				hilightarrow('3',"right",false);
				}
			);	
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function initializePortfolioNav() {
    // Retrieve the portfolio from the webpage
    Anthem_InvokePageMethod("GetPortfolio", [""], GetPortfolioCallback);
		/*var x = new xmlhttp();
			if (x.isEmpty()) {
				alert('failed to initialize xmlhttp object');
				return;
				}
		    x.onerror = function () {
			    ErrorMessage("initializePortfolioNav() xmlhttp error.\n" + 
				    this.m_xmlhttp.getAllResponseHeaders());
			    setBusy(false);
			    };
			x.oncomplete = function () {
				GetPortfolioCallback(this.m_xmlhttp.responseText);
				}
			x.head('xmlhttp/Portfolio.aspx');*/
}

function initializeSeriesNav() {
    // Retrieve the series from the webpage
    Anthem_InvokePageMethod("GetSeries", [""], GetPortfolioCallback);    
}

function initializePublicationsNav() {
    // Retrieve the portfolio from the webpage
    Anthem_InvokePageMethod("GetPublications", [""], GetPortfolioCallback);    
}

function GetPortfolioCallback(response) {
    // Process the portfolio
    //prompt("response",response.value);
    eval("portfolio = " + response.value);

	var container = $('portfolioTopics');
		clearContainer(container);
	var i, n; for (i = 0, n = portfolio.length; i < n; i++) {
		var a = document.createElement('A');
			a.href = '#' + i;
			a.id = 'portfolioNav' + i;
			a.onclick = handlePortfolioNav;
			a.className = "menuNormal" + " " + ((i > (nPORTFOLIO_TOPICS - 1)) ? 'invisible' : '');
		var t = document.createTextNode(portfolio[i].topic.replace(/ /gi,'\u00a0'));
			a.appendChild(t);
			container.appendChild(a);
			t = document.createTextNode(' ');
			container.appendChild(t);
		}
	var img = document.createElement('IMG');
		img.alt = '';
		img.src = './images/spacer.gif';
		img.width = '500';
		img.height = '1';
		img.border = '0';
	container.appendChild(img);
	container.style.visibility = 'visible';
	if (portfolio[currentPortfolioNav] && portfolio[currentPortfolioNav].images) {
	    portfolioDefault = portfolio[currentPortfolioNav].images;
	    } 
	else {
	    portfolioDefault = null;
	    }
    clearContainer($('thumbnails'));
	}
//------------------------------------------------------------------------------/	
//------------------------------------------------------------------------------/	
function initializePortfolioSubNav() {
    clearContainer($('thumbnails'));
    if (!portfolio[currentPortfolioNav].subtopics) {
        initializePortfolioImages();
        $('portfolioSubTopics').style.visibility = 'hidden';
        return;
    }
	var container = $('portfolioSubTopics');
		clearContainer(container);
	var i, n; for (i = 0, n = portfolio[currentPortfolioNav].subtopics.length; i < n; i++) {
		var a = document.createElement('A');
			a.href = '#' + i;
			a.id = 'portfolioSubNav' + i;
			a.onclick = handlePortfolioSubNav;
			a.className = "menuNormal";
		var t = document.createTextNode(portfolio[currentPortfolioNav].subtopics[i].topic);
			a.appendChild(t);
			container.appendChild(a);
			t = document.createTextNode(' ');
			container.appendChild(t);
		}
	var img = document.createElement('IMG');
		img.alt = '';
		img.src = './images/spacer.gif';
		img.width = '600';
		img.height = '1';
		img.border = '0';
	container.appendChild(img);
	container.style.visibility = 'visible';
	// activate the first sub-category
	if (container.firstChild.onclick)
	    container.firstChild.onclick();
	}
//------------------------------------------------------------------------------/	
// show the thumbnails of a given topic											/
//------------------------------------------------------------------------------/	
function initializePortfolioImages() {
	var prevPage = $('prevPage');
	var nextPage = $('nextPage');
	var container = $('thumbnails');
		clearContainer(container);
	var root;
	    if (portfolio[currentPortfolioNav].subtopics)
	        root = portfolio[currentPortfolioNav].subtopics[currentPortfolioSubNav];
	    else
	        root = portfolio[currentPortfolioNav];
	    if (root.text)
	        return showPublication();
	        
	var i, n = root.images.length;
		container.style.width = (n * 50) + "px";
	for (i = 0; i < n; i++) {
		var item = root.images[i];
		var a = document.createElement('A');
			a.href = '#' + i;
			a.className = (i > (nPORTFOLIO_THUMBNAILS - 1)) ? 'invisible' : 'visible';
			a.alt = item.desc;
			a.title = item.desc;
			a.onclick = showPhoto;
		var img = document.createElement("IMG");
			//img.src = './images2/tn/' + item.file;
			img.src = item.thumb;
			img.border = '0';
			img.alt = item.desc;
	    var hid = document.createElement('INPUT');
	        hid.type = 'hidden';
	        hid.id = 'portfolioImg' + i;
	        hid.value = item.file;

			a.appendChild(img);
			container.appendChild(a);
			container.appendChild(hid);
		}
	var indicator = document.createElement("DIV");
		indicator.id = 'currentPhoto';
		indicator.className = 'currentPhoto';
		container.appendChild(indicator);
    // show the pager arrows
    prevPage.style.display = '';
    nextPage.style.display = '';
	// show the first image
	if (container.firstChild.onclick)
	    container.firstChild.onclick();
	}
//------------------------------------------------------------------------------/	
// show the text and image of a given topic	    								/
//------------------------------------------------------------------------------/	
function showPublication() {
	var root;
	    if (portfolio[currentPortfolioNav].subtopics)
	        root = portfolio[currentPortfolioNav].subtopics[currentPortfolioSubNav];
	    else
	        root = portfolio[currentPortfolioNav];
    var img = "";
	        
	if (root.image) {
	    img = "<img src='" + root.image + "' class='publication' border='0' alt=''/>";
	}

    $('textscroll').innerHTML = img + root.text;
	}
//------------------------------------------------------------------------------/	
// show the default thumbnails after a click on 'Portfolio'						/
//------------------------------------------------------------------------------/	
function initializeDefaultThumbnails() {
	var prevPage = $('prevPage');
	var nextPage = $('nextPage');
	var container = $('thumbnails');
		clearContainer(container);
	if (portfolioDefault != null) {
	    var i, n = portfolioDefault.length;
		    container.style.width = (n * 50) + "px";
	    for (i = 0; i < n; i++) {
		    var item = portfolioDefault[i];
		    var a = document.createElement('A');
			    a.href = '#';
			    a.className = (i > (nPORTFOLIO_THUMBNAILS - 1)) ? 'invisible' : 'visible';
			    a.alt = item.desc;
			    a.title = item.desc;
			    a.onclick = showPhoto;
		    var img = document.createElement("IMG");
			    img.src = './images2/tn/' + item.file;
			    img.border = '0';
			    img.alt = item.desc;
			    a.appendChild(img);
			    container.appendChild(a);
		    }
	    var indicator = document.createElement("DIV");
		    indicator.id = 'currentPhoto';
		    indicator.className = 'currentPhoto';
		    container.appendChild(indicator);
	    // show the pager arrows
	    prevPage.style.display = '';
	    nextPage.style.display = '';
	    // show the first image
	    container.firstChild.onclick();
	}
	else {
	    prevPage.style.display = 'none';
	    nextPage.style.display = 'none';
	}    
}
//------------------------------------------------------------------------------/	
// show a photo after a click on it's thumbnail									/
//------------------------------------------------------------------------------/	
function showPhoto () {
	if ($('thumbnails').style.visibility != 'visible') {
		// thumbnails not visible (yet)
		return;
		}
	var i, n, e ; for (i = 0, n = this.parentNode.childNodes.length; i < n; i++) {
		e = this.parentNode.childNodes[i];
		if (e.className.indexOf('thumbFocus') >= 0) {
			e.className = 'visible';
			}
		if (e === this) {
			currentPortfolioPhoto = i;
			}
		}
	this.className = 'thumbFocus';
	var indicator = $('currentPhoto');
		indicator.style.left = (getAbsLeft(this) - getAbsLeft(this.parentNode)) + "px";
		indicator.style.display = 'block';
	var container = $('foto');
		clearContainer(container);
	var img = document.createElement('IMG');
		//img.src = this.firstChild.src.replace(/\/tn\//gi,"/");
		img.src = this.nextSibling.value;
		container.appendChild(img);
	var caption = $("caption");
		caption.innerHTML = this.title;
		caption.style.visibility = 'visible';
	$("foto").style.visibility = 'visible';
	$("cart").style.visibility = 'visible';
	$("hidSelectedPhoto").value = img.src;
	
	return false;
	}
//------------------------------------------------------------------------------/	
// handle portfolio sub-navigation												/
//------------------------------------------------------------------------------/	
function handlePortfolioSubNav() {
	if (focusNav(this.id)) {
		currentPortfolioSubNav = parseInt(this.href.substring(this.href.indexOf('#') + 1),0);
		initializePortfolioImages();
		}
	}
//------------------------------------------------------------------------------/	
// handle portfolio main navigation												/
//------------------------------------------------------------------------------/	
function handlePortfolioNav() {
	if (focusNav(this.id)) {
		currentPortfolioSubNav = null;
		currentPortfolioNav = parseInt(this.href.substring(this.href.indexOf('#') + 1),0);
		initializePortfolioSubNav();
		}
	}
//------------------------------------------------------------------------------/	
// handle content requests 														/
//------------------------------------------------------------------------------/	
function getContent(pageName) {
    // Retrieve the portfolio from the webpage
    Anthem_InvokePageMethod("GetContent", [pageName], GetContentCallback);    
}
function GetContentCallback(response) {
    $('textscroll').innerHTML = response.value;
	$("portfolioThumbnailArrows").style.visibility = 'hidden';
	$("portfolioTopicArrows").style.visibility = 'hidden';
	$("caption").style.visibility = 'hidden';
	$("thumbnails").style.visibility = 'hidden';
	$("portfolioTopics").style.visibility = 'hidden';
	$("portfolioSubTopics").style.visibility = 'hidden';
	$("foto").style.visibility = 'hidden';
	$("cart").style.visibility = 'hidden';
	$("iframe").style.visibility = 'hidden';
	$("textframe").style.display = 'block';
	$("orderform").style.display = 'none';
	$("contactform").style.display = 'none';
}
//------------------------------------------------------------------------------/	
// handle main navigation														/
//------------------------------------------------------------------------------/	
function handleNav (id) {
	if (focusNav(id)) {
		$("cart").style.visibility = 'hidden';

		switch (id) {
			case 'Portfolio':
				$("portfolioThumbnailArrows").style.visibility = 'visible';
				$("portfolioTopicArrows").style.visibility = 'visible';
				$("portfolioSubTopics").style.visibility = 'hidden';
				$("thumbnails").style.visibility = 'visible';
				$("caption").style.visibility = 'hidden';
				$("foto").style.visibility = 'visible';
				initializePortfolioNav();
				$("textframe").style.display = 'none';
				$("iframe").style.display = 'none';
				$("orderform").style.display = 'none';
				$("contactform").style.display = 'none';
				break;
			case 'Series':
				$("portfolioThumbnailArrows").style.visibility = 'visible';
				$("portfolioTopicArrows").style.visibility = 'visible';
				$("portfolioSubTopics").style.visibility = 'hidden';
				$("thumbnails").style.visibility = 'visible';
				$("caption").style.visibility = 'hidden';
				$("foto").style.visibility = 'visible';
				initializeSeriesNav();
				$("textframe").style.display = 'none';
				$("iframe").style.display = 'none';
				$("orderform").style.display = 'none';
				$("contactform").style.display = 'none';
				break;
			case 'Publicaties':
				$("portfolioThumbnailArrows").style.visibility = 'visible';
				$("portfolioTopicArrows").style.visibility = 'visible';
				$("portfolioSubTopics").style.visibility = 'hidden';
				$("thumbnails").style.visibility = 'visible';
				$("caption").style.visibility = 'hidden';
	            $("foto").style.visibility = 'hidden';
				initializePublicationsNav();
	            $("iframe").style.visibility = 'hidden';
	            $("textframe").style.display = 'block';
				$("orderform").style.display = 'none';
				$("contactform").style.display = 'none';
				break;
			case 'Gastenboek':
				$("portfolioThumbnailArrows").style.visibility = 'hidden';
				$("portfolioTopicArrows").style.visibility = 'hidden';
				$("caption").style.visibility = 'hidden';
				$("thumbnails").style.visibility = 'hidden';
				$("portfolioTopics").style.visibility = 'hidden';
				$("portfolioSubTopics").style.visibility = 'hidden';
				$("foto").style.visibility = 'hidden';
				$("textframe").style.display = 'none';
				$("iframe").style.display = 'block';
				$("orderform").style.display = 'none';
				$("contactform").style.display = 'none';
				$("iframe").style.display = 'block';
		        frames['gastenboek'].location.href = "http://defluiter.tboek.nl";
		        frames['gastenboek'].focus();
			    break;
			case 'Contact':
			    // Display contact form always as overlay
				$("orderform").style.display = 'none';
				$("contactform").style.display = 'block';
				$("txtContactName").focus();
			    break;
			default:			
			    getContent(id);
				/*var x = new xmlhttp();
					if (x.isEmpty()) {
						alert('failed to initialize xmlhttp object');
						return;
						}
					x.oncomplete = function () {
						$('textscroll').innerHTML = this.m_xmlhttp.responseText;
						};
					x.get("./stories/" + id + ".htm");*/
				break;
			}
		}
		
		return false;
	}
//------------------------------------------------------------------------------/	
// set focus on a clicked navigational item										/
//------------------------------------------------------------------------------/	
function focusNav (id) {
	var e = $(id);
	if (e.className && contains(e.className,'menuFocus')) {
		return false;
		}
	if (isEmpty(e) === false) {
		var i, n; for (i = 0, n = e.parentNode.childNodes.length; i < n; i++) {
			var node = e.parentNode.childNodes.item(i);
			if (node.className) {
				node.className = node.className.replace(/menuFocus/gi,"");
				node.className = node.className.replace(/menuNormal/gi,"");
				node.className = "menuNormal" + (node.className.length ? " " + node.className : "");
				}
			}
		e.className	= e.className.replace(/menuNormal/gi,"");
		e.className = 'menuFocus' + (e.className.length ? " " + e.className : "");
		}
	return true;
	}
//------------------------------------------------------------------------------/	
// attach event handlers on page-load											/
//------------------------------------------------------------------------------/	
handleEvent(
	window, 'load', 
	function() { 
		initialize(); 
		initializeDefaultThumbnails();
		colorize();
		showbody();
		}
	);	
handleEvent(
	window, 'resize',
	function() {
		showfluiter();
		}
	);
//------------------------------------------------------------------------------/	
// form validation                  											/
//------------------------------------------------------------------------------/	
function validateOrderForm() {
    if ($('txtOrderName').value == '') {
        alert("Vul eerst uw naam in!");
        $('txtOrderName').focus();
        return false;
    }
    if ($('txtOrderEmail').value == '') {
        alert("Vul eerst uw e-mail adres in!");
        $('txtOrderEmail').focus();
        return false;
    }
    
    return true;
}
//------------------------------------------------------------------------------/
function validateContactForm() {
    if ($('txtContactName').value == '') {
        alert("Vul eerst uw naam in!");
        $('txtContactName').focus();
        return false;
    }
    if ($('txtContactEmail').value == '') {
        alert("Vul eerst uw e-mail adres in!");
        $('txtContactEmail').focus();
        return false;
    }
     if ($('txtContactRemarks').value == '') {
        alert("Vul eerst uw vraag in!");
        $('txtContactRemarks').focus();
        return false;
    }
    
    return true;
}