var vIE = document.all?true:false
vArray = new Array();
vArrayOn = new Array();

window.onresize = setTextHeight;

window.onload = headerPhoto;

function setOpacity(fObject, fOpacity){
	if(document.getElementById(fObject))
		fObject = document.getElementById(fObject);
	vIE?fObject.style.filter = 'alpha(opacity='+ fOpacity +')':fObject.style.opacity = (fOpacity / 100);
}
function setTextHeight(){
	//site breedte
	if(document.body.clientWidth < 1000){
		document.getElementById('site').style.width = (document.body.clientWidth - 4) +'px';
	}
	else{
		document.getElementById('site').style.width = '1000px';
	}
	// show/hide nieuws foto ivm hoogte
	if(document.getElementById('nieuwsfoto'))
			document.getElementById('nieuwsfoto').style.display = '';
	if(document.body.clientHeight < (168 + 10 + (document.getElementById('nieuws').offsetHeight) + 10 + (document.getElementById('maillist').offsetHeight))){
		if(document.getElementById('nieuwsfoto'))
			document.getElementById('nieuwsfoto').style.display = 'none';
	}
	document.getElementById('text').style.height = (document.body.clientHeight - 168 - 14) +'px';
}
function maillistForm(vWhich, vAction){
	if(vWhich == 1){
		vName = document.getElementById('maillistName');
		if(vAction == 1 && vName.value == 'uw naam')
			vName.value = '';
		if(vAction == 2 && vName.value == '')
			vName.value = 'uw naam';
	}
	else{
		vEmail = document.getElementById('maillistEmail');
		if(vAction == 1 && vEmail.value == 'uw email')
			vEmail.value = '';
		if(vAction == 2 && vEmail.value == '')
			vEmail.value = 'uw email';
	}
}

