function getElementsByClassName(class_name) {
  var all_obj,ret_obj=new Array(),j=0,teststr;
  if(document.all)all_obj=document.all;
  else if(document.getElementsByTagName && !document.all)
    all_obj=document.getElementsByTagName("*");

  for(var i=0;i<all_obj.length;i++)
  {
    if(all_obj[i].className.indexOf(class_name)!=-1)
    {
      teststr=","+all_obj[i].className.split(" ").join(",")+",";
      if(teststr.indexOf(","+class_name+",")!=-1)
      {
        ret_obj[j]=all_obj[i];
        j++;
      }
    }
  }
  return ret_obj;
}
function setPadding(className) {
	var elements = getElementsByClassName(className);
	for (var i=0;i<elements.length;i++) {
		var childHeight = elements[i].childNodes[0].offsetHeight;
		var parentHeight = elements[i].parentNode.offsetHeight;
		if (parentHeight >= childHeight) {
                        elements[i].style.height = childHeight+'px';
			elements[i].style.overflow = 'hidden';
			var marginTop = (parentHeight - childHeight)/2;
			elements[i].style.marginTop = marginTop+'px';
		}
	}
}

//window.onload = function (e) {
function klapMenu() {
    var mainMenu = document.getElementById('menu').childNodes;
    for(var i = 0; i < mainMenu.length; i++) {
		if(mainMenu[i].nodeName == "UL") {
            mainMenuItems = mainMenu[i].childNodes;
            for (var i = 0; i < mainMenuItems.length; i++) {
                if(mainMenuItems[i].nodeName == "LI") {
                    Submenu = mainMenuItems[i].childNodes;
                    for (var i = 0; i < Submenu.length; i++) {
                        if(Submenu[i].nodeName == "UL") {
                            SubmenuItems = Submenu[i].childNodes;
                            for (var i = 0; i < SubmenuItems.length; i++) {
                                if(SubmenuItems[i].nodeName == "LI") {
                                    SubmenuItems[i].onmouseover = function() { showSubmenu(this); }
                                    SubmenuItems[i].onmouseout = function() { hideSubmenu(this); }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

addTalmonLoadEvent(klapMenu);

function showSubmenu(element) {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
        var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
    } else {
        //
    }
    childArray = element.childNodes;
	for (var i = 0; i < childArray.length; i++) {
		if(childArray[i].nodeName == "UL") {
            var newLiWidth = margin = '';
			
			// oplossing voor het uitlijnen van het submenu in IE, 8 werkt normaal
            if (ieversion<8) {
				childArray[i].style.marginLeft = '-' + element.offsetWidth + 'px';
            }
			
			// oplossing voor breedte in submenu ie7
			childArray[i].style.minWidth = element.offsetWidth+'px';
            if(ieversion == 7) {
				childArray[i].style.minWidth = element.offsetWidth + 70 + 'px';
			} 
			
            childArray[i].style.display = "block";
            if (typeof document.body.style.minWidth == "undefined") { // compensate minwidht for ie6
                if (element.offsetWidth > childArray[i].offsetWidth) {
                    childArray[i].style.width = element.offsetWidth+'px';
                }
            }
			// het hele overmenu is bedoeld voor het laatste submenu
            var overMenu = (childArray[i].offsetLeft + childArray[i].offsetWidth) - document.getElementById('menu').offsetWidth;
            if (overMenu > 0 ) {
                if (ieversion > '') {
                    if (ieversion>=6) margin = (parseInt(childArray[i].style.marginLeft) - overMenu + 24);
                    if (ieversion>=7) margin = (parseInt(childArray[i].style.marginLeft) - overMenu - 4);
                }
                else margin = -(overMenu+22);
                childArray[i].style.marginLeft = margin + 'px';
            }
		}
	}
}
function hideSubmenu(element) {
	childArray = element.childNodes;
	for (var i = 0; i < childArray.length; i++) {
		if(childArray[i].nodeName == "UL") {
			childArray[i].style.display = "none";
		}
	}
}

function LightboxContentImages() {
    var eContent = document.getElementById('cms_content');
    var aImages = eContent.getElementsByTagName('img');
    for (nI=0; nI<aImages.length; nI++) {
        if ( aImages[nI].className != 'nolightbox' ) {
            
            var reg = new RegExp("imageblob_id=([0-9]+)");
            aImageblob = reg.exec(aImages[nI].src);
            if ( aImageblob != null && isArray(aImageblob) ) {
                nId = aImageblob[1];
                
                imgLink = document.createElement('a');
                imgLink.rel = 'lightbox';
                imgLink.href = 'inc/3p/lightbox/imagefullsize.php?imageblob_id=' + nId;
                imgLink.title = aImages[nI].alt;
                newImg = document.createElement('img');
                newImg.src = aImages[nI].src;
                newImg.width = aImages[nI].width;
                newImg.height = aImages[nI].height;
                newImg.alt = aImages[nI].alt;
                newImg.title = aImages[nI].title;
                newImg.alt = aImages[nI].alt;
                
                imgLink.appendChild(newImg);
                
                aImages[nI].parentNode.replaceChild(imgLink, aImages[nI]);
            }
        }
    }
}
addTalmonLoadEvent(LightboxContentImages);	// content images popupen

function getViewport(which) {
    var viewportwidth;
    var viewportheight;
    
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    
    if (typeof window.innerWidth != 'undefined')
    {
        viewportwidth = window.innerWidth,
        viewportheight = window.innerHeight
    }
    
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    
    else if (typeof document.documentElement != 'undefined'
        && typeof document.documentElement.clientWidth !=
    'undefined' && document.documentElement.clientWidth != 0)
    {
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
    }
    
    // older versions of IE
    
    else
    {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    switch(which) {
    case 'height':
        return viewportheight;
        break;
    case 'width':
        return viewportwidth;
        break;
    }
}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addTalmonLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

//chk if an object is an array or not.
function isArray(obj) {
    //returns true is it is an array
    if (obj.constructor.toString().indexOf("Array") == -1)
        return false;
    else
        return true;
}

/*
function checkImg(sId) {
    theImg = document.getElementById(sId);
    if(theImg.complete==true) {
        clearInterval(img_timer);
        setTimeout('', 3000);
        nMaxWidth = 640;
        nMaxHeight = 480;
        
        nHeight = theImg.offsetHeight;
        nWidth = theImg.offsetWidth;
        if (nHeight > nMaxHeight || nWidth > nMaxWidth) {
            if (nHeight > nMaxHeight) {
                //nHeight = nMaxHeight;
                nWidth = ( (nMaxHeight / nHeight) * nWidth) ;
                nHeight = nMaxHeight;
            }
            if (nWidth > nMaxWidth) {
                nHeight = ( (nMaxWidth / nWidth) * nHeight) ;
                nWidth = nMaxWidth;
            }
        }
        theImg.style.width = nWidth;         
        theImg.style.height = nHeight;
        theImg.width = nWidth;         
        theImg.height = nHeight;
        var theDiv = document.getElementById('fotoDiv');
        theDiv.style.top = Math.round( ( getViewport('height') / 2 ) - ( nHeight / 2 ) ) + 'px';
        theDiv.style.marginLeft = Math.round( ( document.getElementById('main').offsetWidth / 2 ) - ( nWidth / 2 ) ) + 'px';
        theDiv.style.width = nWidth;
        theDiv.style.height = nHeight;
        theDiv.style.visibility = 'visible';

    }
}
function showContentFotoDiv(e) {
    //e.src
    var reg = new RegExp("imageblob_id=([0-9]+)");
    aImageblob = reg.exec(e.src);
    nId = aImageblob[1];
    toggleWaas();
    
    var theImg = document.getElementById('popupFoto');
    theImg.src = 'imagefullsize.php?imageblob_id=' + nId;
    
    img_timer = setInterval('checkImg(\''+ theImg.id +'\')', 250);
}
function showFotoDiv(nId, nWidth, nHeight) {
    // Waasje over de hele site heen
    toggleWaas();
    
    var theImg = document.getElementById('popupFoto');
    theImg.src = 'image.php?imageblob_id=' + nId;
    
    var theDiv = document.getElementById('fotoDiv');
    theDiv.style.top = Math.round( ( getViewport('height') / 2 ) - ( nHeight / 2 ) ) + 'px';
    theDiv.style.marginLeft = Math.round( ( document.getElementById('main').offsetWidth / 2 ) - ( nWidth / 2 ) ) + 'px';
    theDiv.style.width = nWidth;
    theDiv.style.height = nHeight;
    theDiv.style.visibility = 'visible';
}
function hideFotoDiv(eId) {
    var theDiv = document.getElementById('fotoDiv');
    theDiv.style.visibility = 'hidden';
    toggleWaas();
}
function toggleWaas() {
    var theWaas = document.getElementById('hook_2');
    if (theWaas.style.display == 'block') {
        theWaas.style.display = 'none';
    }
    else {
        if (document.getElementById('main').offsetWidth > getViewport('width')) {
            theWaas.style.width = document.getElementById('main').offsetWidth;
        } else {
            theWaas.style.width = getViewport('width') + 'px';
        }
        if (document.getElementById('main').offsetHeight > getViewport('height')) {
            theWaas.style.height = document.getElementById('main').offsetHeight;
        } else {
            theWaas.style.height = getViewport('height') + 'px';
        }
        theWaas.style.display = 'block';
    }
}
*/
