// JavaScript Document

var nav_color = "white";

function doPosChangeMem(elem,startPos,endPos,steps,intervals,powr, page) {
	
	if (page != "fouradi") { 
		document.getElementById('subnavigation').style.display = "none";
		document.getElementById('lijntje').style.display = "none";
	}
	
	//Position changer with Memory by www.hesido.com
	if (elem.posChangeMemInt) window.clearInterval(elem.posChangeMemInt);
	var actStep = 0;
	elem.posChangeMemInt = window.setInterval(
											  
		function() {
			elem.currentPos = [
				easeInOut(startPos[0],endPos[0],steps,actStep,powr),
				easeInOut(startPos[1],endPos[1],steps,actStep,powr)
				];
			elem.style.left = elem.currentPos[0] + "px";
			elem.style.top = elem.currentPos[1] + "px";
			actStep++;
			if (actStep > steps) { 
				window.clearInterval(elem.posChangeMemInt); 
				getNavigation (page); 
				if (page == "fouradi") {
					
					document.getElementById('subnavigation').style.display = "block";
					document.getElementById('lijntje').style.display = "block"; 
					
				} else {
					
					document.getElementById('subnavigation').style.display = "none"; 
					document.getElementById('lijntje').style.display = "none"; 
					
				}
				
			}
			
		}
		,intervals);

}

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) { 

	//Generic Animation Step Value Generator By www.hesido.com 
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
    return Math.ceil(stepp);
	
} 
	
function moveToBottom (x, y, page) {
	
	var moveIt = document.getElementById('navigation');
	if (!moveIt.currentPos) moveIt.currentPos = [70,129]; //if no mem is set, set it first;
		doPosChangeMem(moveIt,moveIt.currentPos,[x,y],30,20,0.38, page);
}
	
function init() {

	var moveIt = document.getElementById('navigation');
	if (moveIt != null) moveIt.onclick = moveToBottom;
			
}

function getContent (page) {
	
	var xmlHttp;
	
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		
		catch (e) {
		
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
	
		}
    
	}
	
	xmlHttp.onreadystatechange=function() {
	
		if(xmlHttp.readyState==4) {

			document.getElementById('content').innerHTML=xmlHttp.responseText;
			do_sIFR(page);
			initLightbox();
		
        }
		
	}
	
    xmlHttp.open("GET","pages/content.php?page=" + page,true);
    xmlHttp.send(null);
	
}

function getNavigation (page) {
	
	var xmlHttp;
	
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		
		catch (e) {
		
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
	
		}
    
	}
	
	xmlHttp.onreadystatechange=function() {
	
		if(xmlHttp.readyState==4) {

			document.getElementById('navigation').innerHTML=xmlHttp.responseText;
			do_sIFR(page);
			initLightbox();
		
        }
		
	}
	
    xmlHttp.open("GET","pages/navigation.php?page=" + page,true);
    xmlHttp.send(null);
	
}

var http_request = false;
function makePOSTRequest(url, parameters) {
	
	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	
		http_request = new XMLHttpRequest();
		
		if (http_request.overrideMimeType) {
			
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
			
		}
		
	} else if (window.ActiveXObject) { // IE
	
		try {
			
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			
		} catch (e) {
			
			try {
				
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				
			} catch (e) {}
			
		}
		
	}
	
	if (!http_request) {
		
		alert('Cannot create XMLHTTP instance');
		return false;
		
	}
      
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);

}

function alertContents() {
	
	if (http_request.readyState == 4) {
		
		if (http_request.status == 200) {
			
			// alert(http_request.responseText);
			result = http_request.responseText;
			document.getElementById('guestbook_enter').innerHTML = result;            
			
		} else {
			
			alert('Hmmmrphff ... Daar ging iets fout!');
			
		}
		
	}
	
	getContent ('guestbook');
	
}

function makePOSTRequest2(url, parameters) {
	
	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	
		http_request = new XMLHttpRequest();
		
		if (http_request.overrideMimeType) {
			
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
			
		}
		
	} else if (window.ActiveXObject) { // IE
	
		try {
			
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			
		} catch (e) {
			
			try {
				
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				
			} catch (e) {}
			
		}
		
	}
	
	if (!http_request) {
		
		alert('Cannot create XMLHTTP instance');
		return false;
		
	}
      
	http_request.onreadystatechange = alertContents2;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);

}

