
Cufon.replace('h1,.menuContainer a,#homepanel .text h2,#homepanel .text h3',{hover : true});
var menu = false;
var photoRollCurPos = 0;

//rechtermuisclick uit.
function myclick1() { 
alert('Fotografie is auteursrechtelijk beschermd.\n(c) Sander Nagel.');
return false;
};

function myclick2(event) { 
if (event.button == 2) 
 {
alert('Fotografie is auteursrechtelijk beschermd.\n(c) Sander Nagel.');
};
};

if (document.all) {
document.oncontextmenu=myclick1;
}else {
document.onmousedown=myclick2;
};

$(function(){
	$("a._blank").attr({target : '_blank'});
	$(".menuContainer").show();
	setMenu();
	menuHeight();
	isiPad();
	$(".menuContainer .opacityImage").click(function(){ document.location='/'});
	$(".menuContainer a").hover(function(){ $(this).css({color: '#FFF'});Cufon.replace('.menuContainer a',{hover : true});},function(){ $(this).css({color: ''});Cufon.replace('.menuContainer a',{hover : true});})
	
	if ($("#homepanel").text() != "") {
		if (isiPad()) $(".menuContainer").hide();
		$("#homepanel .text").hover(function(){ 
			$(this).addClass('active');
			Cufon.replace('#homepanel .text h2,#homepanel .text h3');
		},function(){ 
			$(this).removeClass('active');
			Cufon.replace('#homepanel .text h2,#homepanel .text h3');
		});
		$("#logo").click(function(){ menuOn()}).mouseover(function(){ menuOn()});
		$(".menuContainer").mouseover(function(){ menuOn()});
		$(".homephoto").mouseover(function(){ menuOff()});
		$(".homephoto").fadeIn(1000);
		setTimeout(function(){ if(!menu) $("#homepanel").animate({opacity:1},{duration:1000}) },500);

	}else {
		menu=true;
		$(".menuContainer").show().css({left:0,opacity:1});
		if (isiPad()) { $(".photoroll").jScrollTouch({ease:300,displayScrollBar:false }) };

	}
	
	
	//PHOTO
	
	if ($(".photoroll").text() !="") {
		var scrollpos = parseInt(document.location.hash.substr(1),10);	
	if ( !isNaN(scrollpos)) {
		setTimeout(function(){$('.photoroll').scrollTo( scrollpos, 1, {axis:'x'} );},100);
	}
		$('.photoroll').css({left:0});
		$(".photomore").click(function() { 
			$('.photoroll').stop().scrollTo( '+=500px', 300, {axis:'x'} );
			
			
		//leftChecker=setInterval(function(){checkLeft(1)},50);
		//$(".photoroll ul").stop().animate({left: '-=500px'},{easing: 'easeOutCubic',duration:1000, complete : checkLeftOff})
		});
		$(".photoless").click(function() {
			$('.photoroll').stop().scrollTo( '-=500px', 300, {axis:'x'} );

			//leftChecker=setInterval(function(){checkLeft(-1)},50);
			//$(".photoroll ul").stop().animate({left: '+=500px'},{easing: 'easeOutCubic',duration:1000,complete : checkLeftOff})
		});
		$(".photoroll ul").width($(".photoroll ul li").length*($(".photoroll ul li").width()+10));
		$(".photorollContainer").width($(window).width()-245);
		$(".photoroll").width($(window).width()-342);
		$(".photo img, .photoBackground").height($(window).height()-150);
		$(".photo").width($(window).width());
		
			$(".photoroll ul li a").click(function(e){ e.preventDefault();document.location=$(this).attr('href')+"#"+$('.photoroll').scrollLeft(); return false});
	}
})

/*function checkLeft(d)
{
	var left = parseInt($(".photoroll ul").css('left'));
	var maxwidth = $(".photoroll").width()-$(window).width()-50;
	if (d == -1)
	{
		if (left > 0) {
			$(".photoroll ul").stop().css({left: 0});
			checkLeftOff();
		}
	}else {
		if (left < maxwidth) {
			$(".photoroll ul").stop().css({left: maxwidth});
			checkLeftOff();
		}		
	}
}

function checkLeftOff()
{
	clearInterval(leftChecker);
}*/

function menuOn()
{
	if (!menu) {
		$("#homepanel").stop().animate({opacity:0},{duration:500, complete : function(){ $(this).hide()}});
		$(".menuContainer").stop().show().css({left:0}).animate({opacity:1},{duration:500});
	}
	menu = true;
}

function menuOff()
{
	if (menu) {
		$("#homepanel").stop().show().animate({opacity:1},{duration:500});
		$(".menuContainer").stop().animate({opacity:0},{duration:500, complete: function(){
			$(this).css({left:-55});
		}
		});
	}
	menu = false;
}


function isiPad(){
    if(navigator.platform.indexOf("iPad") != -1) {
	$('body,html').css({width:1024,height:758,overflow:'hidden'});
	return true;
	}else {
	$('body,html').css({width:$(window).width(),height:$(window).height(),overflow:'hidden'});
	return false;
	}
}

function setMenu()
{
	var a = $(".menuContainer ul a.active");
	//level activemenu
	if (a.next() != undefined)	a.next().show();
	
	//level parents
	for (i=0;i<=1;i++) // 4 levels
	{	a = a.parent().parent();
		a.show();
	}
	$(".menuContainer ul li a.highest").click(function(e){e.preventDefault();openCurrentSubmenu($(this))});
}


function menuHeight()
{
	var submenuheight = Math.floor(($(window).height()-450)/27)*27;
	$(".menuContainer ul li ul").each(function(i){

		$(this).after('<div class="next" onclick="menumore(\'submenu'+i+'\',5)"></div>');
		$(this).before('<div class="prev" onclick="menumore(\'submenu'+i+'\',-5)"></div>');
		if ($(this).height() > submenuheight) {
			$(this).attr({id : 'submenu'+i,scrollpos : 0}).css({height:submenuheight});
			if ($(this).prev().prev().hasClass('active')) { 
				$(this).prev().show();$(this).next().show();
				$(this).scrollTo( 'li a.active', 10, {axis:'y'} );
			}else {
				$(this).prev().hide();
				$(this).next().hide();	
			}
		}else {
			$(this).prev().removeClass('prev').hide();
			$(this).next().removeClass('next').hide();			
		}
	})
}


function menumore(d,y)
{
	var cur = (parseInt($('#'+d).attr('scrollpos'),10)+y);
	if (cur <= 0) {cur =0;$('#'+d).closest('.prev').slideUp();}else {$('#'+d).closest('.prev').slideDown();}
	if (cur >=  $('#'+d+' li').length-1) {cur = $('#'+d+' li').length-1;$('#'+d).parent().closest('.next').css({opacity:0});}else{$('#'+d).parent().closest('.next').css({opacity:1})}
	$('#'+d).attr({scrollpos:cur});
	$('#'+d).stop().scrollTo( 'li:eq('+cur+')', 1000, {axis:'y'} );
}


function openCurrentSubmenu(submenu)
{
	$(".menuContainer ul li ul, .prev, .next").slideUp();submenu.next().next().attr({scrollpos : 0}).slideDown();submenu.next().slideDown();submenu.next().next().next().slideDown()
}
