var SifrAanHetLaden = '2';
var PortfolioZichtbaar = '2';
var PortfolioActief = '2';
var URL = '';
var ID = '';
var IDLinks = '';
var IDRechts = '';
var PaginaHoogte = '';

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function LaadSifr(){
}

function getPaginaGrootte(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	pageWidth = xScroll;
	pageHeight = yScroll;
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function getPaginaScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function ToonMelding(Pagina){
	var arrayPageSizes = getPaginaGrootte();
	var PaginaHoogte = (arrayPageSizes[1]+"px");
	var PaginaBreedte = (arrayPageSizes[0]+"px");
	
	//document.getElementById('GaSnelNaar').style.visibility = 'hidden';
	document.getElementById('DivAlertBoxAchtergrond').style.height = PaginaHoogte;
	document.getElementById('DivAlertBoxAchtergrond').style.width = PaginaBreedte;
	
	LaadMeldingInDiv(Pagina, 'DivAlertBoxContent');
	
	var NieuweBreedteDiv = 600;
	var NieuweHoogteDiv = 200;
	
	arrayPageScroll = getPaginaScroll();
	
	var TopPositie = arrayPageScroll[1] + (arrayPageSizes[1] / 15);
	TopPositie = TopPositie+'px';
	document.getElementById('DivAlertBoxContent').style.top = TopPositie;
	
	var LinkerPositie = ((arrayPageSizes[0] - NieuweBreedteDiv)/2);
	LinkerPositie = LinkerPositie+'px';
	document.getElementById('DivAlertBoxContent').style.left = LinkerPositie;
}

function ToonNieuwsbrief(Pagina){
	var arrayPageSizes = getPaginaGrootte();
	var PaginaHoogte = (arrayPageSizes[1]+"px");
	var PaginaBreedte = (arrayPageSizes[0]+"px");
	
	//document.getElementById('GaSnelNaar').style.visibility = 'hidden';
	document.getElementById('DivAlertBoxAchtergrond').style.height = PaginaHoogte;
	document.getElementById('DivAlertBoxAchtergrond').style.width = PaginaBreedte;

	LaadMeldingInDiv(Pagina, 'DivAlertBoxContent');
	
	var NieuweBreedteDiv = 750;
	var NieuweHoogteDiv = 200;
	
	arrayPageScroll = getPaginaScroll();
	
	var TopPositie = arrayPageScroll[1] + (arrayPageSizes[1] / 15);
	TopPositie = TopPositie+'px';
	document.getElementById('DivAlertBoxContent').style.top = TopPositie;
	
	var LinkerPositie = ((arrayPageSizes[0] - NieuweBreedteDiv)/2);
	LinkerPositie = LinkerPositie+'px';
	document.getElementById('DivAlertBoxContent').style.left = LinkerPositie;
}

function LaadMeldingInDiv(option, DivID) {
	var urls = option;
	if(window.XMLHttpRequest) {
		reqss = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		reqss = new ActiveXObject("Microsoft.XMLHTTP");
	}
	reqss.open("GET", urls, true);
	reqss.onreadystatechange = callbackMelding;
	
	reqss.send(null);
}

function callbackMelding(DivID) {
	if(reqss.readyState != 4) { 
		document.getElementById('DivAlertBoxContent').innerHTML = '';
	}
	
	if(reqss.readyState == 4) {
		if(reqss.status == 200) {
			response = reqss.responseText;
			var arrayPageSizes = getPaginaGrootte();
			PaginaHoogte = arrayPageSizes[1];
			document.getElementById('DivAlertBoxContent').innerHTML = response;
			$('#DivAlertBoxAchtergrond').fadeIn(300, function(){
				$('#DivAlertBoxContent').fadeIn(300,function(){
					
					
					if(PaginaHoogte < document.getElementById('DivAlertBoxContent').offsetHeight){
						document.getElementById('DivAlertBoxAchtergrond').style.height = ((document.getElementById('DivAlertBoxContent').offsetHeight * 1) + 300) + 'px';
					}
//					LaadSifr();
					FontReplace();
					$('img[@src$=.png]').ifixpng();
				});
			});
			
		} else {

		}
	}
}

function MeldingSluiten(Pagina){
	$('#DivAlertBoxContent').fadeOut(300, function() {
		$('#DivAlertBoxAchtergrond').fadeOut(300);
	});
}

function LaadPortfolio(option) {
	var urls = option;
	if(window.XMLHttpRequest) {
		reqPortfolio = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		reqPortfolio = new ActiveXObject("Microsoft.XMLHTTP");
	}
	reqPortfolio.open("GET", urls, true);
	reqPortfolio.onreadystatechange = callbackPortfolio;
	
	reqPortfolio.send(null);
}

function callbackPortfolio() {
	if(reqPortfolio.readyState == 4) {
		if(reqPortfolio.status == 200) {
			response = reqPortfolio.responseText;
			document.getElementById('PortfolioContainer').innerHTML = response;
			
			if(PortfolioZichtbaar == '2'){
				$('#PortfolioContainer').fadeIn('300');
				PortfolioZichtbaar = '1';
			}
		}
	}
}

function PortfolioVolgende() {
	if(PortfolioActief == '2'){
		PortfolioActief = '1';
		var BreedteTotaal = document.getElementById('PortfolioBreedte').value;
		var Positie = document.getElementById('PortfolioItems').offsetLeft;
		var MaxPositie = BreedteTotaal;
		
		var PositieNieuw = ((Positie * 1) - 900);
		if(PositieNieuw <= MaxPositie){
			PositieNieuw = '0';
		}
		PositieNieuw = PositieNieuw + 'px';
		$('#PortfolioItems').animate({left: PositieNieuw}, 1000, function(){
			PortfolioActief = '2';
		});
	}
}

function PortfolioVorige() {
	if(PortfolioActief == '2'){
		PortfolioActief = '1';
		var BreedteTotaal = document.getElementById('PortfolioBreedte').value;
		var Positie = document.getElementById('PortfolioItems').offsetLeft;
		var MaxPositie = BreedteTotaal;
		
		var PositieNieuw = ((Positie * 1) + 900);
		if(PositieNieuw > '0'){
			var TotaalPaginas = (Math.round(((BreedteTotaal * 1) / 900)) + 1);
			var Test = ((TotaalPaginas * 900) - 900);
			if(Test > BreedteTotaal){
				TotaalPaginas = (Math.round(((BreedteTotaal * 1) / 900)));
			}
			
			PositieNieuw = ((TotaalPaginas * 1) * 900);
		}
		PositieNieuw = PositieNieuw + 'px';
		$('#PortfolioItems').animate({left: PositieNieuw}, 1000, function(){
			PortfolioActief = '2';
		});
	}
}

function FilterPortfolio(Optie){
	URL = Optie;
	$('#DivPortfolioLaden').fadeTo(50, 0.01, function(){
		document.getElementById('DivPortfolioLaden').style.zIndex = '10';
		$('#DivPortfolioLaden').fadeTo(350, 0.7, function(){
			
		});
		$('#PortfolioItems').animate({left: '0px'}, 500, function(){
				var urls = URL;
				if(window.XMLHttpRequest) {
					reqPortfolio = new XMLHttpRequest();
				} else if(window.ActiveXObject) {
					reqPortfolio = new ActiveXObject("Microsoft.XMLHTTP");
				}
				reqPortfolio.open("GET", urls, true);
				reqPortfolio.onreadystatechange = callbackPortfolioFilter;
				
				reqPortfolio.send(null);
			});
	});
}
function callbackPortfolioFilter() {
	if(reqPortfolio.readyState == 4) {
		if(reqPortfolio.status == 200) {
			response = reqPortfolio.responseText;
			document.getElementById('PortfolioContainer').innerHTML = response;
			$('#DivPortfolioLaden').fadeTo(350, 0.0, function(){
				document.getElementById('DivPortfolioLaden').style.zIndex = '-10';
			});
		}
	}
}

function Flip(DivID, DivTekstID, DivKlikID){
	document.getElementById(DivKlikID).style.zIndex = '7';
	$('#' + DivTekstID).fadeTo(50, 0.01, function(){
		document.getElementById(DivTekstID).style.zIndex = '6';
		$('#' + DivTekstID).fadeTo(350, 1);
	});
	$('#' + DivID).fadeTo(50, 0.01, function(){
		document.getElementById(DivID).style.zIndex = '5';
		$('#' + DivID).fadeTo(350, 0.7);
	});
}

function FlipBack(DivID, DivTekstID, DivKlikID){
	document.getElementById(DivKlikID).style.zIndex = '-10';
	$('#' + DivTekstID).fadeTo(350, 0.01, function(){
		document.getElementById(DivTekstID).style.zIndex = '-10';
	});
	$('#' + DivID).fadeTo(350, 0.01, function(){
		document.getElementById(DivID).style.zIndex = '-10';
	});
}

function PortfolioDetails(IDNieuw){
	ID = IDNieuw;
	var Totaal = document.getElementById('PortfolioTotaal').value;
	
	if(ID == '0'){
		IDLinks = ((Totaal * 1) - 1);
	} else {
		IDLinks = ((ID * 1) - 1);
	}
	IDRechts = ((ID * 1) + 1);
	if(IDRechts >= Totaal){
		IDRechts = '0';
	}
	if(document.getElementById('PortfolioDetail' + ID).innerHTML == ''){
		var urls = URLPref + 'inc_portfoliodetails.php?Nav=' + ID;
		if(window.XMLHttpRequest) {
			reqPortfolioID = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			reqPortfolioID = new ActiveXObject("Microsoft.XMLHTTP");
		}
		reqPortfolioID.open("GET", urls, true);
		reqPortfolioID.onreadystatechange = callbackPortfolioID;
		
		reqPortfolioID.send(null);
	} else {
		// GEVRAAGDE PORTFOLIOITEM IS AL GELADEN, TOON DETAILS
		var PositieNieuw = (878 * ID);
		PositieNieuw = '-' + PositieNieuw + 'px';		
		$('#DivPortfolioScrollerContent').animate({left: PositieNieuw}, 50, function(){
			ToonPortfolioDetails();
		});
	}
	
	LaadDetailsRechts();
	LaadDetailsLinks();
	
}

function ToonPortfolioDetails(){
	/*$('#PortfolioDetailsContainer').slideDown(750, function(){
		LaadSifr();
	});*/
	document.getElementById('PortfolioDetailsContainer').style.display = 'block';
//	LaadSifr();
	FontReplace();
	$('img[@src$=.png]').ifixpng();

}

function SluitPortfolioDetails(){
	/*$('#PortfolioDetailsContainer').slideUp(750);*/
	document.getElementById('PortfolioDetailsContainer').style.display = 'none';
}

/* SCROLL DE DETAILS NAAR LINKS EN RECHTS */

function PortfolioDetailsLinks(){
	var Totaal = document.getElementById('PortfolioTotaal').value;
	
	ID = IDLinks;
	if(ID == '0'){
		IDLinks = ((Totaal * 1) - 1);
	} else {
		IDLinks = ((ID * 1) - 1);
	}
	
	IDRechts = ((ID * 1) + 1);
	if(IDRechts >= Totaal){
		IDRechts = '0';
	}
	
	var PositieNieuw = (878 * ID);
	PositieNieuw = '-' + PositieNieuw + 'px';
	$('#DivPortfolioScrollerContent').animate({left: PositieNieuw}, 750);
	LaadDetailsLinks();
}

function PortfolioDetailsRechts(){
	var Totaal = document.getElementById('PortfolioTotaal').value;
	
	ID = IDRechts;
	if(ID == '0'){
		IDLinks = ((Totaal * 1) - 1);
	} else {
		IDLinks = ((ID * 1) - 1);
	}
	IDRechts = ((ID * 1) + 1);
	if(IDRechts >= Totaal){
		IDRechts = '0';
	}
	
	var PositieNieuw = (878 * ID);
	PositieNieuw = '-' + PositieNieuw + 'px';
	$('#DivPortfolioScrollerContent').animate({left: PositieNieuw}, 750);
	LaadDetailsRechts();
}



function LaadDetailsRechts(){
	/* LAAD ALVAST HET RECHTER VLAK */
	if(document.getElementById('PortfolioDetail' + IDRechts).innerHTML == ''){
		var urls = URLPref + 'inc_portfoliodetails.php?Nav=' + IDRechts;
		if(window.XMLHttpRequest) {
			reqPortfolioIDRechts = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			reqPortfolioIDRechts = new ActiveXObject("Microsoft.XMLHTTP");
		}
		reqPortfolioIDRechts.open("GET", urls, true);
		reqPortfolioIDRechts.onreadystatechange = callbackreqPortfolioIDRechts;
		
		reqPortfolioIDRechts.send(null);
	}
}

function LaadDetailsLinks(){
	/* LAAD ALVAST HET LINKER VLAK */
	
	if(document.getElementById('PortfolioDetail' + IDLinks).innerHTML == ''){
		var urls = URLPref + 'inc_portfoliodetails.php?Nav=' + IDLinks;
		if(window.XMLHttpRequest) {
			reqPortfolioIDLinks = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			reqPortfolioIDLinks = new ActiveXObject("Microsoft.XMLHTTP");
		}
		reqPortfolioIDLinks.open("GET", urls, true);
		reqPortfolioIDLinks.onreadystatechange = callbackreqPortfolioIDLinks;
		
		reqPortfolioIDLinks.send(null);
	}
}

function callbackPortfolioID() {
	if(reqPortfolioID.readyState == 4) {
		if(reqPortfolioID.status == 200) {
			response = reqPortfolioID.responseText;
			document.getElementById('PortfolioDetail' + ID).innerHTML = response;
			
			var PositieNieuw = (878 * ID);
			PositieNieuw = '-' + PositieNieuw + 'px';
			$('#DivPortfolioScrollerContent').animate({left: PositieNieuw}, 50, function(){
				ToonPortfolioDetails();
			});
		}
	}
}

function callbackreqPortfolioIDRechts() {
	if(reqPortfolioIDRechts.readyState == 4) {
		if(reqPortfolioIDRechts.status == 200) {
			response = reqPortfolioIDRechts.responseText;
			document.getElementById('PortfolioDetail' + IDRechts).innerHTML = response;
//			LaadSifr();
			FontReplace();
			$('img[@src$=.png]').ifixpng();

		}
	}
}

function callbackreqPortfolioIDLinks() {
	if(reqPortfolioIDLinks.readyState == 4) {
		if(reqPortfolioIDLinks.status == 200) {
			response = reqPortfolioIDLinks.responseText;
			document.getElementById('PortfolioDetail' + IDLinks).innerHTML = response;
//			LaadSifr();
			FontReplace();
			$('img[@src$=.png]').ifixpng();
		}
	}
}

function AanmeldenNieuwsbrief(){
	if(document.getElementById('EmailAdresNieuwsbrief').value == ''){
		document.getElementById('EmailAdresNieuwsbrief').style.backgroundColor = '#cc0000';
	} else {
		if(document.getElementById('NieuwsbriefAanmelden').checked == true){
			var AanAfmelden = '1';
		} else {
			var AanAfmelden = '2';
		}
		var URL = URLPref + 'nieuwsbrief.php?Email=' + document.getElementById('EmailAdresNieuwsbrief').value + '&GroepID=' + document.getElementById('NieuwsbriefGebruikersGroepID').value + '&AanAfmelden=' + AanAfmelden;
		LaadNieuwsbrief(URL);
	}
}

function LaadNieuwsbrief(Optie){
	var urls = Optie;
	if(window.XMLHttpRequest) {
		reqNieuwsbrief = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		reqNieuwsbrief = new ActiveXObject("Microsoft.XMLHTTP");
	}
	reqNieuwsbrief.open("GET", urls, true);
	reqNieuwsbrief.onreadystatechange = callbackNieuwsbrief;
	
	reqNieuwsbrief.send(null);
}
function callbackNieuwsbrief() {
	if(reqNieuwsbrief.readyState == 4) {
		if(reqNieuwsbrief.status == 200) {
			response = reqNieuwsbrief.responseText;
			document.getElementById('DivNieuwsbrief').innerHTML = response;
		}
	}
}

function FontReplace(){
	Cufon.replace('h1', { fontFamily: 'HelveticaLight' });
	Cufon.replace('h2', { fontFamily: 'HelveticaLight' });
	Cufon.replace('h3', { fontFamily: 'HelveticaLight' });
}