// JavaScript Document
$(document).ready(function(){

	doPositionMenu();
	
	hoofdmenu();
	
	$("#submenunav li > ul").css({display: "none"});
	
	$("#submenunav a").click(function() {
		if($(this).parent().children("ul").length == 0){
			return true;
		}else{
			$(this).parent().children("ul").toggle();
			return false;
		}
	}).next("ul").hide();

	$("img").click(function(event){
		try{
			var s;
			var a;
			var w;
			
			s = event.currentTarget.parentNode.nodeName;
			
			if(s == "A"){
				throw "link";
			}

			s = event.currentTarget.src;
			a = s.split("/");
			if(a.length<1){
				throw "incorrect link";
			}
			s = a[a.length-1];
			if((s.substr(s.length-3,s.length))!= "jpg"){
				throw "incorrect format";
			}
			s = s.substr(s.indexOf("_")+1,s.indexOf(".")-2);
			if(s.length == 0){
				throw "empty";
			}
			s = Number(s);
			if(isNaN(s)){
				throw "number";
			}
			
			w = window.location.href;
			if(w.substr(w.length-3,w.length) == "php"){
				w += "?f="+s;
			}else{
				w += "&f="+s;
			}
			window.location.href = w;
			return false;
			
		}catch(err){
			return true;
		}
	});
	
	$(".bannerfotos").innerfade({
		animationtype: 'none',
		type: 'random'
	});
});

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 doPositionMenu(){
	var count=0;
	var som=0;
	$("#menunav").children().each(
		function(){
			count += 1;
			som += $(this).width();
		}
	);
	
//	var marge=Math.round(((1000-som)/(count-1))-1);
	
	var marge=15;
	
	$("#menunav").children().not(":last").each(
		function(){
			$(this).css("margin-right",marge);
		}
	);
	
	var m=(1000-(som+((count-1)*marge)))/2;
	
	$("#menunav").css("padding-left",m);
}