// JavaScript Document

function fotografie(){
	$('#fotografie .portfolioContent .list a').click(function(event){
		event.preventDefault();
		var newId = this['id'];
		newId= newId.replace(newId.charAt(0), "");
		$.ajax({
		   type: "GET",
		   url: "ajax/ajax.php?type=fotografie&id="+newId,
		   success: function(var1){
			   var myArray = var1.split('|');
			   myArray.join(', ');
			 $('#fotografie .portfolioContent .itemTitle h2').replaceWith('<h2>'+myArray[0]+'</h2>');
			 $('#fotografie .portfolioContent .item img').replaceWith('<img src="images/portfolio/'+myArray[1]+'" alt="'+myArray[0]+'"/>');
			 $('#fotografie .portfolioContent .description p').replaceWith('<p>'+myArray[2]+'</p>');
		   },
		   error:function (xhr, ajaxOptions, thrownError){
				alert(xhr.status);
				alert(thrownError);
           }
		 });
	});	
}

function multiMedia(){
	$('#multimedia .portfolioContent .list a').click(function(event){
		event.preventDefault();
		var newId = this['id'];
		newId= newId.replace(newId.charAt(0), "");
		$.ajax({
			type: "GET",
			url: "ajax/ajax.php?type=multimedia&id="+newId,
			success: function(var1){
				var myArray = var1.split('|');
				myArray.join(', ');
				$('#multimedia .portfolioContent .itemTitle h2').replaceWith('<h2>'+myArray[0]+'</h2>');
				if(myArray[5] == "video"){
					$('#multimedia .portfolioContent .item').html('<div id="item"><object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="680" height="454"><param name="movie" value="swf/player.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="file=../video/'+myArray[1]+'&image=images/preview.jpg" /><object type="application/x-shockwave-flash" data="swf/player.swf" width="680" height="454"><param name="movie" value="swf/player.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="file=../video/'+myArray[1]+'&image=images/preview.jpg" /><p><a href="http://get.adobe.com/flashplayer">Get Flash</a> to see this player.</p></object></object></div>');
				}else{
					$('#multimedia .portfolioContent .item').html('<div id="item"><img src="images/portfolio/'+myArray[1]+'" alt="'+myArray[0]+'"/></div>');
				}
				$('#multimedia .portfolioContent .description p').replaceWith('<p>'+myArray[2]+'</p>');
				$('#multimedia .portfolioContent .bezoek a').replaceWith('<a href="'+myArray[3]+'" target="_blank">&nbsp;Bezoek website&nbsp;</a>');
				if(myArray[3] == ""){
					$('#multimedia .portfolioContent .bezoek a').hide();
				}else{
					$('#multimedia .portfolioContent .bezoek a').show();
				}
				var newStr = "";
				for(var i=0; i<myArray[4]; i++){
					var j = i + 1;
					newStr = newStr+'<a href="#" name="ii'+newId+'" id="ai'+i+'">['+j+']</a> ';
				}
				$('#multimedia .portfolioContent .multiLinks span').html(newStr);
				$('#multimedia .portfolioContent .contentType span').replaceWith('<span>&nbsp;Type: '+myArray[5]+'&nbsp;<br />&nbsp;Technieken: '+myArray[6]+'&nbsp;</span>');
				mediaMultiLink();
		   },
		   error:function (xhr, ajaxOptions, thrownError){
				alert(xhr.status);
				alert(thrownError);
			  }
		 });
		});	
}

function analoog(){
	$('#analoog .portfolioContent .list a').click(function(event){
		event.preventDefault();
		var newId = this['id'];
		newId= newId.replace(newId.charAt(0), "");
		$.ajax({
		   type: "GET",
		   url: "ajax/ajax.php?type=analoog&id="+newId,
		   success: function(var1){
			   var myArray = var1.split('|');
			   myArray.join(', ');
			 $('#analoog .portfolioContent .itemTitle h2').replaceWith('<h2>'+myArray[0]+'</h2>');
			 $('#analoog .portfolioContent .item img').replaceWith('<img src="images/portfolio/'+myArray[1]+'" alt="'+myArray[0]+'"/>');
			 $('#analoog .portfolioContent .description p').replaceWith('<p>'+myArray[2]+'</p>');
			 	var newStr = "";
				for(var i=0; i<myArray[4]; i++){
				var j = i + 1;
				newStr = newStr+'<a href="#" name="ii'+newId+'" id="mi'+i+'">['+j+']</a> ';
				}
			 $('#analoog .portfolioContent .multiLinks span').html(newStr);
			 analoogMultiLink();
		   },
		   error:function (xhr, ajaxOptions, thrownError){
				alert(xhr.status);
				alert(thrownError);
           }
		 });
	});	
}