function alertContents2() {
	
	if (http_request.readyState == 4) {
		
		if (http_request.status == 200) {
			
			// alert(http_request.responseText);
			result = http_request.responseText;
			document.getElementById('content').innerHTML=result;
			do_sIFR('nieuwsbrief');
			
		} else {
			
			alert('Hmmmrphff ... Daar ging iets fout!');
			
		}
		
	}
	
}
   
function get(obj, code) {
	
	if (code.toUpperCase() == document.getElementById("code").value.toUpperCase()) {
	
		var poststr = "page=gastenboek_add" +
					"&naam=" + encodeURI( document.getElementById("naam").value ) +
                    "&plaats=" + encodeURI( document.getElementById("plaats").value ) +
                    "&bericht=" + encodeURI( document.getElementById("bericht").value ) +
					"&code=" + encodeURI( document.getElementById("code").value );
					
		makePOSTRequest('pages/content.php', poststr);
		
	} else {
		
		alert ('Code komt niet overeen met het gegeven plaatje');
		
	}

}

function nieuwsbrief() {
	
	var error = '';
	if (document.getElementById("voornaam").value == '')
		error += "- Voornaam is verplicht\n";
	
	if (document.getElementById("achternaam").value == '')
		error += "- Achternaam is verplicht\n";
	
	if (document.getElementById("emailadres").value == '')
		error += "- E-mailadres is verplicht\n";
	
	if (error == '') {
	
		var poststr = "page=nieuwsbrief_add" +
					"&voornaam=" + encodeURI( document.getElementById("voornaam").value ) +
                    "&achternaam=" + encodeURI( document.getElementById("achternaam").value ) +
                    "&emailadres=" + encodeURI( document.getElementById("emailadres").value );
					
		makePOSTRequest2('pages/content.php', poststr);
		
	} else {
		
		alert ("De volgende fouten opgetreden:\n" + error);
		
	}

}

function getContentsub (page) {
	
	var xmlHttp;
	
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		
		catch (e) {
		
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
	
		}
    
	}
	
	xmlHttp.onreadystatechange=function() {
	
		if(xmlHttp.readyState==4) {

			document.getElementById('guestbook_enter').innerHTML=xmlHttp.responseText;
		
        }
		
	}
	
    xmlHttp.open("GET","pages/content_sub.php?page=" + page,true);
    xmlHttp.send(null);
	
}
  
function setContentLayer (x, y, w, h) {

	var element = document.getElementById('content');
	element.style.left = x + "px";
	element.style.top = y + "px";
	element.style.width = w + "px";
	element.style.height = h + "px";
	
	var element = document.getElementById('content_filler');
	element.style.left = (x-17) + "px";
	element.style.top = (y-20) + "px";
	element.style.width = (w+34) + "px";
	element.style.height = (h+40) + "px";
	
}

function setSubContentLayer (x, y) {

	var element = document.getElementById('guestbook_enter');
	element.style.left = x + "px";
	element.style.top = y + "px";
	
}

