// JavaScript Document

var debug = false;
var balk = 0;
var old = 0;
var balkopen = 375;
var balkstep = 15;
var maxbalk = 5;
var speed = 10;
var acceptclicks = true;

function openbalk(x,y) {
	old = balk;
	balk = x;
	
	if(debug) {
		if(y && old==x) {
			alert('Veranderen van content naar sub '+y);
		} else {
			if(old && old!=x) alert('Sluiten van '+old+' en openen van '+x);
			if(old && old==x) alert('Sluiten van '+old);
			if(!old && old!=x) alert('Openen van '+x);
		}
	}
	
	if(y && old==x) {
		goTo(x,y)
	} else {
		if(old && old!=x) _closebalk(old,x,y);
		if(old && old==x) _closebalk(old);
		if(!old && old!=x) _openbalk(x,y);	
	}
}

function goTo(c,i) {
	loadDoc('/site/content.php?cat='+c+'&id='+i,'innercontent'+c);
}

function _openinstant(i,i2,ns) {
	balk = i
	w = 0;
	
	loadDoc('/site/content.php?cat='+i+'&id='+i2+'&ns='+ns,'innercontent'+i);
	w += balkopen; 
	document.getElementById('content'+i).style.width = w+'px';
		
	for(j=i+1;j<=maxbalk;j++) {
		y = parseInt(document.getElementById('bar'+j).style.left);
		y += balkopen;
		document.getElementById('bar'+j).style.left = y+'px';
		y += 100;
		document.getElementById('content'+j).style.left = y+'px';
	}
		
}

function _openbalk(i,i2) {	

	if(!acceptclicks) return;
	acceptclicks = false;

	balk = i
	w = 0;
	
	
	_openInterval = window.setInterval(function () {
		w += balkstep; 
		document.getElementById('content'+i).style.width = w+'px';
		
		for(j=i+1;j<=maxbalk;j++) {
			y = parseInt(document.getElementById('bar'+j).style.left);
			y += balkstep;
			document.getElementById('bar'+j).style.left = y+'px';
			y += 100;
			document.getElementById('content'+j).style.left = y+'px';
		}
		
		if(w>=balkopen) {
			clearInterval(_openInterval);
			if(i2) {
				loadDoc('/site/content.php?cat='+i+'&id='+i2,'innercontent'+i);
			} else {
				loadDoc('/site/content.php?cat='+i,'innercontent'+i);
			}

			acceptclicks = true;

			//alert('openbalk '+i+' ready');
		}
	},speed);
}

function _closebalk(i,i2,i3) {

	if(!acceptclicks) return;
	acceptclicks = false;

	balk = 0;
	w = balkopen;

	document.getElementById('innercontent'+i).innerHTML = "";
	
	_closeInterval = window.setInterval(function () {
		w -= balkstep; 
		document.getElementById('content'+i).style.width = w+'px';
		
		for(j=i+1;j<=maxbalk;j++) {
			y = parseInt(document.getElementById('bar'+j).style.left);
			y -= balkstep;
			document.getElementById('bar'+j).style.left = y+'px';
			y += 100;
			document.getElementById('content'+j).style.left = y+'px';
		}
		

		if(w<=0) {
			clearInterval(_closeInterval);
			
			for(j=1;j<=maxbalk;j++) {
				y = (j-1)*100;
				document.getElementById('bar'+j).style.left = y+'px';
				y = j*100;
				document.getElementById('content'+j).style.left = y+'px';
			}

			document.getElementById('innercontent'+i).innerHTML = "<br /><br /><img src='/site/gfx/loading.gif' />";
			acceptclicks = true;

			//alert('closebalk '+i+' ready');
			if(i2) _openbalk(i2,i3);
		}
	},speed);
}

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
@else
	xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp = false;
	}
}
 
function loadDoc(docname, id) {
	if (xmlhttp) {
		xmlhttp.open("GET",docname,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if(document.getElementById(id)) document.getElementById(id).innerHTML=xmlhttp.responseText;
			}
		}
		xmlhttp.send(null)
	}
}
 
function loadDocValue(docname, id) {
	if (xmlhttp) {
		xmlhttp.open("GET",docname,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if(document.getElementById(id)) document.getElementById(id).value=xmlhttp.responseText;
			}
		}
		xmlhttp.send(null)
	}
}

function openSite(URLStr)
{
    var maxx = screen.width;
    var maxy = screen.height;
    windowprops = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=100,height=100,left=100,top=100";
    window.open(URLStr+"&maxx="+maxx+"&maxy="+maxy,"",windowprops);
}

function subscribe() {
	document.getElementById('result').innerHTML = 'Een moment. Uw aanmelding wordt verzonden...';
	fullname = document.getElementById('fullname').value
	emailadres = document.getElementById('emailadres').value
	loadDoc('/site/subscribe.php?mail='+emailadres+'&fullname='+fullname,'result');
}
