/*
  general functions
*/
var aPopups = new Array();
var aModalPopups = new Array();

window.onfocus = function()
{
	if(aModalPopups.length != 0)
	{
		aModalPopups[0].focus();
	}
}


var sDefaultFeatures = 'channelmode=0, fullscreen=0, location=0, menubar=0, resizable=0, scrollbars=0, status=0, titlebar=0, toolbar=0';

// create popup
function createPopup(sURL, name, sFeatures, iWidth, iHeight){
	var iLeft	= (screen.availWidth - iWidth) / 2;
	var iTop	= (screen.availHeight - iHeight) / 2;
	
	return window.open(sURL, name, sFeatures + ', width=' + iWidth + ', height=' + iHeight + ', left=' + iLeft + ', top=' + iTop);
}


// getcookie
function getCookie(name){
	var aCookie = document.cookie.split("; ");
	
	for (var i=0; i < aCookie.length; i++){
		var aCrumb = aCookie[i].split("=");
		if (name == aCrumb[0]){
			return unescape(aCrumb[1]);
		}
	}
	
	return null;
} /*
  getElementsByClassName	
*/
document.getElementsByClassName = function (needle){
    var s = [document.documentElement || document.body], i = 0, r = [], l = 0, e;
    var re = new RegExp('(^|\\s)' + needle + '(\\s|$)');

    do{
        e = s[i];

        while (e){
            if (e.nodeType == 1){
                if (e.className && re.test(e.className)) r[l++] = e;

                s[i++] = e.firstChild;
            }

            e = e.nextSibling;
        }
    }
	
    while (i--);

    return r;
} /*
  handleBodyLoad
*/
function handleBodyLoad(){
  markLinks();
  initExamples();
  initPopupPainting();
  initShadowOverlay();
} function initExamples(){
  var examplesDivs = document.getElementsByClassName('examples');

  for (var j=0; j < examplesDivs.length; j++){
    var thumbs = examplesDivs[j].getElementsByTagName('img');

    for (var i=0; i < thumbs.length; i++){
      var thumbn = thumbs[i];

      thumbn.onmouseover= function() {
         this.src =this.src.replace('tn','tn140');
         this.style.display = 'block';
         this.style.width = '140px';
         this.style.height='140px';
         this.style.position='absolute';
         this.style.left='-35px';
         this.style.top='-35px';
         this.parentNode.style.zIndex='6';
         this.style.border='2px white solid';
         this.style.backgroundColor= '#777777';
     };
   thumbn.onmouseout= function() {
this.src =this.src.replace('tn140','tn');
        this.style.display = 'block';
        this.style.width = '76px';
        this.style.height='76px';
        this.style.position='relative';
        this.style.left='0';
        this.style.top='0';
        this.parentNode.style.zIndex='1';
        this.style.border='none';
      };
   }
  }
} /*
   mark links
*/
function markLinks(){
	var links = document.getElementsByTagName('a');
	var link, href, mark;
	
	for(var i = 0; i < links.length; i++){
		link = links[i];
		
			
		switch(link.getAttribute('rel')){
			case 'ext': case 'external':
				link.className += ' external';
				link.target = '_blank';
				
				
				if(link.getElementsByTagName('img').length == 0){
					href = link.getAttribute('href').toLowerCase();
					href = href.substring((href.length - 4), (href.length));
					switch(href){
						case '.pdf':
							link.className += ' pdf';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/pdf.png';
							link.insertBefore(mark , (link.firstChild));
							break;
						
						case '.xls':
							link.className += ' pdf';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/xls.png';
							link.insertBefore(mark , (link.firstChild));
							break;
							
						case '.doc':
							link.className += ' pdf';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/doc.png';
							link.insertBefore(mark , (link.firstChild));
							break;
							
						case '.ppt':
							link.className += ' pdf';
							mark = document.createElement('img');
							mark.src = '/data/link-icons/ppt.png';
							link.insertBefore(mark , (link.firstChild));
							break;
							
						default:
							mark = document.createElement('img');
							mark.src = '/data/link-icons/external.png';
							link.appendChild(mark);
							break;
				}
			}
		}
	}
	
	links = document.getElementsByTagName('a');
	
	for(var i = 0; i < links.length; i++){
		if(links[i].getAttribute('href')){
			href = document.createElement('span');
				href.className = 'print';
				href.appendChild((document.createTextNode(' [' + links[i].href + ']')));
			
			links[i].appendChild(href);
		}
	}
	
	mark = null;
	href = null;
	link = null;
	links = null;
} /*
  popupPainting
*/

