//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

MooTools.More={version:"1.2.5.1",build:"254884f2b83651bf95260eed5c6cceb838e22d8e"};(function(){var a=function(c,b){return(c)?($type(c)=="function"?c(b):b.get(c)):"";
};this.Tips=new Class({Implements:[Events,Options],options:{onShow:function(){this.tip.setStyle("display","block");},onHide:function(){this.tip.setStyle("display","none");
},title:"title",text:function(b){return b.get("rel")||b.get("href");},showDelay:100,hideDelay:100,className:"tip-wrap",offset:{x:16,y:16},windowPadding:{x:0,y:0},fixed:false},initialize:function(){var b=Array.link(arguments,{options:Object.type,elements:$defined});
this.setOptions(b.options);if(b.elements){this.attach(b.elements);}this.container=new Element("div",{"class":"tip"});},toElement:function(){if(this.tip){return this.tip;
}return this.tip=new Element("div",{"class":this.options.className,styles:{position:"absolute",top:0,left:0}}).adopt(new Element("div",{"class":"tip-top"}),this.container,new Element("div",{"class":"tip-bottom"}));
},attach:function(b){$$(b).each(function(d){var f=a(this.options.title,d),e=a(this.options.text,d);d.erase("title").store("tip:native",f).retrieve("tip:title",f);
d.retrieve("tip:text",e);this.fireEvent("attach",[d]);var c=["enter","leave"];if(!this.options.fixed){c.push("move");}c.each(function(h){var g=d.retrieve("tip:"+h);
if(!g){g=this["element"+h.capitalize()].bindWithEvent(this,d);}d.store("tip:"+h,g).addEvent("mouse"+h,g);},this);},this);return this;},detach:function(b){$$(b).each(function(d){["enter","leave","move"].each(function(e){d.removeEvent("mouse"+e,d.retrieve("tip:"+e)).eliminate("tip:"+e);
});this.fireEvent("detach",[d]);if(this.options.title=="title"){var c=d.retrieve("tip:native");if(c){d.set("title",c);}}},this);return this;},elementEnter:function(c,b){this.container.empty();
["title","text"].each(function(e){var d=b.retrieve("tip:"+e);if(d){this.fill(new Element("div",{"class":"tip-"+e}).inject(this.container),d);}},this);$clear(this.timer);
this.timer=(function(){this.show(b);this.position((this.options.fixed)?{page:b.getPosition()}:c);}).delay(this.options.showDelay,this);},elementLeave:function(c,b){$clear(this.timer);
this.timer=this.hide.delay(this.options.hideDelay,this,b);this.fireForParent(c,b);},fireForParent:function(c,b){b=b.getParent();if(!b||b==document.body){return;
}if(b.retrieve("tip:enter")){b.fireEvent("mouseenter",c);}else{this.fireForParent(c,b);}},elementMove:function(c,b){this.position(c);},position:function(e){if(!this.tip){document.id(this);
}var c=window.getSize(),b=window.getScroll(),f={x:this.tip.offsetWidth,y:this.tip.offsetHeight},d={x:"left",y:"top"},g={};for(var h in d){g[d[h]]=e.page[h]+this.options.offset[h];
if((g[d[h]]+f[h]-b[h])>c[h]-this.options.windowPadding[h]){g[d[h]]=e.page[h]-this.options.offset[h]-f[h];}}this.tip.setStyles(g);},fill:function(b,c){if(typeof c=="string"){b.set("html",c);
}else{b.adopt(c);}},show:function(b){if(!this.tip){document.id(this);}if(!this.tip.getParent()){this.tip.inject(document.body);}this.fireEvent("show",[this.tip,b]);
},hide:function(b){if(!this.tip){document.id(this);}this.fireEvent("hide",[this.tip,b]);}});})();

var cK = "#FFFFFF";
var bId = 0; //button ID pressed
var cP = 0; //current Page
var lP = 0; //load Page
var nI = 0; //mailing id
var dbCheck = false; //if ajax request fails try once more?
var ajaxIds = new Array(); //array with page id's for ajax link actions

var cL = false;

