function setHeight(){
	var height_final = 0;
	var height_1 = document.body.offsetHeight - 197;
	var height_2 = getObject('center').offsetHeight;
	var height_3 = getObject('left').offsetHeight;
	var height_4 = getObject('right').offsetHeight;
	var heightArray = new Array(height_1, height_2, height_3, height_4);
	for(var i = 0; i < heightArray.length; i++){
		if(heightArray[i] > height_final){
			height_final = heightArray[i];
		}
	}
	
	getObject('right').style.height = height_final + 'px';
	//getObject('portfoliotable').style.height = (0.95*height_final) + 'px';
	getObject('left').style.height = height_final + 'px';
}
window.onresize = setHeight;

function getObject(id){
	obj = document.getElementById(id);
	if(obj != undefined){
		return obj;
	}
}

function redirect(url, target){
	if(target == "_blank"){
		window.open(url, 'new_window');
	}
	else{
		document.location.href = url;
	}
}
function hide(id){
	document.getElementById(id).style.display = 'none';
}
function show(id){
	document.getElementById(id).style.display = 'block';
}

function show_flash(f_id, f_width, f_height, f_src, f_back, flashvars){	
	var params = {};
	params.quality = "high";
	params.menu = "false";
	params.bgcolor = f_back;
	params.wmode = "opaque";
	
	var attributes = {};
	attributes.id = "uniqueID";
	attributes.name = "uniqueID";

	swfobject.embedSWF(f_src, f_id, f_width, f_height, "8.0.0", "", flashvars, params, attributes);
}

function check_flash(id){
	obj = document.getElementById(id);
	var playerVersion = swfobject.getFlashPlayerVersion();
	if(playerVersion.major < 8){
		if(playerVersion.major == 0){
			obj.innerHTML += "<br /><br /><strong>Let op!</strong> U heeft geen Adobe Flash Player geïnstalleerd.";
		}
		else{
			obj.innerHTML += "<br /><br /><strong>Let op!</strong> U heeft een oude versie van de Adobe Flash Player geïnstalleerd.";
		}
		obj.innerHTML += "<br /><a href=\"http://get.adobe.com/flashplayer/\" target=\"_blank\" alt=\"Get Adobe Flash Player\">Klik hier om de nieuwste versie van de Adobe Flash Player te downloaden en te installeren.</a>";
	}
}

function show_img(id, image){
	document.getElementById(id).src = image;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function checkInput(obj, val){
	if(obj.value == val){
		obj.value = '';
		obj.onblur = function() { blurInput(this, val); };
		obj.style.color = '#000000';
	}
}

function blurInput(obj, val){
	if(obj.value == ''){
		obj.style.color = '#d7d7d7';
		obj.value = val;
	}
}

function checkPassword(obj, val) {
	if(obj.value != val) return true;
	var parentElem = obj.parentNode;
	try {
		// For well-behaved browsers
		obj.type = "password";
		obj.value = "";
		obj.style.color = "#000000";
		obj.onblur = function() { blurPassword(this, val); };
	} catch(error) {
		// IE chokes, so catch it and swap out the elements
		var newId = obj.id;
		var newName = obj.name;
		var newStyle = obj.style;
		var textnode = document.createElement("INPUT");
		textnode.type = "password";
		textnode.onblur = function() { blurPassword(this, val); };
		parentElem.appendChild(textnode);
		parentElem.removeChild(obj);
		textnode.id = newId;
		textnode.name = newName;
		textnode.focus();
		textnode.style.color = '#000000';
	}
}

function blurPassword(obj, val) {
	if(obj.value != "") 	return true;
	var parentElem = obj.parentNode;
	try {
		// For well-behaved browsers
		obj.type = "text";
		obj.style.color = "#d7d7d7";
		obj.value = val;
	} catch(error) {
		// IE chokes, so catch it and swap out the elements
		var newId = obj.id;
		var newName = obj.name;
		var newStyle = obj.style;
		var textnode = document.createElement("INPUT");
		textnode.type = "text";
		textnode.style.color = '#d7d7d7';
		textnode.value = val;
		textnode.onfocus = function() { checkPassword(this, val); };
		parentElem.appendChild(textnode);
		parentElem.removeChild(obj);
		textnode.id = newId;
		textnode.name = newName;
		textnode.blur();
	}
}

function showPopup(url){
	pos = findPos(getObject('showdialog'));
	getObject('dialog').style.top = (pos[1] - 259) + 'px';
	showBackground();
	show("dialog");
	updateDiv('dialog', url);
}

function closePopup(){
	hide("background");
	hide("errorFloater");
	getObject('dialog').innerHTML = '';
	hide("dialog");
}

function updateDiv(obj, url){
	new Ajax.Updater(obj, url,
		{
			onComplete: function() { hide('loader'); }
		}
	);
}

function showBackground(){
	obj = document.getElementById('background');
	obj.style.display = 'block'
	var tmp_height = obj.offsetHeight;
	objs = document.getElementsByTagName('div');
	for(var i = 0; i < objs.length; i++){
		objpos = findPos(objs[i]);
		objheight = objs[i].offsetHeight;
		objtemp = objpos[1] + objheight;
		if(objtemp > tmp_height){
			tmp_height = objtemp;
		}
	}
	obj.style.height = tmp_height + 'px';
}
function show_portfolio(item, id, pos){
	obj_pos = findPos(getObject(item));
	show(id);
	height = obj_pos[1];
	if(pos == 'last'){
		height = obj_pos[1] - 165;
	}
	document.getElementById(id).style.top = height + 'px';
}
