// JavaScript Document
var contentleft;
var contentrighta;
var contentrightb;
var contentrightc;

$(document).ready(function(){
	contentleft = $("#contentleft").height();
	contentrighta = $("#contentrighta").height()+20;
	contentrightb = $("#contentrightb").height()+20;
	contentrightc = $("#contentrightc").height()+21;

	doPosistion(contentleft,contentrighta,contentrightb,contentrightc);
	
	doPositionMenu();
	
	hoofdmenu();

});

$(window).resize(function(){
	doPosistion(contentleft,contentrighta,contentrightb,contentrightc);
});

function hoofdmenu(){
	$("#menunav ul").css({display: "none"}); // Opera Fix
	$("#menunav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show();
//		$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(100);
//				$(this).find('ul:first').css({visibility: "visible",display: "none"}).show();
	},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
}

function doPosistion(cleft,crighta,crightb,crightc){
	var xpos = ($(window).width()-900)/2;

//	var windowheight = $(window).height()-$("#topcontainer").height()-$("#menucontainer").height()-$("#bottomcontainer").height();
// TODO padding, margin, borders
	var windowheight;
	if($("#submenucontainer").length>0){
		windowheight = $(window).height()-340;
	}else{
		windowheight = $(window).height()-310;
	}
	var maxheight;
	
	maxheight = (cleft-crightc);
	if(crighta > maxheight){
		maxheight = crighta;
	}
	if(crightb > maxheight){
		maxheight = crightb;
	}
	if((windowheight-crightc) > maxheight){
		maxheight = (windowheight-crightc);
	}
	
	$("#contentleft").height(maxheight+crightc);
	$("#contentrighta").height(maxheight-20);
	$("#contentrightb").height(maxheight-20);
	
}

function doPositionMenu(){
	var count=0;
	var som=0;
	$("#menunav").children().each(
		function(){
			count += 1;
			som += $(this).width();
		}
	);
	
	var marge=Math.round(((950-som)/(count-1))-1);
	
	$("#menunav").children().not(":last").each(
		function(){
			$(this).css("margin-right",marge);
		}
	);
}