window.addEvent('domready', function(){

	$$("#projecten a").slimbox({
		loop:true
	});

	var iW = $('content').getStyle('width').toInt();
	$('inhoudContainer').setStyle('width',iW + 2);
   if(Browser.Engine.name == "gecko" && Browser.Engine.version < 19){
		$('inhoudContainer').setStyle('left',475 - (iW / 2));
	}

	if(document.getElementById('mainContentDiv').innerHTML.length > 15){
		var contentDiv = $('inhoudContainer').setStyles({top:"36px"});
	}

	if(document.getElementById('menu0')){
   	if(document.getElementById('menu0').className == "mainMenuActive"){
         document.getElementById('menu0').className = "mainMenu0Active";
		}
	}
//	if(window.arrayImages){
//     	document.getElementById('mainContentDiv').style.width = "500px";
//     	document.getElementById('inhoud').innerHTML = document.getElementById('inhoud').innerHTML;
//	}
	var i = 0;
	while(document.getElementById('menu' + i)){
		$('menu' + i).addEvent('click', function(){
			el = document.getElementById(this.id).firstChild;
			hostName = window.location.hostname.replace("www.","").toLowerCase();
			if(hostName.substr(0,1) == "0"){hostName = "/" + hostName};
        	if(el.href.indexOf(hostName) > -1){
				pid = 0;
				nI = 0;
				hL = el.href.substr(el.href.indexOf(hostName) + hostName.length).toLowerCase();
				if(hL.indexOf('?pid=') > 3){ pid = hL.substr(hL.indexOf('?pid=') + 5)}
            if(hL.indexOf("/0") > -1){
					pid = hL.substr(hL.indexOf("/0") + 2);
               pid = pid.substr(0, pid.indexOf("/"));
				}
				if(hL.indexOf('?nsid=1') > 3){
            	nI = 1;
            	pid= 9999;
				}
				if(pid > 0 && pid < 99999){
					lP = pid;
					if(!cL && pid != cP){
						cP = pid;
      				bId = this.id.substring(4).toInt() + 2;
				      menuDown(this.id);

						verkrijgKleur.get({"mid": bId, "random" : new Date().getMinutes() });
					}
					return false;
				} else {
					return true;
				}
			}
		});
		i ++;
	}

	//vervang alle links met ajax links
	var ajaxIt = function(){
		hostName = window.location.hostname.replace("www.","").toLowerCase();
   	var contentDiv = document.getElementById('inhoud').getElementsByTagName("a");

   	for(var i=0;i<contentDiv.length;i++){
			ajaxIds[i] = "";
			el = contentDiv[i];
			el.id = 'link' + i;

			pid = 0;
			hL = el.href.toLowerCase();
			if(hL.indexOf('?pid=') > 3){
				pid = hL.substr(hL.indexOf('?pid=') + 5)
				ajaxIds[i] = pid;
				el.id = 'link' + i;
			}
         if(hL.indexOf("/0") > -1 || hL.indexOf("0") == 0){
				pid = hL.substr(hL.indexOf("/0") + 2);
            pid = pid.substr(0, pid.indexOf("/"));
				ajaxIds[i] = pid;
				el.id = 'link' + i;
			}
			if(pid > 0 && pid < 99999){
     			$('link' + i).addEvent('click', function(){
					cP = pid;
    		   	verkrijgData.get({"pid": ajaxIds[this.id.substring(4)] , "random" : new Date().getMinutes()  });
					return false;
				});
   		}

			hL = el.href.substr(el.href.indexOf(hostName) + hostName.length).toLowerCase();
			if(hL.indexOf('?nsid=1') > 3){
  				$('link' + i).addEvent('click', function(){
    		   	verkrijgData.get({"sid": 1 , "random" :new Date().getMinutes()  });
					return false;
				});
   		}
         if(hL.indexOf('?nsid=-1') > 3){
  				$('link' + i).addEvent('click', function(){
    		   	verkrijgData.get({"sid": -1 , "random" : new Date().getMinutes()  });
					return false;
				});
   		}
			pid = 0;
		}
	}
	ajaxIt();

 //We can use one Request object many times.
	var verkrijgKleur = new Request({
		url: 'laadkleur.asp',
		onComplete: function(txt){
			cL = true;
			setCursor('default');
			var t = txt.trim();
			var l = t.length;
			if(l != 3 && l != 7){
				t = "#000000";
			}
			var div = $('content_bg').setStyles({
				display:'block',
				opacity: 1
			});
			$('content_bg').tween('background-color',t);
         verkrijgData.get({"pid": lP ,"sid": nI , "random" : new Date().getMinutes()  });
		},
		// Our request will most likely succeed, but just in case, we'll add an
		// onFailure method which will let the user know what happened.
		onFailure: function(){
			alert('Fout: De gevraagde data is niet gevonden. Excuses voor het ongemak');
			setCursor('default');
		}
	});

	var verkrijgData = new Request.HTML({
		encoding: 'windows-1252',
		url: 'laaddata.asp',
		onRequest: function(){
       	//Clear the text currently inside the results div.
			$('inhoud').set('text', '');
		},
		onComplete: function(html){
			setCursor('default');
         var htmlBU = html.item(html.length - 1);
         var showInhoud = new Fx.Tween('inhoudContainer', {
				property:'top',
           	duration:'500',
           	transition: Fx.Transitions.Quart.easeOut
			});
			if($('inhoudContainer').getStyle('top').toInt() > 0){
				showInhoud.start(-281).chain(function(){
	         	showInhoud.start(36);
	         	$('inhoud').adopt(html);
	         }).chain(function(){
					//doublecheck
					if($('inhoud').get('html') == ''){
                  $('inhoud').adopt(htmlBU);
					};
					ajaxIt();
               cL = false;
				});
	  		} else {
				$('inhoud').adopt(html);
				ajaxIt();
         	showInhoud.start(36).chain(function(){
					cL = false;
				});
			}
		},
		onFailure: function(){
			setCursor('default');
			$('inhoud').set('text', 'De gevraagde informatie is niet gevonden');
		}
	});

	i = 0;
	prEl = projectID.length;

	var rMargin = 5;
	for(i=0;i<prEl;i++){

		var contentDiv = $('project' + i).setStyles({
			left:(i * (198 + rMargin) - (rMargin * 2))
		});
	}

	var dirDef = -1;
   var curDir = dirDef;
   var scrollDef = 30;
	var scrollMs = scrollDef;
	var scrollOn = true;
	var elV = 5;
	var elWidth = 198;
	var elOffset = 0;
	var elL = 0;
	var maxEls = prEl - 1;
	var elTarget = 0;
	var elNextpos = 0;
	var maxWidth = (maxEls) * (elWidth + rMargin);

	if(maxEls < elV){
		maxEls = elV
		scrollDef = 999999999;
		scrollMs = scrollDef;
	}

	var scrollTimer = function(){
		elL = -1;
		elE = -1;
	  	for(i=0;i<prEl;i++){
			elR = parseInt(document.getElementById('project' + i).style.left);
			if(elR < - elWidth - rMargin){
            elL = i;
   		} else if(elR > maxWidth){
            elE = i;
			} else {
      		document.getElementById('project' + i).style.left = (elR + curDir) + "px";
   		}
	  	}
	  	if(elL >= 0){
			if(elL == 0){elTarget = prEl - 1;} else {elTarget = elL - 1;}
			 elNextpos = $('project' + elTarget).getStyle('left').toInt() + rMargin + elWidth;
       	 $('project' + elL).setStyle('left',elNextpos);
		}
		if(elE >= 0){
			if(elE == prEl -1){elTarget = 0;} else {elTarget = elE + 1;}
         elNextpos = $('project' + elTarget).getStyle('left').toInt() - elWidth - rMargin;
       	$('project' + elE).setStyle('left',elNextpos);
		}
	}
	scrollTimer.periodical(scrollMs);
   
	var checkMPos = false;

  	$('projecten').addEvent('mouseenter', function(event){

	   this.addEvent('mousemove', function(event){
			mouseX = event.client.x;
			winWidth = parseInt((window.getWidth() - 950) / 2);
			mouseX = mouseX - winWidth;

			if(mouseX > 650){
          	curDir = -2;
          	if(mouseX > 875){
					curDir = -8;
				}
			} else if(mouseX < 300){
           	curDir = 2;
           	if(mouseX < 75){
					curDir = 8;
				}
			} else {
				scrollMs = scrollDef;
				curDir = 0;
			}
		});
  	});

	$('projecten').addEvent('mouseleave', function(event){
			scrollMs = scrollDef;
			curDir = dirDef;
//			curDir = 0;
  	});

	  for(i=0;i<prEl;i++){

	  	new Tips($('project' + i),{
			  offsets: {'x': 3, 'y': 3},
			  fixed: false,
			  showDelay:200,
			  initialize:function(){
			}
			 })
		$('project' + i).store('tip:text', '<div class="toolTop"><h1>' + projectH[i] + '</h1>' + projectT[i] +
        	'<div class="toolImg" style="background-image:url(\'upload/' + projectImg[i] + '\');"><img src="images/tooltip_img.png" alt="" /></div></div><div class="toolBottom"></div>'
		);
	}
});
function openPicture(pic){
	$('lbImage').setStyle('background-image','url(\'upload/' + pic + '\')');
}