function goToPage (page) {
	
	if (page.match (/home.*?/))
		temp_page = "home";
	else if (page.match (/pics.*?/))
		temp_page = "pics";
	else if (page.match (/videotheek.*?/))
		temp_page = "videotheek";
	else if (page == "fouradi" || page == "djiszyhits" || page.match (/discografie.*/))
		temp_page = "fouradi";
	else if (page.match (/guestbook.*?/))
		temp_page = "guestbook";
	else
		temp_page = page;

	changeBG (temp_page == "nieuwsbrief" ? 'contact' : temp_page);
	changeLogo (temp_page == "nieuwsbrief" ? 'contact' : temp_page);
	
	if (temp_page == "home") {
		moveToBottom (70, 129, "home");
		setContentLayer (365, 92, 308, 464);
	} else if (temp_page == "fouradi") {
		moveToBottom (361, 355, "fouradi");
		setContentLayer (571, 71, 339, 489);
	} else if (temp_page == "agenda") {
		moveToBottom (243, 361, "agenda");
		setContentLayer (360, 125, 283, 430);
	} else if (temp_page == "pics") {
		moveToBottom (429, 228, "pics");
		setContentLayer (17, 79, 926, 105);
	} else if (temp_page == "guestbook") {
		moveToBottom (443, 79, "guestbook");
		setContentLayer (571, 71, 339, 489);
	} else if (temp_page == "videotheek") {
		moveToBottom (54, 96, "videotheek");
		setContentLayer (197, 88, 312, 464);
	} else if (temp_page == "fouradio") {
		moveToBottom (267, 203, "fouradio");
		setContentLayer (448, 270, 475, 289);
	} else if (temp_page == "links") {
		moveToBottom (358, 76, "links");
		setContentLayer (41, 69, 268, 341);
	} else if (temp_page == "contact") {
		moveToBottom (229, 311, "contact");
		setContentLayer (35, 79, 163, 381);
	} else if (temp_page == "nieuwsbrief") {
		moveToBottom (229, 311, "nieuwsbrief");
		setContentLayer (35, 79, 163, 381);
	}
	
	if (temp_page == "home")
		document.getElementById('logos').style.display = 'block';
	else
		document.getElementById('logos').style.display = 'none';
	
	if (temp_page == "guestbook") {
		
		setSubContentLayer (312, 347);
		document.getElementById('guestbook_filler').style.display = 'block';
		document.getElementById('guestbook_enter').style.display = 'block';
		
	} else if (temp_page == "pics") {
		
		setSubContentLayer (64, 224);
		document.getElementById('guestbook_filler').style.display = 'none';
		document.getElementById('guestbook_enter').style.display = 'block';
		
	} else {
		
		document.getElementById('guestbook_filler').style.display = 'none';
		document.getElementById('guestbook_enter').style.display = 'none';
		
	}
		
	getContent (page);
	
	if (temp_page == "guestbook")
		window.setTimeout (getContentsub, 100);
	else if (temp_page == "pics")
		getContentsub (page);
	
}

function changeBG (page) { document.getElementById('container').style.backgroundImage = "url(images/bg_" + page + ".jpg)"; }
function changeLogo (page) { document.getElementById('logo').src = 'images/logo_' + page + '.jpg'; }

function init (page) {
		
	sIFR.bAutoInit = true;
	
	if(typeof sIFR == "function") {
		do_sIFR(page);
	}
	
	
	
}

function do_sIFR(page) {
		sIFR.replaceElement(named({sSelector:"ul#navigation li.active span", sFlashSrc:"/scripts/bignoodletitling.swf", sColor:"#9966ff", sLinkColor:"#9966ff", sHoverColor:"#9966ff", sWmode: "transparent", sFlashVars:"textalign=center&offsetTop=0"}));
		
		if (page == "fouradi"/* || page == "pics" || page == "agenda" || page == "links"*/)
			sIFR.replaceElement(named({sSelector:"ul#navigation li.nonactive span", sFlashSrc:"/scripts/bignoodletitling.swf", sColor:"#000000", sLinkColor:"#000000", sHoverColor:"#9966ff", sWmode: "transparent", sFlashVars:"textalign=center&offsetTop=0"}));
		else
			sIFR.replaceElement(named({sSelector:"ul#navigation li.nonactive span", sFlashSrc:"/scripts/bignoodletitling.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sHoverColor:"#9966ff", sWmode: "transparent", sFlashVars:"textalign=center&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"ul#subnavigation li span", sFlashSrc:"/scripts/bignoodletitling.swf", sColor:"#000000", sLinkColor:"#000000", sHoverColor:"#9966ff", sWmode: "transparent", sFlashVars:"textalign=center&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"/scripts/bignoodletitling.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sHoverColor:"#ffffff", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"h1 span", sFlashSrc:"/scripts/bignoodletitling.swf", sColor:"#9966ff", sLinkColor:"#9966ff", sHoverColor:"#9966ff", sWmode: "transparent", sFlashVars:"textalign=left&offsetTop=0"}));
	}
	
	function include_dom(script_filename) {
		
    	var html_doc = document.getElementsByTagName('head').item(0);
	    var js = document.createElement('script');
	    js.setAttribute('language', 'javascript');
	    js.setAttribute('type', 'text/javascript');
	    js.setAttribute('src', script_filename);
	    html_doc.appendChild(js);
	    return false;
		
	}

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 clickIE() {
	if (document.all){
		return false;
	}
}
 
function clickNS(e) { 
	if (document.layers||(document.getElementById&&!document.all)) {
	
		if (e.which==2||e.which==3) {
			return false;
		}
	}
}

if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
} else {
	document.onmouseup=clickNS;document.oncontextmenu  =clickIE;
} 
document.oncontextmenu=new Function("return false");