// JavaScript Document
image_container = '';
var basic = 0;
var minhoogte = 383;
var home_prod = false;
var totalprod = 0;
var currentprod = 0;
var current = 0;
var links = '';
var timer = 0;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
window.onload = function(){
	setHeight();
	
	var obj = document.getElementById("occasions_sub_rechts_info");
	if(obj){
		if(obj.offsetHeight < 151) 
			obj.style.height = "118px";
	}
}
function setHeight(tmp){
	var choogte, krechts, klinks;
	
	choogte = document.getElementById('main').offsetHeight;
	krechts = document.getElementById('kollomrechts');
	klinks = document.getElementById('balk_links_midden');
	basic = choogte;	
	if(krechts || klinks){
		if(choogte > minhoogte){
			choogte = choogte + 22;
			if(krechts){
				krechts.style.height = choogte - 4 + 'px';
			}
			if(klinks){
				klinks.style.height = choogte - 142 + 'px';
			}
		} else {
			if(krechts){
				krechts.style.height = minhoogte - 4 + 'px';
			}
		}
	}
	
	if(home_prod==true){
		links = document.getElementById('homeprod');
		links = links.getElementsByTagName('a');
			
		for(var i = 0; i < links.length; i++ ) {
			links[i].onmouseover = function() {
				var id = this.id;
				id = id.split("prod_");
				if(currentprod!=id[1]){
					links[currentprod].className='';
				}
				
				currentprod = id[1];
				this.className='active';
				
				switchHomeFoto(this);
				
				//document.getElementById(current).className='';
				//this.className='active';
				clearTimeout(timer);
				return false;
			}
			links[i].onmouseout = function() {
				timer = setTimeout(rotateProducts, 3000);
			}
			MM_preloadImages(links[i].rel);
			totalprod = links.length-1;
		}
		image_container = document.getElementById('h_prod_foto');
		rotateProducts();
	}
}

function rotateProducts(){
	clearTimeout(timer);
	// Oude deactiveren
	links[currentprod].className='';
	
	currentprod++;
	if(currentprod > totalprod) currentprod = 0;
	
	// Nieuwe activeren
	links[currentprod].className='active';
	switchHomeFoto(links[currentprod]);
	
	timer = setTimeout(rotateProducts, 3000);
}
function switchHomeFoto(img){
	image_container.innerHTML = '';
	
	var image =  document.createElement('img');
	image.src = img.rel;
	image.alt = img.title;
	image_container.appendChild(image);
}
function setVisible(type, table){
	document.getElementById(table).style.display = type;
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function showDiv(div){
	var d = document.getElementById(div);
	
	if(d.style.display=='block'){
		setHeightForOfferte(d.offsetHeight, 'min');
		d.style.display = 'none';	
	} else {
		d.style.display = 'block';
		setHeightForOfferte(d.offsetHeight, 'plus');
	}
	
}
function setUit(){
	var d = document.getElementById('zoekbalk_occasions_uit');
	var inp = document.getElementById('uit');
	
	if(d.style.display=='block'){
		inp.value = '1';	
	} else {
		inp.value = '0';	
	}
	
}

function setDivsOff(){
	var d = document.getElementById('offertes');
	d = d.getElementsByTagName('span');
	for(var i = 0; i < d.length; i++ ) {
		var show = 'none';
		for(var r = 0; r < divActive.length; r++){
			if(divActive[r] == d[i].id) show = 'block';
		}
		d[i].style.display = show;
	}
}

function setHeightForOfferte(hoogte, type){
	krechts = document.getElementById('kollomrechts');
	klinks = document.getElementById('balk_links_midden');
	
	if(type=='min') current = current - hoogte;
	else current = current + hoogte;
	
	if(krechts || klinks){
		var tmp = basic + current;
		//alert(current +' > '+ tmp +' - '+ hoogte);
		if(tmp > minhoogte){
			choogte = tmp + 22;
			if(krechts)	krechts.style.height = choogte - 4 + 'px';
			if(klinks)	klinks.style.height = choogte - 142 + 'px';	
		} else {
			if(klinks)	krechts.style.height = basic - 4 + 'px';
			if(klinks)	klinks.style.height = basic - 142 + 'px';	
		}
	}
}
