
/*
	// standalone onDomReady function from http://www.ajaxprogrammer.com/
	window.onDomReady = function(fn){
		window.__ondom_functionArray.push(fn);
	};
	(function(){
		window.__ondom_functionArray = [];
		function _runFunctions(){
			for (var i in window.__ondom_functionArray){
				(window.__ondom_functionArray[i])();
			}
		};
		var _khtml = /(WebKit|khtml)/i.test(navigator.userAgent);
		if(document.addEventListener && !_khtml){
			document.addEventListener('DOMContentLoaded', _runFunctions, false);
		}else if(_khtml){
			var _timer = setInterval(function(){
				if(/loaded|complete/.test(document.readyState)){
					clearInterval(_timer);
					_runFunctions();
				}
			}, 10);
		}else{
			document.write('<script id=__ie_ondom defer src=javascript:void(0)><\/script>');
			var script = document.getElementById('__ie_ondom');
			script.onreadystatechange = function(){
				if(this.readyState == 'complete'){
					_runFunctions();
				}
			};
		}
	})();
*/

	// on dom ready
	onDomReady(function(){

		window.content = document.getElementById('tabContent');
		window.tabLinks = getElementsByClassName('tab', 'a', content);

		var tabLink;

		// make all tab links open the tab system
		for (var i = 0; tabLink = tabLinks[i]; i++)
		{
			addEvent(tabLink, 'click', materializeTabSystem);
		}
	
	});


	// create the tab system if it does not already exists
	function materializeTabSystem(e)
	{
		if (!window.tabSystem)
		{
			tabSystem = document.createElement('div');
			tabSystem.id = 'tabSystem';
			tabsContainer = document.createElement('div');
			tabsContainer.id = 'tabs';
			tabPage = document.createElement('div');
			tabPage.id = 'tabPage';
			originalContent = document.createElement('div');
			if (!/msie|MSIE 6/.test(navigator.userAgent)) originalContent.style.height = '100%'; // else IE6 hang when returning to the original content

			tabs = [];
			tabTargets = [];
			var tab, tabTarget;
			// first tab
			tab = document.createElement('a');
			tab.href = '';
			tab.innerHTML = 'menu';
			addEvent(tab, 'click', showTabPage);
			originalContent.style.display = 'none';
			tab.index = 0;
			tabTargets.push(originalContent);
			tabs.push(tabsContainer.appendChild(tab));
			// tab for links
			var tabLinkContainer, tabLinkGroupName;
			for (var i = 0; tabLink = tabLinks[i]; i++)
			{
				tab = document.createElement('a');
				tab.href = '';
				tabLinkContainer = tabLink.parentNode.parentNode.parentNode;
				if (tabLinkContainer.tagName == 'DIV')
				{
					tabLinkGroupName = getPreviousElement(tabLinkContainer, 'div').innerHTML.replace(/(<\/?)(\w+)([^>]*>)/g, '');
					if (tabLinkGroupName == 'Zaalindeling' || tabLinkGroupName == 'Dienstlijsten') tab.innerHTML = tabLinkGroupName;
					else tab.innerHTML = tabLinkGroupName + ' ' + tabLink.innerHTML.substr(0, 2) + '.';
				}
				else
				{
					tab.innerHTML = tabLink.innerHTML;
				}
				tab.link = tabLink;
				if (tabLink == this) addClassName(tab, 'active');
				addEvent(tab, 'click', showTabPage);

				tabTarget = document.createElement('iframe');
//				if (tabLink == this) 
tabTarget.src = tabLink.href;
				tabTarget.style.width = tabTarget.style.height = '100%';
				tabTarget.style.display = 'none';
				tabTarget.frameBorder = '0';
				tabLink.index = tab.index = i + 1;
				tabTargets.push(tabPage.appendChild(tabTarget));

				tabs.push(tabsContainer.appendChild(tab));

				removeEvent(tabLink, 'click', materializeTabSystem);
				addEvent(tabLink, 'click', showTabPage);
			}
			tabSystem.appendChild(tabsContainer);
			tabPage.appendChild(originalContent);
			tabSystem.appendChild(tabPage);
			content.parentNode.insertBefore(tabSystem, content);
			originalContent.appendChild(content);

			addClassName(tabs[this.index], 'active');
			tabTargets[this.index].style.display = 'block';

			if (!/msie|MSIE 6/.test(navigator.userAgent)) // else IE6 hang when returning to the original content
			{
				setTabSystemSize();
				addEvent(window, 'resize', setTabSystemSize);
			}
		}

		// preventing the propagation of events
		if (!e) e = window.event;
		if(e.preventDefault) e.preventDefault();
		else e.returnValue = false;
	}


	// show tab page of clicked link
	function showTabPage(e)
	{
		this.blur();

		var tab;
		for (var i = 0; tab = tabs[i]; i++)
		{
			removeClassName(tab, 'active');
			tabTargets[i].style.display = 'none';
		}

		addClassName(tabs[this.index], 'active');
		tabTargets[this.index].style.display = 'block';

/*
		iFrameDocument = (tabTargets[this.index].contentWindow.document ? tabTargets[this.index].contentWindow.document : tabTargets[this.index].document);
//		iFrameDocument.write =  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl"><head></head><body><embed src="' + tabs[this.index].link.href + '" width="500" height="650"></embed></body></html>';
		iFrameDocument.getElementsByTagName('body')[0].style.margin = '0px';
		iFrameDocument.getElementsByTagName('body')[0].innerHTML =  '<embed src="' + tabs[this.index].link.href + '" width="100%" height="100%"></embed>';
//		iFrameDocument.getElementsByTagName('body')[0].innerHTML =  '<object type="application/pdf" data="' + tabs[this.index].link.href + '" width="100%" height="100%" ></object>';
*/

		// preventing the propagation of events
		if (!e) e = window.event;
		if(e.preventDefault) e.preventDefault();
		else e.returnValue = false;
	}


	function setTabSystemSize()
	{
		tabSystem.style.width = '0px';
		tabSystem.style.height = '0px';
		tabSystem.style.overflow = 'hidden';

		var viewportSize = getViewportSize();

		tabSystem.style.overflow = 'visible';
		tabSystem.style.width = viewportSize.x + 'px';
		tabSystem.style.height = (viewportSize.y - (/msie|MSIE 6/.test(navigator.userAgent) ? 2 : 0)) + 'px';
		tabPage.style.width = (viewportSize.x - 2) + 'px'; // static decrement with border width
		tabPage.style.height = (viewportSize.y - getElementSize(tabsContainer).y - (/msie|MSIE 6/.test(navigator.userAgent) ? 2 : 0) - 2) + 'px'; // static decrement with border width
	}




	/* common functions */


	// standalone getElementsByClassName function from http://www.robertnyman.com/index.php?p=256
	function getElementsByClassName(className, tagName, parent)
	{
		var
			testClass = new RegExp("(^|\\s)" + className + "(\\s|$)"),
			tagName = tagName || '*', parent = parent || document,
			elements = (tagName == '*' && parent.all)? parent.all : parent.getElementsByTagName(tagName),
			returnElements = [], current, length = elements.length;

		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}

		return returnElements;
	}


	// get parent element with optionally specific tagName
	function getParent(element, tagName)
	{
		var parent = element.parentNode;

		if (!tagName) return parent;

		while(parent.tagName && (parent.tagName.toLowerCase() != tagName.toLowerCase())) parent = parent.parentNode;

		return parent;
	}


	// get previous element, optionally of specfic tagName
	function getPreviousElement(element, tagName)
	{
		while(element.previousSibling)
		{
			if (element.previousSibling.nodeType == 1 && (!tagName || element.previousSibling.tagName.toLowerCase() == tagName))
			{
				return element.previousSibling;
			}
			element = element.previousSibling;
		}

		return false;
	}


	// check whether an element has a specific class
	function hasClassName(element, name)
	{
		var i, list = element.className.split(" ");

		for(i = 0; i < list.length; i++)
			if(list[i] == name)
				return true;

		return false;
	}


	// adds a className to an element
	function addClassName(element, className)
	{
		removeClassName (element, className);
		element.className = (element.className + ' ' + className).replace(/^\s+|\s+$/g, '');
	}


	// removes a className from an element
	function removeClassName(element, className)
	{
		element.className = element.className.replace(className, '').replace(/^\s+|\s+$/g, '');
	}


	// better addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	function addEvent(element, type, fn)
	{
		if (element.addEventListener)
		{
			element.addEventListener(type, fn, false);
		}
		else if (element.attachEvent)
		{
			element['e' + type + fn] = fn;
			element[type + fn] = function() {
				element['e' + type + fn](window.event);
			};
			element.attachEvent('on' + type, element[type + fn]);
		}
	}


	// better removeEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	function removeEvent(element, type, fn)
	{
		if (element.removeEventListener)
		{
			element.removeEventListener(type, fn, false);
		}
		else if (element.detachEvent)
		{
			element.detachEvent('on' + type, element[type + fn]);
			element[type + fn] = null;
			element['e' + type + fn] = null;
		}
	}


	// get an element's size
	function getElementSize(element)
	{
		return {x: element.offsetWidth, y: element.offsetHeight};
	}


	// set of functions to get the viewport's width or height or both
	compatMode = document.compatMode;
	userAgent = navigator.userAgent.toLowerCase();
	isOpera = (userAgent.indexOf('opera') > -1);
	isIE = (!isOpera && userAgent.indexOf('msie') > -1);
	function getViewportSize()
	{
		return {x: getViewportWidth(), y: getViewportHeight()};
	}
	function getViewportWidth()
	{
		var width = window.innerWidth;

		if(compatMode || isIE)
		{
			width = (compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth;
		}

		return width;
	}
	function getViewportHeight()
	{
		var height = window.innerHeight;

		if ((compatMode || isIE) && !isOpera)
		{
			height = (compatMode == 'CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight);
		}

		return height;
	}

