//Globale functies t.b.v. de weergave van de website e.d.

window.status="Gereedschapmakerij De Vink bv";

var Breedte = 0;
var Hoogte = 0;
var nSearchLayerWidth = 0;
var nSearchLayerHeight = 0;
var pathLevel = new Array();
var pathUrl = new Array();
pathLevel[0] = "";	//Toplevel menu naam
pathUrl[0]   = "";	//Toplevel menu url
pathLevel[1] = "";	//Main level menu naam
pathUrl[1]   = "";	//Main level menu url
pathLevel[2] = "";	//Sublevel menu naam
pathUrl[2] 	 = "";	//Sublevel menu url

var iLayerWidth = 0;
//var headImagePath = "../images/header/"; 			//Deze wordt in de index.php ingesteld!!!
var iInterval = "";
var headImages = new Array();
var iMaxHeadImages = 10;
for (i=0; i<10; i++) { headImages[i] = 'headimage' + (i+1) + '.jpg'; }

// Head image instellen middels een random nummer		
function setHeadImage(){
	nRandom = (randomnumber=Math.floor(Math.random()*iMaxHeadImages) + 1);
	document.getElementById('subMenuArea2').style.backgroundImage = 'url(' + headImagePath + headImages[nRandom - 1] + ')';
	}

// Layers op juiste hoogte instellen na resizen van window
function setSize(){
	getScreenDimensions();
	var Hoogte2 = Hoogte - 223; //header - footer
	document.getElementById("main").style.height = Hoogte2 +"px";					
	
	var Hoogte1 = Hoogte - 273;
	document.getElementById("mainwrapper").style.height = Hoogte1 +"px";					
}		

//Venster dimensies ophalen
function getScreenDimensions() {
	if (self.innerWidth){
		Breedte = self.innerWidth;
		Hoogte = self.innerHeight;
	}
	else if (document.documentElement) {
		if (document.documentElement.clientWidth){
			Breedte = document.documentElement.clientWidth;
			Hoogte = document.documentElement.clientHeight;
		}
	}
	else if (document.body){
		Breedte = document.body.clientWidth;
		Hoogte = document.body.clientHeight;
	}
}
	
//S(earch) E(ngine) O(ptimization) Layer openen
function openSearchLayer() {
	getScreenDimensions();
	nSearchLayerWidth += 20;
	nSearchLayerHeight += 10;
	if (nSearchLayerWidth > 600) {nSearchLayerWidth = 600;}
	if (nSearchLayerHeight > 150) {nSearchLayerHeight = 150;}
	document.getElementById("searchOptions").style.top = ((Hoogte - 15) - nSearchLayerHeight) + "px";					
	document.getElementById("searchOptions").style.left = (Breedte / 2) - (nSearchLayerWidth / 2) + "px";					
	
	document.getElementById("searchOptions").style.height = nSearchLayerHeight +"px";					
	document.getElementById("searchOptions").style.width = nSearchLayerWidth +"px";					

	document.getElementById("searchOptionsContent").style.display = "none";					
	document.getElementById("searchOptions").style.display = "block";					

	if ((nSearchLayerWidth < 600) || (nSearchLayerHeight < 150)){
		setTimeout("openSearchLayer()", 10);
	}
	else {
		document.getElementById("searchOptionsContent").style.display = "block";					
	}
}

//S(earch) E(ngine) O(ptimization) Layer sluiten
function closeSearchLayer() {
	nSearchLayerWidth -= 12;
	nSearchLayerHeight -= 7;
	if (nSearchLayerWidth < 0) {nSearchLayerWidth = 0;}
	if (nSearchLayerHeight < 0) {nSearchLayerHeight = 0;}
	document.getElementById("searchOptions").style.top = ((Hoogte - 15) - nSearchLayerHeight) + "px";					
	document.getElementById("searchOptions").style.left = (Breedte / 2) - (nSearchLayerWidth / 2) + "px";					
	
	document.getElementById("searchOptions").style.height = nSearchLayerHeight +"px";					
	document.getElementById("searchOptions").style.width = nSearchLayerWidth +"px";					

	document.getElementById("searchOptionsContent").style.display = "none";					

	if ((nSearchLayerWidth > 0) || (nSearchLayerHeight > 0)){
		setTimeout("closeSearchLayer()", 10);
	}
	else {
		document.getElementById("searchOptionsContent").style.display = "none";					
		document.getElementById("searchOptions").style.display = "none";						
		document.getElementById("searchOptions").style.top = "-500px";					
		document.getElementById("searchOptions").style.left = "-500px";					
	}
}

