// JavaScript Document
var Drawer = {
	start: function(){
		if ($('drawer')) Drawer.parseDrawers();
	},
	
	parseDrawers: function(){
		var drawers = $$('#drawer .drawer');
		var teasers = $$('#drawer .drawer ol .teaser');
		var fx = new Fx.Elements(drawers, {wait: false, duration:350, transition: Fx.Transitions.Quart.easeOut});
		
		drawers.each(function(drawer, i){
			drawer.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {'height': [drawer.getStyle('height').toInt(), drawer.scrollHeight]};
				drawers.each(function(other, j){
					if (other != drawer){
						var w = other.getStyle('height').toInt();
						if (w != 81) obj[j] = {'height': [w, 81]};
						teasers[j].style.backgroundImage = 'url(/assets/templates/udenhout/img/drawer_box_bg_s_1.jpg)';
					}
					else{
						teasers[j].style.backgroundImage = 'url(/assets/templates/udenhout/img/drawer_box_bg_s_1active.jpg)';
					}
				});
				fx.start(obj);
			});
		});
	}
};

var NewsDrawer = {
	start: function(){
		if ($('news')) NewsDrawer.parseDrawers();
	},
	
	parseDrawers: function(){
		var drawers = $$('#news .newsitem');
		var fx = new Fx.Elements(drawers, {wait: false, duration: 500, transition: Fx.Transitions.Quad.easeOut});
		var activeDrawer;
		var open=false;
		drawers.each(function(drawer, i){
			drawer.open=false;		  
			//MouseEnterEvent
			drawer.addEvent('mouseenter', function(e){
				var obj = {};
				if(!open){
					if(!this.open){
						obj[i] = {'height': [drawer.getStyle('height').toInt(), 36]};
					}
					drawers.each(function(other, j){
						if (other != drawer){
							var w = other.getStyle('height').toInt();
							if (w != 22) obj[j] = {'height': [w, 22]};
						}
					});
					fx.start(obj);
				}
			});
			
			
			//MousedownEvent
			drawer.addEvent('mousedown', function(e){
					var obj = {};
				
						if(!this.open && !open){
							this.open=true;
							open=true
							obj[i] = {'height': [drawer.getStyle('height').toInt(), drawer.scrollHeight]};
							drawers.each(function(other, j){
								if (other != drawer){
									var w = other.getStyle('height').toInt();
									if (w != 22) obj[j] = {'height': [w, 22]};
								}
							});
							fx.start(obj);
						}else{
							open=false
							this.open=false;
							obj[i] = {'height': [drawer.getStyle('height').toInt(), 22]};
							fx.start(obj);
						}
					
			});
			
		});
		
		
		//MouseLeaveEvent
		$('news').addEvent('mouseleave', function(e){
			var obj = {};
			drawers.each(function(other, j){
					if(!other.open){
						obj[j] = {'height': [other.getStyle('height').toInt(), 22]};
					}
			});
			fx.start(obj);
		});
	}
};

var Chart = {
	start: function(){
		if ($('chart')) Chart.parseCharts();
	},
	
	parseCharts: function(){
		var charts = $$('#chart .chart');
		var teasers = $$('#chart .chart h1');
		var fx = new Fx.Elements(charts, {wait: false, duration: 400, transition: Fx.Transitions.Quad.easeOut});
		
		charts.each(function(chart, i){
			chart.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {'height': [chart.getStyle('height').toInt(), chart.scrollHeight]};
				charts.each(function(other, j){
					if (other != chart){
						var w = other.getStyle('height').toInt();
						if (w != 29) obj[j] = {'height': [w, 29]};
						teasers[j].style.backgroundImage = 'url(/assets/templates/udenhout/img/chartsheader_bg.jpg)';
					}
					else{
						teasers[j].style.backgroundImage = 'none';
					}
				});
				fx.start(obj);
			});
		});
	}
};

