/*
      ##### #     ##                                       ##           /##   	
   ######  /#    #### /                  #              /####         #/ ###  	
  /#   /  / ##    ###/                  ###     #      /  ###        ##   ### 	
 /    /  /  ##    # #                    #     ##         /##        ##       	
     /  /    ##   #                            ##        /  ##       ##       	
    ## ##    ##   #    /###     /###   ###   ########    /  ##       ######   	
    ## ##     ##  #   / ###  / / ###  / ### ########    /    ##      #####    	
    ## ##     ##  #  /   ###/ /   ###/   ##    ##       /    ##      ##       	
    ## ##      ## # ##    ## ##    ##    ##    ##      /      ##     ##       	
    ## ##      ## # ##    ## ##    ##    ##    ##      /########     ##       	
    #  ##       ### ##    ## ##    ##    ##    ##     /        ##    ##       	
       /        ### ##    ## ##    ##    ##    ##     #        ##    ##       	
   /##/          ## ##    ## ##    ##    ##    ##    /####      ##   ##       	
  /  #####           ######   ######     ### / ##   /   ####    ## / ##       	
 /     ##             ####     ####       ##/   ## /     ##      #/   ##.nl    	
 #                                                 #                          	
  ##                                                ##                        	
*/

window.addEvent('domready', function() {
	
	Milkbox = new Milkbox();
	
	var widthMenu = 290;
	var widthList = 300;
	var widthContent = 350;
	
	//$('info_window').load('data/info.php');
	//$('contact_window').load('data/contact.php');
	
		
	
	var startSearch = function() {
		$('zoeker').value = '';
		selectedFromList = '';
		var request = new Request.JSON({
			url: 'data/abvg.php',
			onRequest: function() {
				$('wrapper').tween('left', (window.getWidth() - (260 + 300)) / 2);
				projectlist.empty();
				projectcontent.empty();
				projectlist.setStyle('opacity','0.001');
			},
			onComplete: function(jsonObj) {
				projectlist.tween('opacity','0.001','1');
				refreshList(jsonObj.items, jsonObj.searchinfo);
			}
		}).send();
	};
	
	
	var menuSearch = function(req) {
		$('zoeker').value = '';
		selectedFromList = '';
		var request = new Request.JSON({
			url: 'data/abvg.php?s=' + req,
			onRequest: function() {
				$('wrapper').tween('left', (window.getWidth() - (widthMenu + widthList)) / 2);
				projectlist.empty();
				projectcontent.empty();
				projectlist.setStyle('opacity','0.001');
			},
			onComplete: function(jsonObj) {
				projectlist.tween('opacity','0.001','1');
				refreshList(jsonObj.items, jsonObj.searchinfo);
			}
		}).send();
	};
	
	
	var menuSearchOnly = function(req) {
		$('zoeker').value = '';
		selectedFromList = '';
		var request = new Request.JSON({
			url: 'data/abvg.php?x=' + req,
			onRequest: function() {
				$('wrapper').tween('left', (window.getWidth() - (widthMenu + widthList)) / 2);
				projectlist.empty();
				projectcontent.empty();
				projectlist.setStyle('opacity','0.001');
			},
			onComplete: function(jsonObj) {
				projectlist.tween('opacity','0.001','1');
				refreshList(jsonObj.items, jsonObj.searchinfo);
			}
		}).send();
	};
	
	var images_path = 'images/projects/';
	var projectlist = $('projectlist');
	
	
	
	
	
	
	var typesblock = $('zoekform_onderwerpen');
	printTypes = function(types) {
		
		typesblock.empty();
		types.each(function(type) {
			// main item
			var el = new Element('div', {
				'class'	: 'button_type',
				'html'  : type.name,
				'events': {
					'click' : function() {
						menuSearchOnly(type.name);
						pageTracker._trackPageview("/Search/Type/" + type.name);
					},
					'mouseover' : function() {
						this.setStyle('color', '#fff');
					},
					'mouseleave' : function() {
						this.setStyle('color', '#999');
					}
				}
			});						
			el.inject(typesblock);
			
		});
	};
	
	
	var getTypes = function() {
		var request = new Request.JSON({
			url: 'data/types.php',
			onRequest: function() {
				$('zoekform_onderwerpen').empty();
			},
			onComplete: function(jsonObj) {
				printTypes(jsonObj.types);
			}
		}).send();
	};
	
	
	getTypes();
	
	
	
	
	
	var tagsblock = $('zoekform_tags');
	printTags = function(tags) {
		
		tagsblock.empty();
		tags.each(function(tag) {
			// main item
			var el = new Element('div', {
				'class'	: 'tag_link',
				'html'  : tag.name,
				'events': {
					'click' : function() {
						menuSearch(tag.name);
						pageTracker._trackPageview("/Search/Tag/" + tag.name);
	
					},
					'mouseover' : function() {
						this.setStyle('color', '#fff');
					},
					'mouseleave' : function() {
						this.setStyle('color', '#999');
					}
				}
			});						
			el.inject(tagsblock);
			
		});
	};
	
	
	var getTags = function() {
		var request = new Request.JSON({
			url: 'data/tags.php',
			onRequest: function() {
				$('zoekform_tags').empty();
			},
			onComplete: function(jsonObj) {
				printTags(jsonObj.tags);
			}
		}).send();
	};
	
	
	
	getTags();

	
	
	
		
	
	
	

	
	
	
	
	
	
	
	
	
	
	
	var selectedFromList = '';
	
	
	
	//var myList = new Fx.Slide('projectlist');
	// var myContents = new Fx.Slide('projectcontents', {mode: 'horizontal'});
			
	refreshList = function(projects, searchinfo) {
		
		projectlist.empty();
		//if (myList) myList.cancel();
		searchinfo.each(function(el) {
			
			if (el.words != '') {
				//el.words = 'Zoekopdracht Actief';
		
				var info 		= new Element('div', {	'class': 'list_SEARCHINFO'});
				var searchclear = new Element('div', {	'class': 'list_SEARCHCLEAR',
														'events': {
															'click' : function() {
																startSearch();
															}
														}
													}).inject(info);
				var searchtext	= new Element('div', {'class': 'list_SEARCHTEXT', 'html': '<b>Search</b> | ' + el.words + '&nbsp;' }).inject(searchclear, 'after');
				if (el.hits == 1) {
					var searchhits	= new Element('div', {'class': 'list_SEARCHHITS', 'html': el.hits + ' Hit'}).inject(searchtext, 'after') 
				} else {
					var searchhits	= new Element('div', {'class': 'list_SEARCHHITS', 'html': el.hits + ' Hits'}).inject(searchtext, 'after') 
				}
				info.inject(projectlist);
			}
		});	
		projects.each(function(proj) {
			// main item
			var el		 	= new Element('div', {
				'class': 'list_ITEM',
				'id': 'uid' + proj.uid,
				'events': {
					'click' : function() {
						openProject(proj.uid);
					},
					'mouseover' : function() {
						if ('uid' + proj.uid != selectedFromList) {
							this.setStyle('background-color', '#666');
							this.getElement('div[class=list_TITLE]').setStyle('color','#fff');
							this.getElement('div[class=list_YEAR]').setStyle('color','#eee');
							this.getElement('div[class=list_SUBTITLE]').setStyle('color','#eee');
							this.getElement('div[class=list_TYPE]').setStyle('color','#eee');
						};
					},
					'mouseleave' : function() {
						if ('uid' + proj.uid != selectedFromList) {
							this.setStyle('background-color', '#eee');
							this.getElement('div[class=list_TITLE]').setStyle('color','#333');
							this.getElement('div[class=list_YEAR]').setStyle('color','#333');
							this.getElement('div[class=list_SUBTITLE]').setStyle('color','#333');
							this.getElement('div[class=list_TYPE]').setStyle('color','#333');
						} else {
							this.setStyle('background-color', '#333');
						};
					}
				}
			});
				
			// left 
			var top		 	= new Element('div', 	{'class': 'list_TOP'}).inject(el);
			var title 		= new Element('div',	{'class': 'list_TITLE', 'html': proj.title}).inject(top);
			var year		= new Element('div',	{'class': 'list_YEAR', 'html': proj.year}).inject(title, 'after');
				
			// right
			var bottom	 	= new Element('div', 	{'class': 'list_BOTTOM'}).inject(el);
			var subtitle	= new Element('div',	{'class': 'list_SUBTITLE', 'html': proj.subtitle + '&nbsp;'}).inject(bottom);
			var type 		= new Element('div',	{'class': 'list_TYPE', 'html': proj.type}).inject(subtitle, 'after');
						
			el.inject(projectlist);
			
		});
		
		//projectlist.setStyle('opacity','1');
		//alert(projectlist.getStyle('opacity'));
		//myList.hide();
		//myList.slideIn();
	};

	
	
	var projectcontent = $('projectcontents');
		
	refreshContent = function(content) {
		
		var gallery	 	= false;
		var galleries	= 0;
		
		content.each(function(item) {
			// main piece
			var el 			= new Element('div',	{'class': 'content_ITEM'});
			
			
			// texttypes
			if (item.ctype == 't1') {
				gallery	 	= false;
				var textitem	= new Element('div',	{'class': 'content_t1', 'html': item.tekst}).inject(el);
			};
			if (item.ctype == 't2') {
				gallery	 	= false;
				var textitem	= new Element('div',	{'class': 'content_t2', 'html': item.tekst}).inject(el);
			};
			if (item.ctype == 't3') {
				gallery	 	= false;
				var textitem	= new Element('div',	{'class': 'content_t3', 'html': item.tekst}).inject(el);
			};
			
			
			// imagetypes
			if (item.ctype == 'i1') {
				if (item.bigSize == 'true') {

					var imagelink	= new Element('a', 		{
																'href': images_path + '' + item.imagepath,
																'rel': 'milkbox[pic' + item.uid + ']',
																'title': item.description,
																'events' : {
																	'click' : function() {
																	}
																}
															}).inject(el);
					var image		= new Element('img',	{
																'border': '0', 
																'alt': '', 
																'width': '100%',
																'height' : 'auto',
																'styles' : {
																	'width' : '100%',
																	'max-width' : '350px',
																	'height' : 'auto'
																},
																'src': images_path + item.imagepath }).inject(imagelink);
					gallery = false;
				
				} else {
					
					if (!gallery) {
						var img_el 	= new Element('div',	{	'class'	: 'content_ITEM',
																'id'	: 'gallery_' + galleries}).inject(projectcontent);
						gallery = true;
						++galleries;
					}
					var imagelink	= new Element('a', 		{
																'href': images_path + '' + item.imagepath,
																'rel': 'milkbox[gallery_' + (galleries - 1) + ']',
																'title': item.description,
																'border': '0', 
																'events' : {
																	'click' : function(e) {				
																	}
																},
																'styles' : {
																	'padding' : '2px'
																}
															});
					var image		= new Element('img',	{
																'border': '0', 
																'alt': '', 
																'width': '40', 
																'height': '40', 
																'styles' : {
																	'width' : '40',
																	'height' : '40'
																},
																'src': images_path + 'thumb_' + item.imagepath }).inject(imagelink);
					imagelink.inject($('gallery_' + (galleries - 1)));
					//img_el.inject(projectcontent)
				}
			};

			if (item.ctype == 'i2') {
				var imagebox	= new Element('div',	{'class': 'content_i2'}).inject(el);
				var image		= new Element('img',	{'src': images_path + item.imagepath}).inject(imagebox);
			};
			if (item.ctype == 'i3') {
				var imagebox	= new Element('div',	{'class': 'content_i3'}).inject(el);
				var image		= new Element('img',	{'src': images_path + item.imagepath}).inject(imagebox);
			};
			
			// ankertypes
			if (item.ctype == 'a1') {
				gallery	 	= false;
				var ankeritem	= new Element('div',	{'class': 'content_a1', 'html': item.anker}).inject(el);
				var ankertext	= new Element('div',	{'class': 'content_a1', 'html': item.showname}).inject(el);
			};
			if (item.ctype == 'a2') {
				gallery	 	= false;
				var ankeritem	= new Element('div',	{'class': 'content_a2', 'html': item.anker}).inject(el);
				var ankertext	= new Element('div',	{'class': 'content_a2', 'html': item.showname}).inject(el);
			};
			if (item.ctype == 'a3') {
				gallery	 	= false;
				var ankeritem	= new Element('div',	{'class': 'content_a3', 'html': item.anker}).inject(el);
				var ankertext	= new Element('div',	{'class': 'content_a3', 'html': item.showname}).inject(el);
			};
	
	
			if (item.ctype == 'v1') {
				gallery	 	= false;
				var vid = item.videopath;
				
				
				
				var videobox	= new Element('div',		{	'html'	: '' }).inject(el);
				
				var videoFrame	= new Element('iframe', 	{ 	'width'			: '345',
																'height'		: '259',
																'scrolling'		: 'no',
																'frameborder'	: '0',
																'marginheight'	: '0',
																'marginwidth'	: '0',
																'src'			: 'data/video_v1.php?id='+vid+'&width=345&height=259'
															}).inject(videobox);
				
				
				
			};
			if (item.ctype == 'v2') {
				gallery	 	= false;
				var vid = item.videopath;
				
				
				
				var videobox	= new Element('div',		{	'html'	: '' }).inject(el);
				
				var videoFrame	= new Element('iframe', 	{ 	'width'			: '345',
																'height'		: '259',
																'scrolling'		: 'no',
																'frameborder'	: '0',
																'marginheight'	: '0',
																'marginwidth'	: '0',
																'src'			: 'data/video_v2.php?id='+vid+'&width=345&height=259'
															}).inject(videobox);
				
				
				
			};
			if (item.ctype == 'f1') {
				gallery	 	= false;
				var filebox		= new Element('div',	{	'class'	: 'content_f1',
															'styles': {
																'vertical-align': 'left',
																'margin-top' 	: '-5px'
															}
														}).inject(el);
				var filelink	= new Element('a',		{	'html'	: '',
															'href'	: 'http://abvg.nl/images/projects/' + item.filepath,
															'target': '_blank',
															'border': '0'
														}).inject(filebox);
				var file		= new Element('img',	{	'src'	: 'images/f1.gif',
															'styles': {
																'width'	: '30px',
																'height': '30px',
																'float'	: 'left',
																'border': '0',
																'position' : 'relative',
																'top'	: '5px',
																'margin-bottom' : '-18px',
																'padding-bottom' : '30px',
																'padding-right' : '10px'
															}
														}).inject(filelink);
				var infobox		= new Element('span',		{	'html'	: 'Right Click to Download<br>',
																'styles': {
																	'color'		: '#777',
																	'font-size'	: '9px'
																}
															}).inject(filebox);
				var filepath = item.filepath.substring(0,item.filepath.length - 11); 
				var filelink	= new Element('a',		{	'html'	: filepath,
																'href'	: 'http://abvg.nl/images/projects/' + item.filepath,
																'target': '_blank'
														}).inject(filebox);
						
			};
			

						
			if (!gallery) el.inject(projectcontent);
			
			
		});
		var fillitem	= new Element('div',	{'class': 'filler'}).inject(projectcontent);
		
		// if(img_el.get('html')) img_el.inject(projectcontent, 'top');
		
		
		//myContents.hide();
		//myContents.slideIn();
		
		var initMilk = function() {
			
		}
		// var trowMilk = initMilk.delay(3000);
		
		Milkbox.initialize();	
			
		


	};

	
	$('zoekform_word').addEvent('keyup', function(e) {
		e.stop();
		var request = new Request.JSON({
			url: 'data/abvg.php?s=' + $('zoeker').value,
			
			onRequest: function() {
				projectcontent.empty();
				//projectlist.setStyle('opacity','0.001');
				$('wrapper').tween('left', (window.getWidth() - (widthMenu + widthList)) / 2);
			},
			onComplete: function(jsonObj) {
				//if (projectlist.get('tween')) projectlist.get('tween').cancel();
				//projectlist.tween('opacity','0.001','1');
				projectlist.empty();
				refreshList(jsonObj.items, jsonObj.searchinfo);
			}
		}).send();
	});
	
		
	var openProject = function(uid) {
		selectedFromList = 'uid' + uid;
		
		projectlist.getElements('div[class=list_TITLE]').each(function(el) {
			el.setStyle('color','#333');
		});
		projectlist.getElements('div[class=list_ITEM]').each(function(el) {
			el.setStyle('background-color','#eee');
			el.getElement('div[class=list_TITLE]').setStyle('color','#333');
			el.getElement('div[class=list_YEAR]').setStyle('color','#333');
			el.getElement('div[class=list_SUBTITLE]').setStyle('color','#333');
			el.getElement('div[class=list_TYPE]').setStyle('color','#333');
		});
		$('uid' + uid).getElement('div[class=list_TITLE]').setStyle('color','#fff');
		$('uid' + uid).getElement('div[class=list_YEAR]').setStyle('color','#fff');
		$('uid' + uid).getElement('div[class=list_SUBTITLE]').setStyle('color','#fff');
		$('uid' + uid).getElement('div[class=list_TYPE]').setStyle('color','#fff');
		$('uid' + uid).setStyle('background-color','#333');
						
		var ganal = $('uid' + uid).getElement('div[class=list_TITLE]').get('html');
		ganal = ganal.replace(/[^a-zA-Z0-9]+/g,'_');
		pageTracker._trackPageview("/Projects/Project/" + ganal);
		
		var request = new Request.JSON({
			url: 'data/abvg.php?c=' + uid,
			onRequest: function() {
				projectcontent.setStyle('visibility','hidden');
				var top_position = projectlist.getElement('div[id=uid' + uid + ']').getPosition().y - $('wrapper').getCoordinates().top - 2;
				projectcontent.setStyle('top', top_position);
			 	$('wrapper').tween('left', (window.getWidth() - (widthMenu + widthList + widthContent)) / 2);
			},
			onComplete: function(jsonObj) {
				projectcontent.empty();
				refreshContent(jsonObj.contents);
				projectcontent.setStyle('opacity','0.001');
				projectcontent.tween('opacity','0.001','1');
				
			}
		}).send();
		
		
	};
	
	
	
	var menublock = new Fx.Slide('menublock');
	menublock.hide();
	
	
	var zoekblock = new Fx.Slide('zoekblock');
	zoekblock.hide();
	
	var form_type = new Fx.Slide('form_type');
	form_type.hide();
	var form_word = new Fx.Slide('form_word');
	form_word.hide();
	var form_tags = new Fx.Slide('form_tags');
	form_tags.hide();
	
	
	var p_button = new Boolean();
	p_button = false;
	i_button = false;
	c_button = false;
	
	(function(){ menublock.slideIn()}).delay(3000);
	
	$('logo').addEvent('click', function(e) {
		e.stop();
		menublock.slideIn();
		pageTracker._trackPageview("/Menu/Logo");
	});
	
	$('zoek_type').addEvent('click', function(e) {
		e.stop();
		$('zoek_type').set('class','button_switch_on');
		$('zoek_word').set('class','button_switch_off');
		$('zoek_tags').set('class','button_switch_off');
		
		form_type.slideIn();
		form_word.slideOut();
		form_tags.slideOut();
		(function(){ zoekblock.slideIn()}).delay(500);
		pageTracker._trackPageview("/Project/Function/Type");
	});
	
	$('zoek_word').addEvent('click', function(e) {
		e.stop();
		$('zoek_type').set('class','button_switch_off');
		$('zoek_word').set('class','button_switch_on');
		$('zoek_tags').set('class','button_switch_off');
		form_word.slideIn();
		form_type.slideOut();
		form_tags.slideOut();
		(function(){ zoekblock.slideIn()}).delay(500);
		pageTracker._trackPageview("/Project/Function/Word");
	
	});
	
	$('zoek_tags').addEvent('click', function(e) {
		e.stop();
		$('zoek_type').set('class','button_switch_off');
		$('zoek_word').set('class','button_switch_off');
		$('zoek_tags').set('class','button_switch_on');
		form_tags.slideIn();
		form_type.slideOut();
		form_word.slideOut();
		(function(){ zoekblock.slideIn()}).delay(500);
		pageTracker._trackPageview("/Project/Function/Tags");
	
	});
	

	
	var selectedFromMenu = '';
	var menu_projects_firstclick = true;
	
	$('menu_projecten').addEvent('click', function(e) {
		e.stop();
		selectedFromMenu = 'projecten';
		if (i_button) {
			i_button = !i_button;
			$('menu_info').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_info').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_info').getElement('div[class=buttonbarb_active]').set('class','buttonbarb');
			
		
		};
		if (c_button) {
			c_button = !c_button;
			$('menu_contact').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_contact').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_contact').getElement('div[class=buttonbarb_active]').set('class','buttonbarb');
		};
		if (p_button) {
			p_button = !p_button;
			if(zoekblock) zoekblock.cancel();
			zoekblock.slideOut();
			projectlist.empty();
			projectcontent.empty();
			$('wrapper').tween('left', (window.getWidth() - ($('mainmenu').getCoordinates().width + $('projectlist').getCoordinates().width + $('projectcontents').getCoordinates().width)) / 2);
			
			$('menu_projecten').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_projecten').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_projecten').getElement('div[class=buttonbarb_active_dark]').set('class','buttonbarb');
		} else {
			
			p_button = !p_button;
			if(zoekblock) zoekblock.cancel();
			zoekblock.slideIn();
			(function(){ menublock.slideIn()}).delay(500);
			projectlist.setStyle('top', $('menu_projecten').getPosition().y.toInt() - 101);	
			if(menu_projects_firstclick) {
				
				(function(){ 
					$('zoek_type').set('class','button_switch_on');
					$('zoek_word').set('class','button_switch_off');
					$('zoek_tags').set('class','button_switch_off');
					
					form_type.slideIn();
					form_word.slideOut();
					form_tags.slideOut();
					(function(){ zoekblock.slideIn()}).delay(500);
	
				}).delay(1000);
				//(function(){ alert('first click')}).delay(1000);
				menu_projects_firstclick = false;
			};
			menuSearch('');
			$('menu_projecten').getElement('div[class=menuitem]').set('class','menuitem_active');
			$('menu_projecten').getElement('div[class=buttonbar]').set('class','buttonbar_active');
			$('menu_projecten').getElement('div[class=buttonbarb]').set('class','buttonbarb_active_dark');
			
			
			pageTracker._trackPageview("/Menu/Projects");
		}
	
	});
	
	
	$('menu_projecten').addEvent('mouseover', function(e) {
		if (selectedFromMenu != 'projecten') {
		
		
		} else {
		
		
		}
	});
	
	
	
		
		
	
	
	$('menu_info').addEvent('click', function(e) {
		e.stop();
		if (p_button) {
			p_button = !p_button;
			$('menu_projecten').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_projecten').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_projecten').getElement('div[class=buttonbarb_active_dark]').set('class','buttonbarb');
		};
		if (c_button) {
			c_button = !c_button;
			$('menu_contact').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_contact').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_contact').getElement('div[class=buttonbarb_active]').set('class','buttonbarb');
		};
		if (i_button) {
			i_button = !i_button;
			$('menu_info').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_info').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_info').getElement('div[class=buttonbarb_active]').set('class','buttonbarb');
			projectlist.empty();
			projectcontent.empty();
		
		} else {
		
			i_button = !i_button;
			$('menu_info').getElement('div[class=menuitem]').set('class','menuitem_active');
			$('menu_info').getElement('div[class=buttonbar]').set('class','buttonbar_active');
			$('menu_info').getElement('div[class=buttonbarb]').set('class','buttonbarb_active');
		
	
			zoekblock.slideOut();
			projectlist.empty();
			projectcontent.empty();
			var newinfo = $('info_window').clone();
			newinfo.inject(projectlist);
			newinfo.setStyle('visibility','visible');
			newinfo.setStyle('opacity','0.001');
			projectlist.setStyle('top', 90);	
			newinfo.tween('opacity','0.001','1');
			$('wrapper').tween('left', (window.getWidth() - ($('mainmenu').getCoordinates().width + $('projectlist').getCoordinates().width + $('projectcontents').getCoordinates().width)) / 2);
			pageTracker._trackPageview("/Menu/Info");
		};
	});
	
	
	
	$('menu_contact').addEvent('click', function(e) {
		e.stop();
		if (p_button) {
			p_button = !p_button;
			$('menu_projecten').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_projecten').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_projecten').getElement('div[class=buttonbarb_active_dark]').set('class','buttonbarb');
		};
		if (i_button) {
			i_button = !i_button;
			$('menu_info').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_info').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_info').getElement('div[class=buttonbarb_active]').set('class','buttonbarb');
			
		
		};
		if (c_button) {
			c_button = !c_button;
			$('menu_contact').getElement('div[class=menuitem_active]').set('class','menuitem');
			$('menu_contact').getElement('div[class=buttonbar_active]').set('class','buttonbar');
			$('menu_contact').getElement('div[class=buttonbarb_active]').set('class','buttonbarb');
			projectlist.empty();
			projectcontent.empty();
		} else {
		
			c_button = !c_button;
			$('menu_contact').getElement('div[class=menuitem]').set('class','menuitem_active');
			$('menu_contact').getElement('div[class=buttonbar]').set('class','buttonbar_active');
			$('menu_contact').getElement('div[class=buttonbarb]').set('class','buttonbarb_active');
			
			zoekblock.slideOut();
			projectlist.empty();
			projectcontent.empty();
			var newcontact = $('contact_window').clone();
			newcontact.inject(projectlist);
			newcontact.setStyle('visibility','visible');
			newcontact.setStyle('opacity','0.001');
			projectlist.setStyle('top', 128);	
			newcontact.tween('opacity','0.001','1');
			
			$('wrapper').tween('left', (window.getWidth() - ($('mainmenu').getCoordinates().width + $('projectlist').getCoordinates().width + $('projectcontents').getCoordinates().width)) / 2);											
			pageTracker._trackPageview("/Menu/Contact");
					
		}
	});
	
	
	$('wrapper').setStyle('left', (window.getWidth() - (widthMenu)) / 2);
	
	$('wrapper').tween('opacity', '0.001','0.8');
	if(Browser.Engine.trident) $('wrapper').tween('opacity', '0.001','1');
	$('wrapper').setStyle('top', '100px');
				
	// Milkbox.showThisImage("images/projects/01.jpg","Caption...");
	//menuSearch('A');
	//startSearch();
});


window.addEvent('resize', function() {
	$('wrapper').tween('left', (this.getWidth() - ($('mainmenu').getCoordinates().width + $('projectlist').getCoordinates().width + $('projectcontents').getCoordinates().width)) / 2);

});