var toggleSubMenu = function  (nr, el, fast) {
//	el = false;
	fast = fast || false;
	
	var item = document.getElementById('submenu_'+nr);

	if (toggleSubMenu.intervalOut || toggleSubMenu.intervalIn ) {
		return false;
	}
	
	if (fast) {
		
		toggleSubMenu.activeSub = nr;
		
		item.style.display = 'block';
		
		if (!item.maxWidth ) {
			item.maxWidth = item.scrollWidth;
		}
		return true;
	}
	
	if (toggleSubMenu.activeSub && nr!=toggleSubMenu.activeSub ) {
		document.getElementById('sep_' + toggleSubMenu.activeSub).style.display = 'block';
		var tmpS = document.getElementById('submenu_'+toggleSubMenu.activeSub)
		tmpS.style.overflow = 'hidden';
			
			toggleSubMenu.intervalIn2 = window.setInterval (function () {
				if (tmpS.offsetWidth <= 50) {
					window.clearInterval (toggleSubMenu.intervalIn2);
					toggleSubMenu.intervalIn = false;
					
					tmpS.style.display = 'none';
					toggleSubMenu.maxWidth = false;
					tmpS.style.fontWeight = 'normal';
					
				} else {
					submenu.style.overflow = 'hidden';
					submenu.style.textAlign = 'left';
					tmpS.style.width = (tmpS.offsetWidth - 8) + 'px'
				}
				},2);

	}
		
	if (item) {
		var submenu = item;
		if (item.style.display == 'none') {
			// fold out
			submenu.style.display = 'block';
			
			if (!submenu.maxWidth ) {
				submenu.maxWidth = submenu.scrollWidth;
			}
			
			submenu.style.width = '10px';

			toggleSubMenu.intervalOut = window.setInterval (function () {

				if (submenu.offsetWidth >= (submenu.maxWidth) || submenu.offsetWidth ==0 ) {
					window.clearInterval (toggleSubMenu.intervalOut);
					document.getElementById('sep_'+nr).style.display = 'none';
					submenu.style.overflow = 'auto';
					submenu.style.width = (submenu.maxWidth+10) + "px";
					
					toggleSubMenu.activeSub = nr;
					toggleSubMenu.activeEl = submenu;
					toggleSubMenu.intervalOut = false;
				} else {
					submenu.style.overflow = 'hidden';
					submenu.style.textAlign = 'left';
					submenu.style.width = (submenu.offsetWidth + 8) + 'px'
				}
			}, 2);
			
			document.getElementById('sep_'+nr).style.display = 'none';
			if (el)
				el.style.fontWeight = 'bold';
		} else {
			
			// fold in
			submenu.style.overflow = 'hidden';
			
			toggleSubMenu.intervalIn = window.setInterval (function () {
				if (submenu.offsetWidth <= 50) {
					window.clearInterval (toggleSubMenu.intervalIn);
					toggleSubMenu.intervalIn = false;
					document.getElementById('sep_'+nr).style.display = 'block';
					submenu.style.display = 'none';
					toggleSubMenu.maxWidth = false;
					submenu.style.fontWeight = 'normal';
					toggleSubMenu.activeSub = false;
					toggleSubMenu.activeEl = false;
				} else {
					submenu.style.overflow = 'hidden';
					submenu.style.textAlign = 'left';
					submenu.style.width = (submenu.offsetWidth - 8) + 'px'
				}
			}, 2);
	
		}
	}
}

function toggleProjecten(id) {
	obj = document.getElementById('more'+id);
	hyperlink = document.getElementById('link'+id);
	if (obj) {
		if (obj.style.display == 'block') {
			hyperlink.innerHTML = 'meer...';
			obj.style.display = 'none';
		} else {
			obj.style.display = 'block';
			hyperlink.innerHTML = '&laquo; inklappen';
		}
	}
}

function toon_na_video(obj,type) {
	if (obj.src) {
		if (type == 'small') {
			obj.src = '/images/notavailable/na_video_small.gif';
			obj.style.width = '260px';
			obj.style.height = '153px';
		} else {
			obj.src = '/images/notavailable/na_video.gif';
			obj.style.width = '300px';
			obj.style.height = '275px';
		}
	}
}