function setCursor(cursor){
	document.body.style.cursor = cursor;
}
function menuDown(e){
	i = 0;
	while(document.getElementById('menu' + i)){
		if(parseInt(e.substring(4)) != i){
   		document.getElementById('menu' + i).className = "mainMenu";
 		}
		i ++;
	}
		if(e == "menu0"){document.getElementById(e).className = "mainMenu0Active"
	} else {
		document.getElementById(e).className = "mainMenuActive";
	}
}

//verkrijg base href als deze aanwezig is voor het corrigeren van iexplorer javascript links
var baseAdres = "";
if( document.getElementsByTagName ) {
	var elems = document.getElementsByTagName('base');
	if( elems.length ) {
		baseAdres = elems[0].href;
	}
}

function printPagina(){
	printVenster = open("","printWindow","width=800,height=400,left=10,top=10");
	var printHTML = '<HTML><HEAD><TITLE>' + document.title + '</TITLE><LINK HREF="basic.css" REL="stylesheet" TYPE="text/css"></HEAD><BODY onload="window.print()">'
	printHTML += document.getElementById("mainContentDiv").innerHTML;
	printHTML += '</BODY></HTML>'
	printVenster.document.open();
	printVenster.document.write(printHTML);
	printVenster.document.close();
}

//handige functies
//voorkom lelijke omlijning van a elementen door indrukken van tab
var theahrefs = document.getElementsByTagName('a'); for(var x=0;x!=theahrefs.length;x++){theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};}