/* VACATURES */		
var Vacatures = {
	start: function(){
		if ($('vacatures')) Vacatures.parseVacatures();
	},
	
	parseVacatures: function(){
		var boxes = $$('#vacatures .vacatureitem .itemopen');
		var content = $$('#vacatures .vacatureitem .itemcontent');
		var open = false;
		var fx = new Fx.Elements(content, {wait: false, duration:350, transition: Fx.Transitions.Quart.easeOut});
		
		boxes.each(function(box, i){
			box.open = false;
			box.addEvent('click', function(){
				var obj = {};
				if(!this.open){
					obj[i] = {'height': [content[i].getStyle('height').toInt(), content[i].scrollHeight]};
					box.innerHTML = 'Klik om te sluiten';
					box.style.backgroundImage = 'url(/assets/templates/udenhout/img/close.gif)';
					this.open = true;
				}
				else{
					obj[i] = {'height': [content[i].getStyle('height').toInt(), 0]};
					box.innerHTML = 'Klik voor meer informatie';
					box.style.backgroundImage = 'url(/assets/templates/udenhout/img/open.gif)';
					this.open = false;
				}
				boxes.each(function(other, j){
					if (other != box){
						var w = content[j].getStyle('height').toInt();
						if (w != 0){
							obj[j] = {'height': [w, 0]};
							boxes[j].innerHTML = 'Klik voor meer informatie';
							boxes[j].style.backgroundImage = 'url(/assets/templates/udenhout/img/open.gif)';
							boxes[j].open = false;
						}
					}
				});
				fx.start(obj);
			});
		});
	}
}


/* VESTIGINGEN */		
var Vestigingen = {
	start: function(){
		if ($('vestigingen')) Vestigingen.parseVestigingen();
	},
	
	parseVestigingen: function(){
		var boxes = $$('#vestigingen .vestiging .open');
		var content = $$('#vestigingen .vestiging .tijdenDiv');
		var open = false;
		var fx = new Fx.Elements(content, {wait: false, duration:350, transition: Fx.Transitions.Quart.easeOut});
		
		boxes.each(function(box, i){
			box.open = false;
			box.addEvent('click', function(){
				var obj = {};
				if(!this.open){
					obj[i] = {'height': [content[i].getStyle('height').toInt(), content[i].scrollHeight]};
					box.style.backgroundImage = 'url(/assets/templates/udenhout/img/close.gif)';
					this.open = true;
				}
				else{
					obj[i] = {'height': [content[i].getStyle('height').toInt(), 0]};
					box.style.backgroundImage = 'url(/assets/templates/udenhout/img/open.gif)';
					this.open = false;
				}
				boxes.each(function(other, j){
					if (other != box){
						var w = content[j].getStyle('height').toInt();
						if (w != 0) {
							obj[j] = {'height': [w, 0]};
							boxes[j].style.backgroundImage = 'url(/assets/templates/udenhout/img/open.gif)';
							boxes[j].open = false;
						}
					}
				});
				fx.start(obj);
			});
		});
	}
}


/* ACTIEMODELLEN */		
var Actiemodellen = {
	start: function(){
		if ($('actiemodellen')) Actiemodellen.parseActiemodellen();
	},
	
	parseActiemodellen: function(){
		var boxes = $$('#actiemodellen .modellen .open');
		var content = $$('#actiemodellen .modellen .specsDiv');
		var open = false;
		var fx = new Fx.Elements(content, {wait: false, duration:350, transition: Fx.Transitions.Quart.easeOut});
		
		boxes.each(function(box, i){
			box.open = false;
			box.addEvent('click', function(){
				var obj = {};
				if(!this.open){
					obj[i] = {'height': [content[i].getStyle('height').toInt(), content[i].scrollHeight]};
					box.style.backgroundImage = 'url(/assets/templates/udenhout/img/close.gif)';
					this.open = true;
				}
				else{
					obj[i] = {'height': [content[i].getStyle('height').toInt(), 0]};
					box.style.backgroundImage = 'url(/assets/templates/udenhout/img/open.gif)';
					this.open = false;
				}
				boxes.each(function(other, j){
					if (other != box){
						var w = content[j].getStyle('height').toInt();
						if (w != 0) {
							obj[j] = {'height': [w, 0]};
							boxes[j].style.backgroundImage = 'url(/assets/templates/udenhout/img/open.gif)';
							boxes[j].open = false;
						}
					}
				});
				fx.start(obj);
			});
		});
	}
}
