function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function picturewidth() {
	var divs=document.getElementsByTagName('div');
	for (i=0;i<divs.length;i++) {
		if (divs[i].className=='caption') {
			var picture=divs[i].parentNode;
			var images=picture.getElementsByTagName('img');
			picture.style.width=images[0].offsetWidth+'px';
		}	
	}
}


function links() {
	var zoekvergrootglasLink=document.getElementById("zoekvergrootglas");
	if(zoekvergrootglasLink) {
		zoekvergrootglasLink.onclick=function() {
			zoekform = document.getElementById("searchForm");
			if(zoekform) {
				zoekform.submit();
			}
			return false;
		}
	}
	var printlink=document.getElementById("print");
	if(printlink) {
		printlink.onclick=function() {
			print();
			return false;
		}
	}
	var referlink=document.getElementById("mail");
	if(referlink) {
		referlink.onclick=function() {
			var theWidth = 550;
			var theLeft = Math.ceil((screen.width-theWidth)/2);
			var winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,scrollbars=no,resizable=yes,width="+theWidth+",height=650,top=0,left="+theLeft;
			openPopup(this.href,winopts);
			return false;
		}
	}
	var links=document.getElementsByTagName("a");
	for(i=0;i<links.length;i++) {
		if (links[i].className.indexOf("extLink") >= 0) {
			links[i].onclick=function() {
				openPopup(this.href,"");
				return false;
			}
		}
	}
	var facebooklink=document.getElementById("facebook");
	if(facebooklink) {
		facebooklink.onclick=function() {
			var theWidth = 700;
			var theLeft = Math.ceil((screen.width-theWidth)/2);
			var winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,scrollbars=no,resizable=yes,width="+theWidth+",height=800,top=0,left="+theLeft;
			openPopup(this.href,winopts);
			return false;
		}
	}
	var twitterlink=document.getElementById("twitter");
	if(twitterlink) {
		twitterlink.onclick=function() {
			var theWidth = 700;
			var theLeft = Math.ceil((screen.width-theWidth)/2);
			var winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,scrollbars=no,resizable=yes,width="+theWidth+",height=800,top=0,left="+theLeft;
			openPopup(this.href,winopts);
			return false;
		}
	}
}

function openPopup(href,winopts) {
	smallwindow=window.open(href,"Popup",winopts);
	smallwindow.focus();
}

addLoadEvent(picturewidth);
addLoadEvent(links);


$(document).ready(function(){

	// select
	$('#persontype, #choice, #opl_department, #opl_interest, #opl_type').sSelect();

	// homepage slider
	if($("#cycle_root").length > 0) {
		$('#cycle_root').cycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 7000,
			activePagerClass: 'active',
			pager:  '#newsNr'
		});
	}

	$('#iAmForm #persontype').change(function() {
		if($(this).val() != '') {
			$('#iAmForm').attr('action','/' + $(this).val());
			$('#iAmForm').submit();
		}
	});
	$('#iAmForm').submit(function() {
		if($('#persontype').val() != '') {
			$('#iAmForm').attr('action','/' + $('#persontype').val());
		} else {
			return false;
		}
	});

	$('#iSearchForm #choice').change(function() {
		if($(this).val() != '') {
			$('#iSearchForm').attr('action',$(this).val());
			$('#iSearchForm').submit();
		}
	});
	$('#iSearchForm').submit(function() {
		if($('#choice').val() != '') {
			$('#iSearchForm').attr('action',$('#choice').val());
		} else {
			return false;
		}
	});

	// placeholder
	$('input[placeholder]').placeHeld();

	// block image loop
	if($(".cycle_root").length > 0) {
		$('.cycle_root').cycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 3000
		});
	}

	
});
