function getAjaxObject(){
	var ajaxRequest;
	try{
		ajaxRequest = new XMLHttpRequest();
	}catch(e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return false;
			}
		}
	}
	return ajaxRequest;
}
function ajax(file,action){
	var ajaxRequest=getAjaxObject();
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			action(ajaxRequest.responseText);
		}
	}
	try{
		ajaxRequest.open("GET", file, true);
		ajaxRequest.send(null);
	}catch(e){
		return false;
	}
}

function ajaxPOST(file,postvalue,action){
	var ajaxRequest=getAjaxObject();
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			action(ajaxRequest.responseText);
		}
	}
	try{
		ajaxRequest.open("POST", file, true);
		
		ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxRequest.setRequestHeader("Content-length", postvalue.length);
		ajaxRequest.setRequestHeader("Connection", "close");
		
		ajaxRequest.send(postvalue);
	}catch(e){
		return false;
	}
}

function submitForm(sender_name, sender_email, sender_message){
	if(sender_name != '' || sender_email != '' || sender_message != ''){
		var getval = '?name='+sender_name+'&email='+sender_email+'&message='+sender_message;
		var postval = 'name='+escape(sender_name)+'&email='+escape(sender_email)+'&message='+escape(sender_message);
		ajaxPOST('setContent.php', postval,function(response){
			alert(response);
		});
	}
	else{
		alert('Vul alle velden in.');
	}
}

function getContent(page,lang) {
	ajax('setContent.php?page='+page+'&lang='+lang,function(response){
		document.getElementById("content").innerHTML=response;
	});
}

var opaque = 0;
function showContent()
{
	elem = document.getElementById('content');
	if(opaque < 100) {
		elem.style.display = "block";
		opaque +=5;
		elem.style.opacity = (opaque / 100);
		elem.style.MozOpacity = (opaque / 100);
		elem.style.KhtmlOpacity = (opaque / 100);
		elem.style.filter = "alpha(opacity=" + opaque + ")";
		window.setTimeout('showContent()',20);
	}
}
var shrunk = 0;
function showTitle() {
	elem = document.getElementById('logo');
	if(shrunk < 105) {
		elem.style.display = "block";
		elem.style.width = (550 - shrunk)+"px";
		elem.style.left = -(275 - (shrunk/2)) + "px";
		shrunk +=5;
		elem.style.opacity = (shrunk / 100);
		elem.style.MozOpacity = (shrunk / 100);
		elem.style.KhtmlOpacity = (shrunk / 100);
		elem.style.filter = "alpha(opacity=" + shrunk + ")";
		window.setTimeout('showTitle()',20);	
	}
	else {
		showContent();
	}
}
var nextbutton = "home";
var added = 0;
function moveIt(elem) {
	if(added < 45) {
		elem.style.display = "block";
		elem.style.left = (elem.offsetLeft - 2) + "px";
		added +=2;
		elem.style.opacity = (added*2 / 100);
		elem.style.MozOpacity = (added*2 / 100);
		elem.style.KhtmlOpacity = (added*2 / 100);
		elem.style.filter = "alpha(opacity=" + added*2 + ")";
	}
	else
	{
		elem.style.opacity = (1);
		elem.style.MozOpacity = (1);
		elem.style.KhtmlOpacity = (1);
		elem.style.filter = "alpha(opacity=100)";
		added = 0;
		return("done");
	}
}
function moveButtons() {
	switch(nextbutton) {
	case "home":
		if(moveIt(document.getElementById('home')) == "done")
		{
			nextbutton = "over";
		}
		break;
	case "over":
		if(moveIt(document.getElementById('over')) == "done")
		{
			nextbutton = "galerie";
		}
		break;
	case "galerie":
		if(moveIt(document.getElementById('galerie')) == "done")
		{
			nextbutton = "gastenboek";
		}
		break;
	case "gastenboek":
		if(moveIt(document.getElementById('gastenboek')) == "done")
		{
			nextbutton = "contact";
		}
		break;
	case "contact":
		if(moveIt(document.getElementById('contact')) == "done")
		{
			nextbutton = "links";
		}
		break;
	case "links":
		if(moveIt(document.getElementById('links')) == "done")
		{
			nextbutton = "none";
			showTitle();
			return;
		}
		break;
	}
	window.setTimeout('moveButtons()',10);
}
function grow(elem) {
	var img = elem.getElementsByTagName("img")[0];
	if (img.clientWidth == 50)
	{
		img.style.width = "60px";
		img.style.height = "60px";
		img.style.left = img.offsetLeft - 5;
		img.style.top = img.offsetTop - 5;
	}
}
function shrink(elem) {
	var img = elem.getElementsByTagName("img")[0];
	if (img.clientWidth != 50)
	{
		img.style.width = "50px";
		img.style.height = "50px";
		img.style.left = img.offsetLeft + 5;
		img.style.top = img.offsetTop + 5;
	}
}

function getWindowX() {
  var myWidth = 0;
  var button=document.getElementById('button');
  myWidth=parseInt(button.style.left)+128;
  
  res=screen.width;
  res-=1085;
  res/=2;
  myWidth+=res;
  return myWidth;
}

if (window.Event) {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getCursorX;

var mouseX;
function getCursorX(e) {
	mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
}

var mouseIn=0;
var running=0;
function getMouse(mouse) {
	if(mouse == 1) {
		mouseIn=1;
		if(running==0) {
			running=1;
			initColorbox();
			moveGallery();
		}
	}
	else
		mouseIn=0;
}
function moveGallery(dir, e) {
	//cont=document.getElementById('paintingscontainer');
	pos=(dir>0)?'+':'-';
	//document.getElementById('cursorX').value = pos;
	$('#paintingscontainer').scrollTo({left:pos+'=200px',top:0},500);
	/*
	if(mouseIn==1) {
		//alert(mouseX+'-'+getWindowX()+'='+(mouseX-getWindowX()));
		var mouseRel=(mouseX-getWindowX());
		if(mouseRel > 3 || mouseRel < -3) {
			document.getElementById('cursorX').value = mouseRel;
			//gal.style.left=gal.offsetLeft+mouseRel;
		}
	}
	window.setTimeout('moveGallery()',30);
	*/
}
var cboxrunning=0;
function initColorbox() {
	if(cboxrunning!=1) {
		$("a[rel='painting']").colorbox({maxWidth:"90%",maxHeight:"90%", photo:true});
	}
}
