var Menu=new Class({
	initialize:function(a){
		this.children=$$(a).shift().getChildren("li");
		this.startEvents()
	},
	startEvents:function(){
		this.children.each(function(b){
			var a=b.getChildren("ul");if($chk(a)){
				a.hide();b.addEvents({
					mouseenter:function(){a.show()},
					mouseleave:function(){a.hide()}
				})
			}
		})
	}
});

var HeaderLoop=new Class({
	Implements:Options,options:{speed:6000},
	initialize:function(a,c,b){
		this.setOptions(b);
		this.images=$(a).getElements("img");
		this.count=this.images.length;
		this.current=0;
		this.previous=this.count-1;
		this.ifThumbs=c;
		this.prev=$("nav-big-prev");
		this.next=$("nav-big-next");
		if(this.count>1){
			this.loadImage(true);
			this.loop=this.loadImage.periodical(this.options.speed,this);
			if(c){
				this.projects=$$(c);
				this.addCustomEvents()
			}
		}else{
			this.singleImage()
		}
	},
	singleImage:function(){
		var a=new Fx.Tween(this.images[0]);a.start("opacity",0,1)
	},
	loadImage:function(e){
		this.images.setStyle("z-index",0);
		var b=this.images[this.previous];
		var c=this.images[this.current];
		b.setStyle("z-index",1);
		var a=new Fx.Tween(c);
		var d=new Fx.Tween(b);
		c.setStyle("z-index",2);
		if(e){
			a.start("opacity",0,1).chain(function(){
				b.setStyle("opacity",0);
				if(this.ifThumbs){
					this.projects[this.previous].getElement("img").setStyle("opacity",0.3)
				}
			}.bind(this))
		}else{
			if(this.ifThumbs){
				this.projects[this.current].getElement("img").setStyle("opacity",0.3);
				this.projects[this.previous].getElement("img").setStyle("opacity",1)
			}
			d.start("opacity",1,0).chain(function(){
				a.start("opacity",0,1)
			}.bind(this))
		}
		this.previous=this.current;
		this.current++;
		if(this.current==this.count){
			this.current=0
		}
	},
	reverseImage:function(){
		this.current--;
		this.previous--;
		if(this.current==-1){
			this.current=this.count-1
		}
		if(this.previous==-1){
			this.previous=this.count-1
		}
		this.images.setStyle("z-index",0);
		var b=this.images[this.current];
		var c=this.images[this.previous];
		b.setStyle("z-index",1);
		var a=new Fx.Tween(c);
		var d=new Fx.Tween(b);
		c.setStyle("z-index",2);
		if(this.ifThumbs){
			this.projects[this.previous].getElement("img").setStyle("opacity",1);
			this.projects[this.current].getElement("img").setStyle("opacity",0.3)
		}
		d.start("opacity",1,0).chain(function(){
			a.start("opacity",0,1)
		}.bind(this))
	},
	setImage:function(){
		this.images.setStyles({"z-index":0,opacity:0});
		this.projects.getElement("img").setStyles({opacity:0.3});
		this.images[this.current].setStyles({"z-index":2,opacity:1,visibility:"visible"});
		this.projects[this.current].getElement("img").setStyles({opacity:1});
		this.previous=this.current;
		this.current++;
		if(this.current==this.count){
			this.current=0
		}
	},
	addCustomEvents:function(){
		this.projects.each(function(b,a){
			b.addEvents({
				mouseenter:function(){
					$clear(this.loop);
					this.current=a;
					this.setImage()
				}.bind(this),
				mouseleave:function(){
					this.loop=this.loadImage.periodical(this.options.speed,this)
				}.bind(this)
			})
		}.bind(this));
		this.prev.addEvents({
			mouseenter:function(){
				$clear(this.loop)
			}.bind(this),
			mouseleave:function(){
				this.loop=this.loadImage.periodical(this.options.speed,this)
			}.bind(this),
			click:function(){
				this.reverseImage()
			}.bind(this)
		});
		this.next.addEvents({
			mouseenter:function(){
				$clear(this.loop)
			}.bind(this),
			mouseleave:function(){
				this.loop=this.loadImage.periodical(this.options.speed,this)
			}.bind(this),
			click:function(){
				this.loadImage()
			}.bind(this)
		})
	}
});
var SimpleGoogleMap=new Class({Implements:Options,options:{markerImage:{image:false,size:[0,0],start:[0,0],offset:[0,0]},markerShadow:{image:false,size:[0,0],start:[0,0],offset:[0,0]},route:{routeInput:false,routeSubmit:false},zoom:15},initialize:function(a,c,b){this.setOptions(b);this.latLng=new google.maps.LatLng(-34.397,150.644);this.address=a;this.map=$(c);this.image=null;this.shadow=null;if(this.options.markerImage.image){this.image=new google.maps.MarkerImage(this.options.markerImage.image,new google.maps.Size(this.options.markerImage.size[0],this.options.markerImage.size[1]),new google.maps.Point(this.options.markerImage.start[0],this.options.markerImage.start[1]),new google.maps.Point(this.options.markerImage.offset[0],this.options.markerImage.offset[1]))}if(this.options.markerShadow.image){this.shadow=new google.maps.MarkerImage(this.options.markerShadow.image,new google.maps.Size(this.options.markerShadow.size[0],this.options.markerShadow.size[1]),new google.maps.Point(this.options.markerShadow.start[0],this.options.markerShadow.start[1]),new google.maps.Point(this.options.markerShadow.offset[0],this.options.markerShadow.offset[1]))}if(this.options.route.routeInput&&this.options.route.routeSubmit){this.insertRouteOverlay();this.bindRouteEvents()}this.initMap()},initMap:function(){var b=new google.maps.Geocoder();var a=new google.maps.Map(this.map,{zoom:this.options.zoom,center:this.latLng,mapTypeId:google.maps.MapTypeId.ROADMAP});b.geocode({address:this.address},function(c,e){if(e==google.maps.GeocoderStatus.OK){a.setCenter(c[0].geometry.location);var d=new google.maps.Marker({map:a,position:c[0].geometry.location,icon:this.image,shadow:this.shadow})}}.bind(this))},insertRouteOverlay:function(){this.routeBase=new Element("div").setStyles({position:"fixed",width:"200%",height:"200%",background:"#000000",opacity:0,visibility:"hidden","z-index":999}).inject($(document.body),"top");this.route=new Element("div").setStyles({position:"fixed",width:1,height:1,padding:20,background:"#ffffff",opacity:0,visibility:"hidden","z-index":1000}).inject($(document.body),"top")},bindRouteEvents:function(){$(this.options.route.routeSubmit).addEvent("click",function(){if($(this.options.route.routeInput).get("value").length>0){this.animateRoute($(this.options.route.routeInput).get("value"))}}.bind(this))},animateRoute:function(a){var e=new Fx.Morph(this.routeBase);var d=new Fx.Morph(this.route);var b=$(document.body).getSize();var c=true;e.start({opacity:0.9}).chain(function(){this.routeBase.addEvent("click",function(){if(!c){this.routemap.destroy();this.routeDescription.destroy();d.start({width:1,height:1,opacity:0,left:0,top:0}).chain(function(){c=true;e.start({opacity:0})})}}.bind(this));d.start({width:800,height:500,opacity:1,left:(b.x/2)-400,top:(b.y/2)-250}).chain(function(){c=false;this.closer=new Element("div",{html:"X"}).setStyles({color:"#ffffff","font-size":18,position:"absolute",top:"-28px",right:0,cursor:"pointer"}).inject(this.route).addEvent("click",function(){if(this.routemap){this.routemap.destroy()}if(this.routeDescription){this.routeDescription.destroy()}if(this.error){this.error.destroy()}this.closer.destroy();d.start({width:1,height:1,opacity:0,left:0,top:0}).chain(function(){c=true;e.start({opacity:0})})}.bind(this));this.routemap=new Element("div").setStyles({position:"relative",width:420,height:490,"float":"left",border:"5px solid #D7DADC",visibility:"hidden"}).inject(this.route);this.routeDescription=new Element("div").setStyles({position:"relative",width:350,height:500,"float":"right",overflow:"auto",visibility:"hidden"}).inject(this.route);var i=new google.maps.Map(this.routemap,{mapTypeId:google.maps.MapTypeId.ROADMAP});var h=new google.maps.DirectionsService();var f=new google.maps.DirectionsRenderer();f.setMap(i);f.setPanel(this.routeDescription);var g={origin:a+", Nederland",destination:this.address,travelMode:google.maps.DirectionsTravelMode.DRIVING};h.route(g,function(k,j){if(j==google.maps.DirectionsStatus.OK){f.setDirections(k);this.routemap.setStyle("visibility","visible");this.routeDescription.setStyle("visibility","visible")}else{this.routemap.destroy();this.routeDescription.destroy();this.error=new Element("div",{html:"Het adres wat u opgegeven heeft is niet gevonden. Probeer het nogmaals."}).setStyles({position:"absolute",width:300,left:250,top:250,"font-weight":"bold",cursor:"pointer","text-align":"center"}).inject(this.route).addEvent("click",function(){this.error.destroy();d.start({width:1,height:1,opacity:0,left:0,top:0}).chain(function(){c=true;e.start({opacity:0})})}.bind(this))}}.bind(this))}.bind(this))}.bind(this))}});window.addEvent("domready",function(){var a=new Menu(".navigation");if($("latest-project-image")){new HeaderLoop("latest-project-image",false)}if($("contact-map")){new SimpleGoogleMap("Eusebiusbuitensingel 9, 6828 HT Arnhem, Nederland","contact-map",{markerImage:{image:"/asset/images/map-marker.png",size:[131,103],start:[0,0],offset:[33,103]},markerShadow:{image:"/asset/images/map-shadow.png",size:[198,82],start:[0,0],offset:[33,73]},route:{routeInput:"route-address",routeSubmit:"start-route"}})}if($("big-image")){new HeaderLoop("big-image",".project-small")}if($("project-view")){$$(".project img").addEvent("click",function(){var b=$(this).get("src").replace("thumb","res");$("big-image").getElement("img").set("src",b)})}});