function toon_afbeelding_big(obj) {
	var randomnummer = Math.round( Math.random() * 17);
	obj.src = '/images/notavailable/not_available'+randomnummer+'.jpg';
}

//popup voor modules binnen admin
try {
	top.window.popupProjectmodule = function () {
		popupModules('projecten');
	}
} catch(e) {}

function popupModules(modulenaam) {
	var filename="/admin/modules/"+modulenaam+"/index.php";
	var fileid="Activiteiten";
	var width="800";
	var height="580";
	var scrollbars="no";
	var resizable="yes";
	var menubar="no";
	var toolbar="no";
	var status="no";
	var location="no";
	var popupscherm=0;
	var args = "height=" + height + ", width=" + width + ", scrollbars=" + scrollbars + ", resizable=" + resizable +  ", menubar=" + menubar + ", toolbar=" +toolbar + ", status=" + status + " ,location=" + location;
	popupscherm = top.window.open(filename, fileid, args);
}

//benodigde functie voor foto overzichts bouwsteen
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var popupscherm=0;

function popup_afbeelding(filename, fileid, width, height, scrollbars, resizable, menubar, toolbar, status, location) {
	if (popupscherm && ! popupscherm.closed)	popupscherm.close();
	if (!filename || filename=="")				filename="http://www.grundel.nl";
	if (!fileid || fileid=="")					fileid="Grundel";
	if (!width || width=="")					width="50";
	if (!height || height=="")					height="50";
	if (!scrollbars || scrollbars=="")			scrollbars="no";
	if (!resizable || resizable=="")			resizable="no";
	if (!menubar || menubar=="")				menubar="no";
	if (!toolbar || toolbar=="")				toolbar="no";
	if (!status || status=="")					status="no";
	if (!location || location=="")				location="no";
	popupscherm=0;
	var args = "height=" + height + ", width=" + width + ", scrollbars=" + scrollbars + ", resizable=" + resizable +  ", menubar=" + menubar + ", toolbar=" +toolbar + ", status=" + status + " ,location=" + location;
	popupscherm = open(filename, fileid, args);
	if (!InternetExplorer) 						popupscherm.focus();
}

//hoogte browser
	var isNav6;
	var isBrand = navigator.appName;
	var navVer = parseInt(navigator.appVersion);
	var isNav6 = (isBrand == "Netscape" && navVer >= 5) ? true : false

function getInsideWindowHeight() {
	if (isNav6)
		return window.innerHeight
 	else 
	    return document.body.clientHeight
}

//this function will get the current/computed style in IE and Moz/FF
function getStyle(obj,Attribute) {
	if (obj.currentStyle) //if IE
		var value = eval('obj.currentStyle.'+Attribute)
	else //if Mozilla or FF
		var value = eval('document.defaultView.getComputedStyle(obj, null).'+Attribute)
	return parseInt(value);
}

//zet hoogtes van verschilldende divjes goed
function setHeights(template) {
	schermhoogte = getInsideWindowHeight();
	var mainsite = document.getElementById('mainsite');
	var maintable = document.getElementById('divMaintable');
	if (!maintable)
		var maintable = document.getElementById('scrollcontainer');
		
	if (mainsite && maintable) {
		if ((maintable.offsetHeight + getStyle(maintable,'top')) < schermhoogte)
			mainsite.style.height = schermhoogte;
		else
			mainsite.style.height = getStyle(maintable,'top') + maintable.offsetHeight;
	}
}


	/**
	 * function for calculating a CSS property
	 * thanks to jquery.js for the example
	 * @param el object -  the HTML DOMobject
	 * @param prop string - the desired cdd property
	 * computeStyle (document.getElementById('a'), 'padding-left');
	 * computeStyle (document.getElementById('a'), 'width');
	 * computeStyle (document.getElementById('a'), 'backgroundColor');
	 * computeStyle (document.getElementById('a'), 'background-color');
	 * @return the property value of false;
	 */
	function getCSSStyle (el, prop) {
		if (document.defaultView && document.defaultView.getComputedStyle) {
			
			prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
			var cur = document.defaultView.getComputedStyle(el, null);
			return cur.getPropertyValue(prop) || false;
			
		} else if (el.currentStyle) {
				
				var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
				return el.currentStyle[prop] || el.currentStyle[newProp] || false;
				
		} else 
			return false;
	}
	
window.onresize = setHeights;
