var fotoboek_left_pos = 0;
var project_left_pos = 0;
var left_pos = 0;

$.extend(
	{   
		PODgetUrlVars: function()
		{     
			var vars = [], hash;     
			
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');     
			for(var i = 0; i < hashes.length; i++)     
			{       
				hash = hashes[i].split('=');       
				vars.push(hash[0]);       
				vars[hash[0]] = hash[1];     
			}     
			return vars;   
		},   
			
		PODgetUrlVar: function(name)
		{     
			return $.PODgetUrlVars()[name];   
		} 
	}
);


function showMask(p_div_str)
{
	//$('body').css({'overflow':'hidden'});
	var maskHeight = $(document).height()-20;   
	//var maskWidth = GetClientWindowSize();   
	var maskWidth = $(window).width();
	
	//Set height and width to mask to fill up the whole screen   
	$(p_div_str).css({'width':maskWidth,'height':maskHeight,'padding':'0','margin':'0'});   
	   
	//transition effect        
	$(p_div_str).fadeIn(1000);       
	$(p_div_str).fadeTo("slow",0.8);  
}

function showProject(p_id)
{
	 //Cancel the link behavior   
			  
			   showMask('#project_mask');
			   
			   
				//Get the window height and width   
				var winH = $(window).height();   
				var winW = $(window).width();   
						 
			   //Set the popup window to center   
				$('#project_wrapper').css('top',  (winH/2-$('#project_wrapper').height()/2) + $(window).scrollTop());   
			   $('#project_wrapper').css('left', winW/2-$('#project_wrapper').width()/2);   
			   
			   $("#project_window").hide();
			   $("#project_loading").show();
				//transition effect   
			   $('#project_wrapper').fadeIn(2000);   
			   
			  $('#project_window').load('project.php?id=' + p_id, function() {
				  $('#project_loading').hide();
  					$('#project_window').fadeIn(1000);    
				});
}

	$(document).ready(
		function()
		{
			
			// zoek mailto links	
			$('a[href^=mailto]').addClass('email');
				
			// de bladerknoppen boven aan op de niet fotoboek, projecten pagina's
			$('#home_foto_right').bind("click", function()
			{		
				left_pos-=350;
			
				 //$('#home_fotobar_content').css("left", left_pos);		 
				 $("#home_fotobar_content").animate({left: "-=350px"}, 300 ); 	
			});
			
			$('#home_foto_left').bind("click", function()
			{
				if (left_pos == 0)
				{
					return;
				}
				
				left_pos+=350;
				
				// $('#home_fotobar_content').css("left", left_pos);
				 $("#home_fotobar_content").animate({left: "+=350px"}, 300 ); 
			});
			
			
			// de bladerknoppen van de fotoboek pagina
			// de bladerknoppen boven aan
			$('#fotoboek_foto_right').bind("click", function()
			{			
				fotoboek_left_pos-=350;
				
				 //$('#home_fotobar_content').css("left", left_pos);		 
				 $("#fotoboeken_fotobar_content").animate({left: "-=350px"}, 300 ); 
				
			});
			
			$('#fotoboek_foto_left').bind("click", function()
			{
				if (fotoboek_left_pos == 0)
				{
					return;
				}
				
				fotoboek_left_pos+=350;
				
				// $('#home_fotobar_content').css("left", left_pos);
				 $("#fotoboeken_fotobar_content").animate({left: "+=350px"}, 300 ); 
			});
			
			
			// de projecten 
			// de bladerknoppen boven aan
			$('#project_foto_right').bind("click", function()
			{		
				project_left_pos-=350;
				
				 //$('#home_fotobar_content').css("left", left_pos);	 
				 $("#fotoboeken_fotobar_content").animate({left: "-=350px"}, 300 ); 
				
			});
			
			$('#project_foto_left').bind("click", function()
			{
				if (project_left_pos == 0)
				{
					return;
				}
				
				project_left_pos+=350;
				
				// $('#home_fotobar_content').css("left", left_pos);
				 $("#fotoboeken_fotobar_content").animate({left: "+=350px"}, 300 ); 
			});
						
			// de projectlinks gekoppelt a/d foto's
			
			  $('a.project_link').click(function(e) 
			  {   
			    e.preventDefault();   
			  	showProject( $(this).attr('id'));
				
			  });
				
				
				 //if mask is clicked   
		$('#project_mask').click(function () {   
			$('#project_mask').fadeOut(1000);   
		   $('#project_wrapper').fadeOut(1000, resetBody);   
		   
		    
		}); 
		
		
		// de projectlinks gekoppelt a/d foto's
			
			  $('a.artikel_link').click(function(e) 
			  {   
			   
			   //Cancel the link behavior   
			   e.preventDefault();   
			   showMask('#artikel_mask');
			   
			   
				//Get the window height and width   
				var winH = $(window).height();   
				var winW = $(window).width();   
						 
			   //Set the popup window to center   
				$('#artikel_wrapper').css('top',  (winH/2-$('#artikel_wrapper').height()/2) + $(window).scrollTop());   
			   $('#artikel_wrapper').css('left', winW/2-$('#artikel_wrapper').width()/2);   
			   
			   $("#artikel_window").hide();
			   $("#artikel_loading").show();
				//transition effect   
			   $('#artikel_wrapper').fadeIn(2000);   
			   
			  $('#artikel_window').load('artikel.php?id=' + $(this).attr('id'), function() {
				  $('#artikel_loading').hide();
  					$('#artikel_window').fadeIn(1000);    
				});
				
			  });
				
				
				 //if mask is clicked   
		$('#artikel_mask').click(function () {   
			$('#artikel_mask').fadeOut(1000);   
		   $('#artikel_wrapper').fadeOut(1000, resetBody);   
		   
		    
		}); 
				// de fotolinks gekoppelt a/d foto's
			
			  $('a.foto_link').click(function(e) 
			  {   
			   
			   //Cancel the link behavior   
			   e.preventDefault();   
			    
				showMask('#foto_mask');  
			   
				//Get the window height and width   
				var winH = $(window).height();   
				var winW = $(window).width();   
						 
			   //Set the popup window to center   
				$('#foto_wrapper').css('top', ( winH/2-$('#foto_wrapper').height()/2) + $(window).scrollTop());   
			   $('#foto_wrapper').css('left', winW/2-$('#foto_wrapper').width()/2);   
			   
			   $("#foto_window").hide();
			   $("#foto_loading").show();
				//transition effect   
			   $('#foto_wrapper').fadeIn(2000);   
			   
			  $('#foto_window').load('fotoboek.php?fotoboek_id=' + $(this).attr('id'), function() {
				  $('#foto_loading').hide();
  					$('#foto_window').fadeIn(1000);    
				});
				
			  });
				
		
		 //if mask is clicked   
		$('#foto_mask').click(function () {   
			$('#foto_mask').fadeOut(1000);   
		   
		    $('#foto_wrapper').fadeOut(1000, resetBody);    
			
		});
		
		
		// de thema projectlinks gekoppelt a/d themas zelf
		
			
			  $('a.thema_project_link').click(function(e) 
			  {   
			   
			   //Cancel the link behavior   
			   e.preventDefault();   
			 
				showMask('#thema_project_mask');
			   
			   
				//Get the window height and width   
				var winH = $(window).height();   
				var winW = $(window).width();   
						 
			   //Set the popup window to center   
				$('#thema_project_wrapper').css('top', ( winH/2-$('#project_wrapper').height()/2) + $(window).scrollTop());   
			   $('#thema_project_wrapper').css('left', winW/2-$('#project_wrapper').width()/2);   
			   
			   $("#thema_project_window").hide();
			   $("#thema_project_loading").show();
				//transition effect   
			   $('#thema_project_wrapper').fadeIn(2000);   
			   
			   
			  $('#thema_project_window').load('thema.php?id=' + $(this).attr('id'), function() {
				  $('#thema_project_loading').hide();
  					$('#thema_project_window').fadeIn(1000);    
				});
			  	
			  });
				
				
				 //if mask is clicked   
		$('#thema_project_mask').click(function () {   
			$('#thema_project_mask').fadeOut(1000);   
		   $('#thema_project_wrapper').fadeOut(1000, resetBody);
		   
		     
		});  
			
		
		//$(window).bind('resize', repositionFooter);
			//repositionFooter();
	
		
		
		// hebben we nog een extra code ivm het meteen tonen van een fotoboek of project
		
		var what = $.PODgetUrlVar('what');
		var id2 =  $.PODgetUrlVar('id2');
		if (what != "")
		{
			
			
			switch (what)
			{
				case 'fb':
					$('#' + id2).trigger('click');
					break;
					
				case 'proj':
					showProject(id2);
					break;
					
			}
		}
		
		}

 	);
	
	function showThemaProject(p_id)
	{
						    $('#thema_project_window').load('thema_project.php?id=' + p_id, function() {
				 // doe niets (reload)
				}); 
				   
			
	}
	
	function sluitProjectWindow()
	{	  
		$('#project_mask').fadeOut(1000);   
		$('#project_wrapper').fadeOut(1000, resetBody); 
	}
	
	function sluitThemaProjectWindow()
	{	  
		$('#thema_project_mask').fadeOut(1000);   
		$('#thema_project_wrapper').fadeOut(1000, resetBody);
	}
	
	function sluitFotoWindow()
	{  
			$('#foto_mask').fadeOut(1000);   
		   $('#foto_wrapper').fadeOut(1000, resetBody);     
	}
	
	function sluitArtikelWindow()
	{  
			$('#artikel_mask').fadeOut(1000);   
		   $('#artikel_wrapper').fadeOut(1000, resetBody);     
	}
	
	function resetBody()
	{
		  //$('body').css({'overflow':'auto'});
	}
	
	function loadFoto(p_fotoboek_id, p_foto_index)
	{
		 $('#foto_window').load('fotoboek.php?fotoboek_id=' + p_fotoboek_id + "&foto_index=" + p_foto_index);
	}
		
	function repositionFooter()
	{
		// we willen nu eventueel de footer groter hebben ivm de backimage
			var win_h;
			var body_h;
			
			win_h = $(window).height();
			body_h = $(document.body).height();
				
			if (win_h > body_h)
			{
				
				$('#footer').height($('#footer').height()+ (win_h - body_h) ) ;			
			}
	}
 
 

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' is geen e-mail adres.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is verplicht.\n'; }
  } if (errors) alert('Gegevens niet verzonden:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function valContactForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=valContactForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' is geen e-mail adres.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is verplicht.\n'; }
  } if (errors) 
 
  		alert('Gegevens niet verzonden:\n'+errors);
  if (errors == '')
	
		{
			
			document.frm_contact.submit();
		}
  document.MM_returnValue = (errors == '');
}

function contactForm()
{
	
	
	
	valContactForm('naam','','R','email','','RisEmail','vraag','','R');
}

