var banners, bnum, bmax, bprev, tmpbnum;
$(document).ready(function() {
	banners = Array();
	bmax = Array();
	bnum = Array();
	bprev = Array()
	tmpbnum = Array()
	
	checkBanner(1);
	checkBanner(2);
	
	if(document.forms["keuze"]) {
		setOption(document.forms["keuze"].elements["object"], 0)
	}
	
	checkForImage();
	$("#checkforimage input").click(function() {
		checkForImage();
	});
	
	lightbox()

	if($("#filetree a.openclose").length > 0) {
		$("#filetree  a.openclose").each(function() {
			$(this).click(function() {
				v = $(this).parent("li").find("ul").eq(0);
				if($(v).is(":visible") == false) {
					$(v).show();
					$(this).find("img").attr("src", $(this).attr("open"));
				} else {
					$(v).hide();
					$(this).find("img").attr("src", $(this).attr("close"));
				}
			});
		});
	}
	
	$(".languageTab li").hover(function() {
		if($(this).children("ul").length > 0) {
			$(this).children("ul").show();
		}
	}, function() {
		if($(this).children("ul").length > 0) {
			$(this).children("ul").hide();
		}
	});
	
});
function checkBanner(num) {
	banners[num] = Array();
	nn = "#imagelist" + num + " div";
	bmax[num] = $(nn).length;
	if(bmax[num] > 1) {
		$(nn).each(function(i) {
			banners[num][i] = this;
			$(this).fadeTo(1, 0);
			$(this).hide();
			if(i == 0) {
				$(this).fadeTo(1, 1);
				$(this).show();
			}
		});
		bnum[num] = 0;
		t = setTimeout("dobBanner(" + num + ");", num * 2500);
	}
}
function dobBanner(num) {
	tmpbnum[num] = bnum[num];
	nn = "#imagelist" + num + " div";
	
	$(nn).eq(tmpbnum[num]).fadeTo(1000, 0, function() {
		$(this).hide();
	});
	bprev[num] = bnum[num];
	bnum[num]++;
	if(bnum[num] >= bmax[num]) {
		bnum[num] = 0;
	}
	$(nn).eq(bnum[num]).show();
	$(nn).eq(bnum[num]).fadeTo(1000, 1, function() {	
		setTimeout("dobBanner(" + num + ");", 5000);
	});
}
var checkA, activeImage;
function checkForImage() {
	if(typeof(arr) == "undefined") {
		return;
	}
	activeImage = new Array()
	checkA = new Array();
	$("#allimages img").hide();
	p = 0;
	$("#checkforimage input").each(function () {
		
		if(this.type == "checkbox") {
			v = $(this).attr("rel");
			checkA[v] = this.checked;
			if(this.checked) {
				p = p + parseFloat($("#p" + v).text());
			}
			
		}
	});
	$("#tot_sum").html("&euro; " + number_format(p, 2, ",", "."));
	tot = p + parseFloat($("#koopsom").text());
	$("#tot_tot").html("&euro; " + number_format(tot, 2, ",", "."));
	num = 0;
	for(i in arr) {
		show = true;
		for(j in checkA) {
			if(arr[i][j] == undefined) {
				arr[i][j] = false;
			}
			if(arr[i][j] == checkA[j]) {
				
			} else {
				
				show = false;
			}
		}
		if(show) {
			activeImage[num] = i;
			num++;
		}
	}
	an = 0;
	$("#img" + activeImage[an]).fadeIn("slow");
	$("#afblabel").text("afbeelding " + (an+1) + " van " + activeImage.length);
}
var an;
function loopImage(what) {
	$("#img" + activeImage[an]).fadeOut("slow", function() {
		if(what) {
			an = an + 1;
			if(an >= activeImage.length) {
				an = 0;
			}
		} else {
			an = an - 1;
			if(an < 0) {
				an = activeImage.length-1;
			}
		}
		$("#img" + activeImage[an]).fadeIn("slow");
		$("#afblabel").text("afbeelding " + (an+1) + " van " + activeImage.length);
	});
}



function number_format (number, decimals, dec_point, thousands_sep) {
    var n = number, prec = decimals;
 
    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);
        return (Math.round(n*k)/k).toString();
    };
 
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
 
    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = toFixedFix(Math.abs(n), prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    var decPos = s.indexOf(dec);
    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';
    }
    return s;
}