/* dropdown */
function setDropdown(vId){
	document.getElementById('div_'+ vId).style.left = document.getElementById('menu'+ vId).offsetLeft +'px';
	document.getElementById('div_'+ vId +'_2').style.left = document.getElementById('menu'+ vId).offsetLeft +'px';
	document.getElementById('div_'+ vId +'_2').style.width = document.getElementById('div_'+ vId +'-2').offsetWidth +'px';
}
function button(vId){
	vDiv = document.getElementById('div_'+ vId);
	vDiv2 = document.getElementById('div_'+ vId +'-2');
	if(typeof(window['vArray['+ vId +']']) == 'undefined'){
		vArray[vId] = new Array();
		
		if(vIE == true){
			vArray[vId][1] = vDiv2.offsetHeight;
		}
		else{
			vArray[vId][1] = vDiv2.clientHeight;
		}
		vArray[vId][2] = Math.ceil(vArray[vId][1] / 10);
		vArray[vId][3] = 'up';
		setDropdown(vId);
		vDiv.style.display = '';
	}
	
	vArray[vId][3] = 'down';
	setTimeout('schuiven('+ vId +')', 125);			
}
function schuiven(vId){
	vHeight = document.getElementById('div_'+ vId).clientHeight;
	if(vArray[vId][3] == 'down'){
		if(vHeight < vArray[vId][1]){
			if((vHeight + vArray[vId][2]) > vArray[vId][1]){
				document.getElementById('div_'+ vId).style.height = vArray[vId][1] +'px';
				document.getElementById('div_'+ vId +'_2').style.height = vArray[vId][1] +'px';
			}
			else{
				document.getElementById('div_'+ vId).style.height = (vHeight + vArray[vId][2]) +'px';
				document.getElementById('div_'+ vId +'_2').style.height = (vHeight + vArray[vId][2]) +'px';
				setTimeout('schuiven('+ vId +')', 25);
			}
		}
	}
	else{	
		if(vHeight != 0){
			if((vHeight - vArray[vId][2]) < 0){
				document.getElementById('div_'+ vId).style.height = '0px';
				document.getElementById('div_'+ vId +'_2').style.height = '0px';
			}
			else{
				document.getElementById('div_'+ vId).style.height = (vHeight - vArray[vId][2]) +'px';
				document.getElementById('div_'+ vId +'_2').style.height = (vHeight - vArray[vId][2]) +'px';
				setTimeout('schuiven('+ vId +')', 10);
			}
		}
	}
}
function dropdownOn(vId){
	vArrayOn[vId] = 'on';
	document.getElementById('menu'+ vId).src = 'images/menutop_rondje_hover.gif';
	if(document.getElementById('div_'+ vId)){
		if(vArray[vId]){
			if(vArray[vId][3] != 'down'){
				button(vId);
			}
		}
		else{
			button(vId);
		}
	}
}
function dropdownOut(vId){
	vArrayOn[vId] = 'off';
	setTimeout('inschuiven('+ vId +')', 50);
}
function inschuiven(vId){
	if(vArrayOn[vId] == 'off'){
		document.getElementById('menu'+ vId).src = 'images/menutop_rondje.gif';
		if(document.getElementById('div_'+ vId)){
			vArray[vId][3] = 'up';
			schuiven(vId);
		}
	}
}
/* einde dropdown */
vFotoArray = '';
vFotoNum = 0;
vFotoPath = 'producten_extra';
function fotobox(vFoto1, vFoto2, vFoto3, vFoto4){
	if(!document.getElementById('fotobox')){
		vBody = document.getElementsByTagName('body')[0];
		vAlertDiv = document.createElement('div');
		vAlertDiv.setAttribute('id', 'fotobox');
		
		vBody.insertBefore(vAlertDiv, vBody.firstChild);
		
		document.getElementById('fotobox').innerHTML = '<div id="fotobox_bg"></div><div id="fotobox_fg"><div id="fotobox_foto"></div><div id="fotobox_prev"><a href="#" onclick="fotobox_prev();">&#60;</a></div><div id="fotobox_aantal" style="text-align:center;"></div><div id="fotobox_next"><a href="#" onclick="fotobox_next();">&#62;</a></div><div id="fotobox_close"><a href="#" onclick="fotobox_close();">sluiten</a></div></div>';
	}
	vFotoArray = new Array();
	if(vFoto1)
		vFotoArray.push(vFoto1);
	if(vFoto2)
		vFotoArray.push(vFoto2);
	if(vFoto3)
		vFotoArray.push(vFoto3);
	if(vFoto4)
		vFotoArray.push(vFoto4);
		
	if(vFotoArray.length != 0){
		fotobox_show(0);
		document.getElementById('fotobox').style.display = '';
	}
}
function fotobox_prev(){
	vFotoNum--;
	if(vFotoNum < 0)
		vFotoNum = (vFotoArray.length - 1);
	fotobox_show(vFotoNum);
}
function fotobox_next(){
	vFotoNum++;
	if(vFotoArray.length == vFotoNum)
		vFotoNum = 0;
	fotobox_show(vFotoNum);
}
function fotobox_show(vId){
	vFotoNum = vId;
	document.getElementById('fotobox_aantal').innerHTML = (vFotoNum + 1) +'/'+ vFotoArray.length;
	document.getElementById('fotobox_foto').style.backgroundImage = "url('./data/images/"+ vFotoPath +"/gr_"+ vFotoArray[vId] +"')";
}
function fotobox_close(){
	document.getElementById('fotobox').style.display = 'none';
}
function sendMail(vEmail){
	vEmail = vEmail.replace('[op]', '@');
	vEmail = vEmail.replace('[punt]', '.');
	document.location.href = "mailto:"+ vEmail;
}
vImage = '';
vActive = 'head_bg1';
vNonActive = 'head_bg2';
function loadPhoto(vPhoto){
	if(vPhoto){
		vImage = new Image();
		vImage.src = vPhoto;
	}
	else{
		return vImage.complete;
	}
}
function setPhoto(){
	vNumber = (Math.floor(Math.random()*5) + 1);
	if(vPhotoNum == vNumber){
		if((vNumber + 1) > vPhotoTotal)
			vNumber--;
		else
			vNumber++;
	}
	vPhotoNum = vNumber;
	loadPhoto('./images/'+ vPhotoFirst +'_header'+ vNumber +'.jpg');
}
function headerPhoto(){
	if(vPhotoTotal > 1){
		if(vImage == ''){
			setPhoto();
			setTimeout('headerPhoto()', 5000);
		}
		else{
			if(loadPhoto()){
				document.getElementById(vNonActive).style.backgroundImage = "url('"+ vImage.src +"')";
				changeHeadPhoto();
				setPhoto();
				setTimeout('headerPhoto()', 5000);
			}
			else
				setTimeout('headerPhoto()', 100);
		}
	}
}
function changeHeadPhoto(vNum){
	if(!vNum)
		vNum = 1;
	
	setOpacity(vActive, (100-(vNum * 10)));
	setOpacity(vNonActive, (vNum * 10));
	
	if(vNum < 10)
		setTimeout('changeHeadPhoto('+ (vNum + 1) +')', 50);
	else{
		vTemp = vNonActive;
		vNonActive = vActive;
		vActive = vTemp;
	}
}