//Menu optie activeren	
function activateMenu(nMenuID, iRow, iHasChilds, cMenuName, cMenuUrl){
	if (iRow == 0) { 
		document.getElementById('subMenuArea3').style.marginTop = 0;
		document.getElementById('subMenuArea3').style.height = 160;
	}
	else {
		document.getElementById('subMenuArea3').style.marginTop  = 31; // (iRow * 31);
		document.getElementById('subMenuArea3').style.height = 170;
	}
	document.getElementById('menudiv' + nMenuID).style.backgroundColor = '#AAC8E0';
	if (iHasChilds > 0) { 
		document.getElementById('subMenuArea3').style.display="block";
	}
	else {
		document.getElementById('subMenuArea3').style.display="none";
	}
	pathLevel[1] = cMenuName;
	pathUrl[1] = cMenuUrl;
	//iLayerWidth = 1;
	//document.getElementById('subMenuArea3').style.width = iLayerWidth ;
	//iInterval = setInterval("increaseLayerWidth('subMenuArea3', 200)",  1);
	check_content('main/submenu.php?parent=' + String(nMenuID), 'subMenuArea3');
	
}

function increaseLayerWidth(cLayer, iMaxWidth) {
	iLayerWidth += 10;
	if (iLayerWidth >= iMaxWidth) {
		iLayerWidth = iMaxWidth
		clearInterval(iInterval);
		iInterval = "";
	}
	document.getElementById(cLayer).style.width = iLayerWidth;
}

function deactivateMenu(nMenuID){
	document.getElementById('menudiv' + nMenuID).style.backgroundColor = '#C6D8EE';
}

function activateSubMenu(nMenuID){
	document.getElementById('submenudiv' + nMenuID).style.backgroundImage = 'url("images/transparantdark.png")';
}

function deactivateSubMenu(nMenuID){
	document.getElementById('submenudiv' + nMenuID).style.backgroundImage = '';
}

function hideSubMenu() {
	document.getElementById('subMenuArea3').style.display="none";
}

function handleMenuOption(iLevel, cName, cUrl, cImageList) {
	/*
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	
		try {
			var pageTracker = _gat._getTracker("UA-6654976-1");
			pageTracker._trackPageview("test/test1");
		} 
		catch(err) {}
	*/

	if (iLevel == 1) { 
		pathLevel[0] = cName; 
		pathUrl[0] = cUrl; 
		pathLevel[1] = ''; 
		pathUrl[1] = ''; 
		pathLevel[2] = ''; 
		pathUrl[2] = ''; 
	} 
	if (iLevel == 2) { 
		pathLevel[1] = cName; 
		pathUrl[1] = cUrl; 
		pathLevel[2] = ''; 
		pathUrl[2] = ''; 
	} 
	if (iLevel == 3) { 
		pathLevel[2] = cName; 
		pathUrl[2] = cUrl; 
	} 

	if (cImageList != '') {
		
		iMaxHeadImages = 0;
		arrImages = cImageList.split("&img");
		for (i=0;i<arrImages.length;i++) {
			str = arrImages[i + 1];
			if ((str != '') && (str != null)) {
				nPos = 2;
				if (i >= 10) { nPos = 4; }
				headImages[i] = str.substr(nPos, (str.length - (nPos - 1))) ;
				iMaxHeadImages++;
			}
		}
		setHeadImage();
	}
	
	var nPath = "";
	if (pathLevel[0] != "") {
		if (pathUrl[1] != "") {
			if (pathUrl[0] == "index.php") {
				chRef = pathUrl[0]; 
				nPath = nPath + '<A href="index.php" target="_top">' + pathLevel[0] + '</A>';
			}
			else {
				chRef = "javascript:check_content('" + pathUrl[0] + "'); handleMenuOption(1, '" + pathLevel[0] + "', '" + pathUrl[0] + "')"; 
				nPath = nPath + '<A href="' + chRef + '">' + pathLevel[0] + '</A>';
			}
		}
		else { nPath = nPath + pathLevel[0]; }
	}
	if (pathLevel[1] != "") { 
		if (pathUrl[2] != "") {
			chRef = "javascript:check_content('" + pathUrl[1] + "'); handleMenuOption(2, '" + pathLevel[1] + "', '" + pathUrl[1] + "')"; 
			nPath = nPath + ' >> <A href="' + chRef + '">' + pathLevel[1] + '</A>';
		}
		else { nPath = nPath + ' >> ' + pathLevel[1]; }
	}
	if (pathLevel[2] != "") { nPath = nPath +  ' >> ' + pathLevel[2];}
	document.getElementById('navPath').innerHTML = "&nbsp;&nbsp;U bent hier:&nbsp;" + nPath;
	
	if (cUrl == "index.php") {
		window.top.location.href = "index.php";
		}
	else {
		check_content(cUrl);
	}

	//try {
		var pageTracker = _gat._getTracker("UA-6654976-1");
		pageTracker._trackPageview(cUrl);
	//} 
	//catch(err) {}
}

window.onload = function(){
	setSize();
}
window.onresize = function(){
	setSize();
}

function goToUrl(sUrl) {
	window.top.document.location.href= sUrl;
}
	
