﻿window.onload = laadpag;

var isIE = (navigator.appName.indexOf("Microsoft") != -1 && navigator.appVersion.indexOf("Windows") > -1)+1-1;
try { if (isIE) document.execCommand('BackgroundImageCache', false, true); } catch(e) {}

var bgnr = Math.round(7*Math.random()) + 1;
var kleuren = ';#767676;#818480;#A4917B;#7B9BA9;#BEBB9E;#BFA584;#BAB49D;#C7B696';
document.write('<style type="text/css">body{background-color:' + kleuren.split(';')[bgnr] + ' !important}</style>');

var objBody;
var hasFlash = function(){
	var nRequiredVersion = 8;
	if(isIE){
		document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
		if(window.hasFlash != null){ return window.hasFlash;};
	};
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		var vr = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1)); if (vr < 4) vr += 10;	
		return vr >= nRequiredVersion;
	};
	return false;
}();

function laadpag(){
	zetvideo();
	bg();
	if (eId('items')) start();
}

function bg(){
	document.getElementsByTagName("body")[0].style.backgroundImage = 'url(/grafiek/bg' + bgnr + '.jpg)';
	}

function zetvideo(){
	if (eId('video')){
			var fv = 'file=/video/' + eId('video').title + '.flv&image=/video/' + eId('video').title + '.flv.jpg&height=370&width=600&backcolor=0x493a34&frontcolor=0xFFFFFF&lightcolor=0x493a34&screencolor=0x493a34&overstretch=none';
			eId('video').innerHTML = flash("/grafiek/mediaplayer.swf", '600', '370', '#000000', '', fv, '');
			eId('video').title = '';
	}
}

// portfolio
var zoekTekst = "zoekterm";

function start() {
	eId('soort').onchange = filter;
	eId('techniek').onchange = filter;
	eId('tekst').value = zoekTekst;
	eId('tekst').onfocus = leeg;
	eId('tekst').onblur = vul;
	eId('tekst').onkeyup = filter;
	var tmp = getCookie('soort_Cookie', '');
	if (location.hash.length > 0){
		tmp = location.hash;
	}
	for (var x = 0; x < 10; x++) { 
		if (eId('soort').options[x].value == tmp.replace("#", "")) {
			eId('soort').options[x].selected = true; 
		}
	}
	for (var y = 0; y < 5; y++) { 
		if (eId('techniek').options[y].value == getCookie('techniek_Cookie', '')) {
			eId('techniek').options[y].selected = true; 
		}
	}
	var tmp2 = getCookie('tekst_Cookie', '');
	if (tmp2 != '' ){
		eId('tekst').value = tmp2;
	}
	filter();
}

function herstel() {
	eId('tekst').value = zoekTekst;
	eId('soort').selectedIndex = 0;
	eId('techniek').selectedIndex = 0;
	filter();
}

function leeg(){
	if (eId('tekst').value == zoekTekst){
		eId('tekst').value = "";
	}
}

function vul(){
	if (eId('tekst').value == ""){
		eId('tekst').value = zoekTekst;
	}
}

function niets () {
	titel = this.title;
	url = this.firstChild.title;
	return false;
}

function setCookie(name, val){
   document.cookie = name + "="  + val + "; path=/";
}

function getCookie(name, defval) {
   var nameEQ = name + "="; var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
       var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length);
       if (c.indexOf(nameEQ) == 0) {
           ck = '' + c.substring(nameEQ.length,c.length); if (ck != '') return ck;}
   }
   return defval;
}

function filter(){
		setCookie('soort_Cookie', eId('soort').value);
		setCookie('techniek_Cookie', eId('techniek').value);
		setCookie('tekst_Cookie', eId('tekst').value);
		herstellink = "";
		var items = eId('items').getElementsByTagName("a");
		var totaal = items.length;
		var teller = 0;
		var treffer = false;
		for (i=0;i<items.length;i++) {
				items[i].className = '';
				items[i].onclick = function () {this.title = titel;this.firstChild.title = url;}
				
				if (items[i].getAttribute("rel").indexOf(eId('soort').value) < 0 && eId('soort').value != ""){
					items[i].className = "greyedOut";
	items[i].onmouseover = niets;
					treffer = true;
				}
				if (items[i].firstChild.getAttribute("alt").indexOf(eId('techniek').value) < 0 && eId('techniek').value != ""){
					items[i].className = "greyedOut";
	items[i].onmouseover = niets;
					treffer = true;
				}
				if (items[i].getAttribute("title").toLowerCase().indexOf(eId('tekst').value.toLowerCase()) < 0 && eId('tekst').value != "" && eId('tekst').value != zoekTekst){
					items[i].className = "greyedOut";
	items[i].onmouseover = niets;
					treffer = true;
				}
				if (treffer){
						teller++;
						treffer = false;
				}else{
	items[i].onmouseover = function() {
	titel = this.title;
	url = this.firstChild.title;
	this.title = "";
	this.firstChild.title = "";
	setLabel("<strong>" + titel + "</strong><br />" + url);
	}
	items[i].onmousemove = LocateTt;
	items[i].onmouseout = function () {
	verbergLabel();
	this.title = titel;
	this.firstChild.title = url;
	}
	}
	}
	if (teller > 0){
		herstellink = "&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"javascript:herstel();\">toon alles</a>";
	}
	eId("aantal").innerHTML = (totaal - teller) + " van " + totaal + " projecten" + herstellink;
}

function LocateTt(e){
	var posx=0,posy=0;
	if(e==null) e=window.event;
	if(e.pageX || e.pageY){
	posx = e.pageX;
	posy = e.pageY;
		}
	else if(e.clientX || e.clientY){
		if(document.documentElement.scrollTop){
			posx=e.clientX+document.documentElement.scrollLeft;
			posy=e.clientY+document.documentElement.scrollTop;
			}
		else{
			posx=e.clientX+document.body.scrollLeft;
			posy=e.clientY+document.body.scrollTop;
			}
		}
	eId("label").style.right = (document.documentElement.clientWidth - posx) + "px";
	eId("label").style.top = (posy - 50) + "px";
}

function verbergLabel() {
	eId("label").style.display = "none";
}

function setLabel(tit) {
	eId("label").style.display = "block";
	eId("label").innerHTML = tit;
}

// einde portfolio

function flash(movie, w, h, bg, wm, flashvars, bas){
	if (isIE){
		return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="'+movie+'" width="'+ w + '" height="' + h + '"><param name="movie" value="' + movie + '" /><param name="FlashVars" value="' + flashvars + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="' + wm + '" /><param name="bgcolor" value="' + bg + '" /><param name="base" value="' + bas + '" /><param name="allowfullscreen" value="true" /></object>';
	} else {
		return '<embed src="' + movie + '" quality="high" wmode="' + wm + '" bgcolor="' + bg + '" menu="false" width="'+ w + '" base="' + bas + '" height="'+ h + '" FlashVars="' + flashvars + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true" />';}
}


function eId(w){return document.getElementById(w);}

function zet(str){document.write(str);}