function mediaMultiLink(){
	$('#multimedia .portfolioContent .multiLinks span a').click(function(event){
		event.preventDefault();
		//alert(this['name']);
		var newId = this['id'];
		newId= newId.replace(newId.charAt(0), "");
		newId= newId.replace(newId.charAt(0), "");
		var newName = this['name'];
		newName= newName.replace(newName.charAt(0), "");
		newName= newName.replace(newName.charAt(0), "");
		//alert(newId);
		$.ajax({
		   type: "GET",
		   url: "ajax/ajaxItem.php?section=multimedia&ii="+newName+"&imgId="+newId,
		   success: function(var1){
			   //alert(var1);
			  $('#multimedia .portfolioContent .item img').replaceWith('<img src="images/portfolio/'+var1+'" alt="'+var1+'"/>');
		   },
		   error:function (xhr, ajaxOptions, thrownError){
				alert(xhr.status);
				alert(thrownError);
		   }
		 });
	});
};
function analoogMultiLink(){
	$('#analoog .portfolioContent .multiLinks span a').click(function(event){
		event.preventDefault();
		//alert(this['name']);
		var newId = this['id'];
		newId= newId.replace(newId.charAt(0), "");
		newId= newId.replace(newId.charAt(0), "");
		var newName = this['name'];
		newName= newName.replace(newName.charAt(0), "");
		newName= newName.replace(newName.charAt(0), "");
		//alert(newId);
		$.ajax({
		   type: "GET",
		   url: "ajax/ajaxItem.php?section=analoog&ii="+newName+"&imgId="+newId,
		   success: function(var1){
			   //alert(var1);
			  $('#analoog .portfolioContent .item img').replaceWith('<img src="images/portfolio/'+var1+'" alt="'+var1+'"/>');
		   },
		   error:function (xhr, ajaxOptions, thrownError){
				alert(xhr.status);
				alert(thrownError);
		   }
		 });
	});
};
function formSubmit(){
	$('#contact .myContent #contactContent #form1 #formOnd .error').hide();
	$('#contact .myContent #contactContent #form1 #formSend .error').hide();
	$('#contact .myContent #contactContent #form1 #formMsg .error').hide();
	$('#contact .myContent #contactContent #form1 #frmGetal .error').hide();
	$('#contact .myContent #contactContent #form1').submit(function(event){
		event.preventDefault();
		var sbj = $("#subject").val();
		var send = $("#sender").val();
		var msg = $("textarea").val();
		var getal = $("#getal").val();
		var cont = 0;
		if(sbj == ""){$('#contact .myContent #contactContent #form1 #formOnd .error').show("slow")}else{cont++};
		if(send == ""){$('#contact .myContent #contactContent #form1 #formSend .error').show("slow")}else{cont++};
		if(msg == ""){$('#contact .myContent #contactContent #form1 #formMsg .error').show("slow")}else{cont++};
		if(getal == "7" || getal == "zeven"){cont++}else{$('#contact .myContent #contactContent #form1 #frmGetal .error').show("slow")};
		if(cont == 4){
			$.ajax({
			   type: "GET",
			   url: "ajax/contactForm.php?subject="+sbj+"&msg="+msg+"&sender="+send,
			   success: function(var1){
				   if(var1 == 1){
					   $('#contact .myContent #contactContent #form1').hide("slow");
					   $('#formRetMess').html("Uw bericht:<br /><em>"+msg+"</em><br /><br />Met als onderwerp: <strong>"+sbj+"</strong><br />is verzonden.<br /><br />Dank u voor uw reactie.<br /><a href='#' id='formReset'>Nog een bericht plaatsen</a>");
					   $('#formRetMess').show("slow");
					   $('#formReset').click(function(event){
							event.preventDefault();
							$('#contact .myContent #contactContent #form1').show("slow");
							$('#contact .myContent #contactContent #formRetMess').hide("slow");
						});
				   }else{
					   $('#formRetMess').html("Er is iets mis gegaan. Probeert u het opnieuw.<br /> Mocht het probleem zich voor blijven doen.<br /> Gebruik dan uw normale e-mail programma.");
					   $('#formRetMess').show("slow");
				   }
			   },
			   error:function (xhr, ajaxOptions, thrownError){
					alert(xhr.status);
					alert(thrownError);
			   }
			 });
		}else{
			formSubmit()	
		}
	});
};