function createPopupPainting(src){
	var popup;
	var popupHeader;
	
	// remove old wrapper
	if(document.getElementById('popup')){
		document.getElementById('popup').parentNode.removeChild(document.getElementById('popup'));
	}
	
	// popup div
	popup = document.createElement('div');
	popup.id = 'popup';
	popup.style.display = 'none';

	// header div
	var popupHeader = document.createElement('div');
	popupHeader.id = 'popupHeader';
	
	// close link
	var popupCloseLink = document.createElement('a');
	popupCloseLink.innerHTML = '<em>Sluiten</em>';
	popupCloseLink.href = '#';
	popupCloseLink.onclick = function(){
		switchShadowOverlay('off');
		document.getElementById('popup').parentNode.removeChild(document.getElementById('popup')); 
		return false; 
	}
	
	// append all
	popup.appendChild(popupHeader);
	popupHeader.appendChild(popupCloseLink);
	document.body.appendChild(popup);

	// popup image big
	var popupImage = document.createElement('img'); 
	popupImage.onload = function(){
		document.getElementById('popup').style.marginLeft = this.width/-2+'px';
		
		if(this.height > 580){
			document.getElementById('popup').style.top = 70+'px';
		} else {
			document.getElementById('popup').style.top = '50%';
			document.getElementById('popup').style.marginTop = this.height/-2+'px';
		}

		document.getElementById('popupHeader').style.width = this.width+'px';
	}
	popupImage.src = unescape(src); 
	popupImage.id = 'popupImageBig';
	popup.appendChild(popupImage);

	popup.style.display = 'block';

}
		
function initPopupPainting(){
	
	var listItemArrays = [];
	
	if(document.getElementsByClassName('contentGallery').length) {
		listItemArrays[listItemArrays.length] = document.getElementsByClassName('contentGallery')[0].getElementsByTagName('li');
	}
	
	if(document.getElementById('examplesTop')) {
		listItemArrays[listItemArrays.length] = document.getElementById('examplesTop').getElementsByTagName('li');
	}

	
	if(document.getElementById('examplesLeft')) {
		listItemArrays[listItemArrays.length] = document.getElementById('examplesLeft').getElementsByTagName('li');
	}
	
	if(document.getElementById('examplesBottom')) {
		listItemArrays[listItemArrays.length] = document.getElementById('examplesBottom').getElementsByTagName('li');
	}
	
	// for every list item, get anchor and specifiy the onclick event to be createpopup (a.src) 
	
	for (var j=0; j < listItemArrays.length; j++) {
		for(var i=0; i<listItemArrays[j].length; i++) {
			listItemArrays[j][i].getElementsByTagName('a')[0].onclick = function(){ 
				switchShadowOverlay('on');
				createPopupPainting(this.href);
				return false;
			}
		}
	}
}
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function switchShadowOverlay(onoff) {
var objOverlay = document.getElementById('overlay');
	var arrayPageSize =getPageSize(); 
	switch(onoff) {
		case 'on':
			objOverlay.style.height = (arrayPageSize[1] + 'px');
			objOverlay.style.display = 'block';
			break;
		default:
			objOverlay.style.display = 'none';	
	}
}

function initShadowOverlay() {
var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {
		if(document.getElementById('popup')){
			document.getElementById('popup').parentNode.removeChild(document.getElementById('popup')); 
		}
		switchShadowOverlay('off');
		return false;
	}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
}

function initThumbnails() {
}