var albumActive = false;

//functie om externe links automatisch in nieuw venster te tonen
window.onload = externeLinks;
function externeLinks (){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && obj.target == "" && href.indexOf("javascript")==-1 && href.indexOf(hostname)==-1) ? true : false;
	};
	this.set = function(obj){
		obj.target = "_blank";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};
};
function openTour(){
var w = 580;
var h = 570;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var props = 'left=' + left +',top='+ top + ',width=580,height=570,menubar=no,scrollbars=no,status=no,location=no,toolbar=no,resizable=yes';
window.open('http://www.villa-eijsberg.nl/virtualtour/Tourviewer_VillaEijsberg.html','VTour',props);
}

function checkSubscribe(){
	var returnStatus = true;
	var testEmail = document.inputForm.email.value;
	document.getElementById("error1").innerHTML = '';
	document.getElementById("error2").innerHTML = '';
	document.getElementById("error3").innerHTML = '';
	if(testEmail.indexOf('@') < 2 || testEmail.indexOf('.') == -1){
		document.getElementById("error1").innerHTML = " ongeldig adres"
		returnStatus = false;
	}
	var testNaam = document.inputForm.naam.value;
	if(testNaam == ""){
		document.getElementById("error2").innerHTML = " verplicht veld"
		returnStatus = false;		
	}
	var testCaptcha = document.inputForm.recaptcha_response_field.value;
	if(testCaptcha == ""){
		document.getElementById("error3").innerHTML = " vul de beveiligingscodes in"
		returnStatus = false;		
	}
	return returnStatus;
}
