var home;
var fotos;
var links;
var nuDataArray;
var divIdNu;
var jobNuPositie=0;
var maxRegelsNu;
var xmlhttp_data;
var xmlhttp_data_jobnu;
var xmlhttp_data_mail;
var xmlhttp_data_fotos;
var xmlhttp_data_fotos_productie;
var xmlhttp_data_links;
var xmlhttp_data_video;
var xmlhttp_aantal_regels_jobnu;

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp_data=new XMLHttpRequest();
	xmlhttp_data_jobnu=new XMLHttpRequest();
	xmlhttp_data_mail=new XMLHttpRequest();
	xmlhttp_data_fotos=new XMLHttpRequest();
	xmlhttp_data_fotos_productie=new XMLHttpRequest();
	xmlhttp_data_links=new XMLHttpRequest();
	xmlhttp_aantal_regels_jobnu=new XMLHttpRequest();
	xmlhttp_data_video=new XMLHttpRequest();
}
else
{// code for IE6, IE5
	xmlhttp_data=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp_data_jobnu=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp_data_mail=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp_data_fotos=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp_data_fotos_productie=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp_data_links=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp_aantal_regels_jobnu=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp_data_video=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp_data.onreadystatechange=function()
{
	if (xmlhttp_data.readyState==4 && xmlhttp_data.status==200)
	{
			document.getElementById("content").innerHTML=xmlhttp_data.responseText;
			if (home===true) {
				getAantalNuRegels();
				getDataJobNu(0);
				home=false;
			}
			if (fotos===true) {
				getDataFotos(1);
				getDataFotosProductie(1);
				fotos=false;
			}
			if (links===true) {
				getDataLinks(1);
				links=false;
			}
	}
}
xmlhttp_data_jobnu.onreadystatechange=function()
{
	if (xmlhttp_data_jobnu.readyState==4 && xmlhttp_data_jobnu.status==200)
	{
			document.getElementById("nuDoetJob_content").innerHTML = xmlhttp_data_jobnu.responseText;

				if (maxRegelsNu > 2 && home===true){
					document.getElementById("meerKnopNu").style.visibility="visible";
				}
	}
}
xmlhttp_data_fotos.onreadystatechange=function()
{
	if (xmlhttp_data_fotos.readyState==4 && xmlhttp_data_fotos.status==200)
	{
			fotoDataArray = eval(xmlhttp_data_fotos.responseText);
			fotoArrayPrinten();
	}
}
xmlhttp_data_fotos_productie.onreadystatechange=function()
{
	if (xmlhttp_data_fotos_productie.readyState==4 && xmlhttp_data_fotos_productie.status==200)
	{
			fotoProductieDataArray = eval(xmlhttp_data_fotos_productie.responseText);
			fotoProductieArrayPrinten();
	}
}
xmlhttp_data_mail.onreadystatechange=function()
{
	if (xmlhttp_data_mail.readyState==4 && xmlhttp_data_mail.status==200)
	{
			document.getElementById("errorMail").innerHTML=xmlhttp_data_mail.responseText;
	}
}
xmlhttp_data_links.onreadystatechange=function()
{
	if (xmlhttp_data_links.readyState==4 && xmlhttp_data_links.status==200)
	{
			document.getElementById("links_omhullend").innerHTML=xmlhttp_data_links.responseText;
	}
}
xmlhttp_data_video.onreadystatechange=function()
{
	if (xmlhttp_data_video.readyState==4 && xmlhttp_data_video.status==200)
	{
			document.getElementById("content").innerHTML=xmlhttp_data_video.responseText;
	}
}

function getAantalNuRegels()
{
		xmlhttp_aantal_regels_jobnu.open("POST","include/php/nuRegelsOphalen.php",false);
		xmlhttp_aantal_regels_jobnu.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_aantal_regels_jobnu.send();
		maxRegelsNu = xmlhttp_aantal_regels_jobnu.responseText;
}
function getData(menuKnop)
{
		menuKnopNummer = menuKnop;
		xmlhttp_data.open("POST","include/php/dataOphalen.php",true);
		xmlhttp_data.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_data.send("i="+ menuKnopNummer);
}
function getDataJobNu(jobNuDivStartMysqlId)
{
		jobNuPositie = jobNuDivStartMysqlId;
		jobNuPositie++;
		xmlhttp_data_jobnu.open("POST","include/php/dataOphalenJobNu.php",false);
		xmlhttp_data_jobnu.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		if (jobNuPositie==maxRegelsNu) {
			var roll=1;
		}
		xmlhttp_data_jobnu.send("i="+ jobNuPositie +"&r="+ roll);
		
		document.getElementById("nuDoetJob_content").innerHTML = xmlhttp_data_jobnu.responseText;
				if (maxRegelsNu > 2 && home===true){
					document.getElementById("meerKnopNu").style.visibility="visible";
				}
			if (jobNuPositie==maxRegelsNu){
				jobNuPositie=0;
			}
}
function getDataFotos(fotosDivStartMysqlId)
{
		xmlhttp_data_fotos.open("POST","include/php/dataOphalenFotos.php",true);
		xmlhttp_data_fotos.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_data_fotos.send("i="+ fotosDivStartMysqlId);
}
function getDataFotosProductie(fotosProductieDivStartMysqlId)
{
		xmlhttp_data_fotos_productie.open("POST","include/php/dataOphalenFotosProductie.php",true);
		xmlhttp_data_fotos_productie.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_data_fotos_productie.send("i="+ fotosProductieDivStartMysqlId);
}
function getDataLinks(linksDivStartMysqlId)
{
		xmlhttp_data_links.open("POST","include/php/dataOphalenLinks.php",true);
		xmlhttp_data_links.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_data_links.send("i="+ linksDivStartMysqlId);
}
function getDataVideo()
{
		xmlhttp_data_video.open("POST","include/php/dataOphalenVideo.php",true);
		xmlhttp_data_video.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_data_video.send();
}
function nuDataArrayPrinten() {
		document.getElementById("nu_plaatje1").style.backgroundImage = "url(" + nuDataArray[0] +")";
		document.getElementById("nu_tekst1").innerHTML=nuDataArray[1];
		document.getElementById("nu_plaatje2").style.backgroundImage = "url(" + nuDataArray[2] +")";
		document.getElementById("nu_tekst2").innerHTML=nuDataArray[3];
}

function fotoArrayPrinten() {
		var titel;	
		for (var i = 1; i < 9; i++ ) {
			titel = fotoDataArray[ ((4 * (i+8)) - 2) ];
			if (titel!=="<span class=foto_titel></span>" && typeof(titel)!="undefined") {
				document.getElementById("vorigeFotoKnopCasting").style.display = "block";
				document.getElementById("volgendeFotoKnopCasting").style.display = "block";
				break;
			}
		}
		for (var i = 1; i < 9; i++ ) {
		if(fotoDataArray[ ((4 * i) - 2) ]=="<span class=foto_titel></span>"){
			document.getElementById("c" + i).innerHTML = "";
		}else {
			document.getElementById('c' + i).innerHTML = '<span id="fotoTiteldiv' + i + '"></span><br /><img src="' + fotoDataArray[ ((4 * i) - 4) ] +'">';
			document.getElementById("fotoTiteldiv" + i).innerHTML = fotoDataArray[ ((4 * i) - 2) ];
		}
			if (document.links){
				document.getElementById("casting" + i).setAttribute("href", fotoDataArray[ ((4 * i) - 3) ]);
			}

		}
}
function fotoProductieArrayPrinten() {
		var titel;
		for (var i = 1; i < 9; i++ ) {
			titel = fotoProductieDataArray[ ((4 * (i+8)) - 2) ];
			if (titel!=="<span class=foto_titel></span>" && typeof(titel)!="undefined") {
				document.getElementById("vorigeFotoKnopProductie").style.display = "block";
				document.getElementById("volgendeFotoKnopProductie").style.display = "block";
				break;
			}
		}
		for (var i = 1; i < 9; i++ ) {
		
		if(fotoProductieDataArray[ ((4 * i) - 2) ]=="<span class=foto_titel></span>"){
			document.getElementById("p" + i).innerHTML = "";
		}else {
			document.getElementById("p" + i).innerHTML = '<span id="fotoTiteldivp' + i +'"></span>ljfa<br /><img src="' + fotoProductieDataArray[ ((4 * i) - 4) ] +'">';
			document.getElementById("fotoTiteldivp" + i).innerHTML = fotoProductieDataArray[ ((4 * i) - 2) ];
		}
			if (document.links){
				document.getElementById("productie" + i).setAttribute("href", fotoProductieDataArray[ ((4 * i) - 3) ]);
			}
		}
}
function verwerkMail(form)
{
		var formArray = new Array (4);
		formArray[0] = form.naam.value;
		formArray[1] = form.afzender.value;
		formArray[2] = form.subject.value;
		formArray[3] = form.tekst.value;
		
		xmlhttp_data_mail.open("POST","include/php/contact.php",true);
		xmlhttp_data_mail.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp_data_mail.send("i="+ formArray);
}
function showThumb(fotoNummer) {
	document.getElementById("showFotoWrapper").style.display = "block";
	document.getElementById("showFotoRef").style.display = "block";
	document.getElementById("thumbShow").src = fotoDataArray[ ((4 * fotoNummer) - 3) ];
	if (fotoDataArray[ ((4 * fotoNummer) - 1) ]!="") {
		document.getElementById("showFotoTitel").innerHTML = "Foto: " + fotoDataArray[ ((4 * fotoNummer) - 1) ];
	}	
	return false;
}
function showThumbProductie(fotoNummer) {
	document.getElementById("showFotoWrapper").style.display = "block";
	document.getElementById("showFotoRef").style.display = "block";
	document.getElementById("thumbShow").src = fotoProductieDataArray[ ((4 * fotoNummer) - 3) ];
	if (fotoProductieDataArray[ ((4 * fotoNummer) - 1) ] != "") {
		document.getElementById("showFotoTitel").innerHTML = "Foto: " + fotoProductieDataArray[ ((4 * fotoNummer) - 1) ];
	}
	return false;
}
function hideThumb() {
	document.getElementById("showFotoWrapper").style.display = "none";
	document.getElementById("showFotoRef").style.display = "none";
	document.getElementById("thumbShow").src = "#";
	document.getElementById("showFotoTitel").innerHTML = "";
	return false;
}

