function base64_decode (data) {
    // http://kevin.vanzonneveld.net
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Thunder.m
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_decode
    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'

    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['btoa'] == 'function') {
    //    return btoa(data);
    //}

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];

    if (!data) {
        return data;
    }

    data += '';

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);

    dec = tmp_arr.join('');
    dec = this.utf8_decode(dec);

    return dec;
}

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }

    return tmp_arr.join('');
}

var gMapsMarkers = new Array();
//var gMapsHereInfoWindow = false;
var gMapsActiveMarkers = new Array();
var gMapsActiveRoutes = new Array();
var gGeoXML = false;
var gMapBig;
var current_layer = false;
var mgr = false;
var mgrExtra = false;
var bounds = false;
var batch_extra = false;
var batch = false;
var gGeoXML = false;
var openInfoWindow = false;
var startPunt;
var current_marker = false;
var eersteMarker = false;
var currentSubcatMenu = false;
var currentMapType = false;

var morphFooter = false;
var morphSubcat = false;
var morphSubcatList = false;
var morphSubcatListNew = false;
var openeersteMaker = true;

var melding = new Element('div', {
	'html': '<h4><Selecteer een categorie</h4>'
});

// Load-events
window.addEvent('load', function() {
	var myFx = null;//new Fx.Scroll(window).toElement('footer_plattegrond');							 
	loadPlattegrond();	
	loadPlattegrondItems();
});

window.addEvent('domready', function() {
	initExtra();
});

// Load Plattegrond via Ajax and inject into the footer
function loadPlattegrond() {
	addPlattegrondFunctions();
	initializeGoogleMapsBigNew(51.261915, 6.004028);
}


// Adds functions to the Plattegrond page
function addPlattegrondFunctions() {
	$$('#footer_plattegrond ul.filters li').each(function(value,key) {
		value.getElement('a').addEvent('click', function(e) {
			if(e) {
				e.stop();
			}
			if (melding) melding.dispose();
			// Change button status
			if (this && !this.hasClass('active')) {
				var currentElement = this;
				
				// Show filters for current category
				var clickedCat = this.getProperty('rel');

				$$('div.subcategorie div.subcat_animator').setStyles({
					'display':'none',
					'left': 270
				});
				if ($('subcat'+clickedCat)) {
					$('subcat'+clickedCat).setStyles({
						'display':'block',
						'left': 0
					});
				}
				$$('#footer_plattegrond ul.filters li a').removeClass('active');
				currentElement.addClass('active');
				
				// klap menu uit als dit nog niet is gedaan
				if ($('uitklap').hasClass('ingeklapt')) { klapuit(); }
				
				addSubcategoryFunctions();
				
				setGoogleMapsBigMarker(clickedCat, false, false);

			}
			else {
				$$('#footer_plattegrond ul.filters li a').removeClass('active');
				setGoogleMapsBigMarker(false, false, false);
				currentElement = false;
				mgr.clearMarkers();
				mgr = false;
				$$('div.subcat_animator').setStyle('display','none');
				melding.inject($('categorie'));
				//melding.setStyle('top','0');
			}
		});
	});
}

function InfowinGroot(latlng, html) {
	this.latlng_ = latlng;
	this.html_ = html;
	this.prototype = new GOverlay();

	// Creates the DIV representing the infowindow
	this.initialize = function(map) {
		var infoWindow = new Element('div', {
			'class': 'googlemaps_infowindow big',
			'events': {
				'click': function() {
					this.setStyle('display', 'none');
				}
			}
		});
		var infoWindowContent = new Element('div', {
			'class': 'content'
		});
		infoWindowContent.inject(infoWindow);
		
		infoWindow.inject(map.getPane(G_MAP_FLOAT_PANE));
	
		this.map_ = map;
		this.div_ = infoWindow;
		this.update(this.html_);
	}
	
	this.update = function(html) {
		$(this.div_).getElement('div').set('html', html);
		this.redraw(true);
	}
	
	// Remove the main DIV from the map pane
	this.remove = function() {
		$(this.div_).dispose();
	}

	// Copy our data to a new instance
	this.copy = function() {
		return new InfowinGroot(this.latlng_, this.html_);
	}

	// Redraw based on the current projection and zoom level
	this.redraw = function(force) {
		if (!force) return;

		var point = this.map_.fromLatLngToDivPixel(this.latlng_);
		
		// Now position our DIV based on the DIV coordinates of our bounds
		$(this.div_).setStyles({
			left: point.x - 331,
			top: point.y - 188  - 18
		});
	}
	
	this.show = function() {
		//$$('div.googlemaps_infowindow').setStyle('display', 'none');	
		$(this.div_).setStyle('display', 'block');	
	}
	
	this.hide = function() {
		$(this.div_).setStyle('display', 'none');	
	}
}

// New function to initialize big plattegrond (googlemaps)
function initializeGoogleMapsBigNew(lat, lng) {
	// Destination container exist
	if ($$('#footer_plattegrond div.googlemaps')[0]) {
		
		// Browser is GMaps compatible
		if (GBrowserIsCompatible()) {
			// Instantiate GoogleMaps v2
			gMapBig = new GMap2($$('#footer_plattegrond div.googlemaps')[0]);
			
			GEvent.addListener(gMapBig, "load", function() {
				if (this.isLoaded()) {
					clearDom(false);
				}
			});
				
			function customControls() {}
			customControls.prototype = new GControl();
			customControls.prototype.initialize = function(map) {
				
				// create control elements
				var container = new Element('div', {
					'class': 'googlemaps_controls'
				});
				var zoomInDiv = new Element('div', {
					'class': 'zoomin'
				});
				var zoomOutDiv = new Element('div', {
					'class': 'zoomout'
				});
				var topDiv = new Element('div', {
					'class': 'top'
				});
				var rightDiv = new Element('div', {
					'class': 'right'
				});
				var bottomDiv = new Element('div', {
					'class': 'bottom'
				});
				var leftDiv = new Element('div', {
					'class': 'left'
				});
	
				// add elements to the container
				zoomInDiv.inject(container);
				zoomOutDiv.inject(container);
				topDiv.inject(container);
				rightDiv.inject(container);
				bottomDiv.inject(container);
				leftDiv.inject(container);
				
				// add event listeners
				GEvent.addDomListener(zoomInDiv, "click", function() {
					map.zoomIn();
				}); 
				GEvent.addDomListener(zoomOutDiv, "click", function() {
					map.zoomOut();  
				});
				GEvent.addDomListener(topDiv, "click", function() {
					map.panDirection(0,1);  
				}); 
				GEvent.addDomListener(rightDiv, "click", function() {
					map.panDirection(-1,0);  
				}); 
				GEvent.addDomListener(bottomDiv, "click", function() {
					map.panDirection(0,-1);  
				}); 
				GEvent.addDomListener(leftDiv, "click", function() {
					map.panDirection(1,0);  
				}); 
				
				var container2 = new Element('div', {
					'class': 'googlemaps_controls_view'
				});
				var normal = new Element('div', {
					'class': 'normal active'
				});
				var satelliet = new Element('div', {
					'class': 'satelliet'
				});
				var terrein = new Element('div', {
					'class': 'terrein'
				});
				
				GEvent.addDomListener(normal, "click", function() {
					currentMapType.removeClass('active');
					gMapBig.setMapType(G_NORMAL_MAP); 
					this.addClass('active');
					currentMapType = this;
				});
				GEvent.addDomListener(satelliet, "click", function() {
					currentMapType.removeClass('active');											   
					gMapBig.setMapType(G_HYBRID_MAP);
					this.addClass('active');
					currentMapType = this;
				});
				GEvent.addDomListener(terrein, "click", function() {
					currentMapType.removeClass('active');											 	
					gMapBig.setMapType(G_PHYSICAL_MAP);
					this.addClass('active');
					currentMapType = this;
				});
				
				currentMapType = normal;
				
				normal.inject(container2);
				satelliet.inject(container2);
				terrein.inject(container2);
				
				// add the controls to googlemaps
				container.inject(map.getContainer());
				container2.inject(map.getContainer());
				return container;
	
			}
			
			customControls.prototype.getDefaultPosition = function() {
				return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(8, 11));
			}
			
			// Add custom controls
			gMapBig.addControl(new customControls());
			
			// Get all category/filter/company information and add a marker to the map
			/*
			$$('div.overzicht_item_big').each(function(val,key) {
				// Get company info from the DOM
				var bedrijfInfo = val.innerHTML.split('||');
				
				// Get variables from company
				var bedrijfId = parseInt(bedrijfInfo[0]);
				var bedrijfLat = bedrijfInfo[1];
				var bedrijfLng = bedrijfInfo[2];
				var bedrijfHtml = bedrijfInfo[3];
				var categoryId = parseInt(bedrijfInfo[4]);
				var filterId = parseInt(bedrijfInfo[5]);
				var categoryType = bedrijfInfo[6];
				var xml = '';
				if (bedrijfInfo[7] != '')	{	
					xml = bedrijfInfo[7];
				}
				
				// create a new marker for company / route / event
				var marker = nieuweMarker(bedrijfLat, bedrijfLng, bedrijfHtml, categoryType, 'groot', bedrijfId, filterId, categoryId, xml, val.id);
				
				if (!gMapsMarkers[categoryId]) {
					gMapsMarkers[categoryId] = new Array();
				}
				if (!gMapsMarkers[categoryId][filterId]) {
					gMapsMarkers[categoryId][filterId] = new Array();
				}
				if (!gMapsMarkers[categoryId][filterId][bedrijfId]) {
					gMapsMarkers[categoryId][filterId][bedrijfId] = new Array();
				}
				// Add marker to the marker-list
				gMapsMarkers[categoryId][filterId][bedrijfId] = marker;

			});
			*/
			
			// Create infoWindow for 'U bevind zich hier'
			//var zuilInfo = new Infowin(new GLatLng(lat, lng), '<span>U bent hierrrr</span>', 'big');
			// Save the 'U bevind zich hier' inoWindow
			//gMapsHereInfoWindow = zuilInfo;
			// Add infoWindow to googleMaps
			//gMapBig.addOverlay(zuilInfo);
			
			//Initialize GoogleMaps width default zoom-level
			gMapBig.setCenter(new GLatLng(lat, lng), 9);
			
			// activate the zuilInfo infoWindow
			setGoogleMapsBigMarker(false, false, false);
		}
	}
}

function loadGMapsMarkersIfNeeded(cid) {
	//console.log('/css-js/ajax-json/json_plattegrond_v1.0.php?regio_id='+$('uitklap').getProperty('rel')+'&categorie_id='+cid);
	// JSON Request doen en gMapsMarkers vullen voor de gegeven categorie_id
	$('loader').setStyle('display', 'block');
	var jsonRequest = new Request.JSON({
		async: true,
		url: '/css-js/ajax-json/json_plattegrond_v1.0.php?regio_id='+$('uitklap').getProperty('rel')+'&categorie_id='+cid+'&pid='+$('pageid').get('html'),
		onSuccess: function(totalInfo) {
			//console.log(responseText);
			//console.log(totalInfo);
			totalInfo.marker.each(function(value ,key) {
			
	
			
				// Get variables from company
				var bedrijfId = value.id;
				var bedrijfLat = value.lat;
				var bedrijfLng = value.lng;
				var bedrijfHtml = value.infowindowhtml;
				var categoryId = value.categorie;
				var filterId = value.filter;
				var categoryType = value.type;
				
				// Deze xml-shizzle nog bekijken!!
				if (value.categorie == 21 || value.categorie == 22) {
					var xml = value.id;
				}
				//if (bedrijfInfo[7] != '') {	
				//	xml = bedrijfInfo[7];
				//}



				var marker = nieuweMarker(value.lat, value.lng, value.infowindowhtml, value.type, 'groot', value.id, value.filter, value.categorie, xml, value.element_id_val);

				if (!gMapsMarkers[value.categorie]) {
					gMapsMarkers[value.categorie] = new Array();
				}
				if (!gMapsMarkers[value.categorie][value.filter]) {
					gMapsMarkers[value.categorie][value.filter] = new Array();
				}
				if (!gMapsMarkers[value.categorie][value.filter][value.id]) {
					gMapsMarkers[value.categorie][value.filter][value.id] = new Array();
				}
				// Add marker to the marker-list
				gMapsMarkers[value.categorie][value.filter][value.id] = marker;

			//Initialize GoogleMaps width default zoom-level
			//gMapBig.setCenter(new GLatLng(lat, lng), 15);
			
			// activate the zuilInfo infoWindow
			//setGoogleMapsBigMarker(false, false, false);

			});
			
			setCategoryOnScreen(cid);
			clearDom(false);

		},
		onFailure: function() {
			//if(console)console.log('Failure loading: RouteBeginPunten');
		}
	}).send();	
	
}

// Function adds events to buttons on Plattegrond-Page that will use ajax
function addSubcategoryFunctions() {
	// Store main-subcat-menu
	var previousSubcatMenu = new Array();
	
	$$('div.subcat_animator.category').each(function(value,key) {
		var previousSubcatMenu = new Array();
		previousSubcatMenu.push(value);
		$('container').store('previousSubcatMenu_'+value.getProperty('rel'), previousSubcatMenu);
	});

	// Add events to all menus
	$$('div.subcat_animator').each(function(value, key) {
										 
		// List-Element Buttons
		var listElements = value.getElements('div.subcat_container ul li');
		value.store('aantalSubcatItems', listElements.length);
		value.store('subcatCurrentPage', 1);
		listElements.addEvent('click', function(e) {
			if (e) e.preventDefault();
			if (!(morphSubcatList || morphSubcatListNew)) {
				var subcatItemRel = this.getElement('a').rel;
				// active class weghalen en toevoegen bij current
				activelinks = $$('div.subcat_container a.active');
				if (activelinks) activelinks.removeClass('active');
				this.getElement('a').addClass('active');
				// Animate to next menu
				if (subcatItemRel.substr(0,6)=='filter') {
					var subcatElement = $$('div.subcat_animator.'+subcatItemRel)[0];
					//checkPlattegrondButtons(subcatElement);
					previousSubcatMenu = $('container').retrieve('previousSubcatMenu_'+this.getParent('div').getParent('div').getProperty('rel'));
					previousSubcatMenu.push(subcatElement);
					$('container').store('previousSubcatMenu_'+this.getProperty('rel'), previousSubcatMenu);
					
					currentSubcatMenu = value;
					value.getElement('div.subcat_container').setStyle('overflow','hidden');
					morphSubcatList = new Fx.Morph(value,{duration: 'normal', transition: Fx.Transitions.Sine.easeOut});
					morphSubcatList.addEvent('onComplete', function() {
						morphSubcatList = false;					
						//value.getElement('div.subcat_container').setStyle('overflow','auto');	
					});
					morphSubcatList.start({
						'left': [0, -270]
					});
					subcatElement.setStyle('display', 'block');
					
					var currentListElement = this;
					morphSubcatListNew = new Fx.Morph(subcatElement,{duration: 'normal', transition: Fx.Transitions.Sine.easeOut});
					morphSubcatListNew.addEvent('onComplete', function() {
						subcatElement.getElement('div.subcat_container').setStyle('overflow','auto');											   
						morphSubcatListNew = false;
						if (subcatItemRel.substr(0,6)=='filter') {
							var currentFid = parseInt(subcatItemRel.substr(6));
						}
						else currentFid = false;
						
						// Get current cid
						var currentCid = currentListElement.getParent('div').getParent('div').getProperty('rel');
						setGoogleMapsBigMarker(currentCid, currentFid, false);
						
					});
					morphSubcatListNew.start({
						'left': [270, 0]
					});
					
				}
				// Set icons on googlemaps for current filter or bedrijven
				else if (subcatItemRel.substr(0,3)=='bid') {
					var currentCid = this.getParent('div').getParent('div').getProperty('rel');
					var currentFid = this.getParent('div').getParent('div').getProperty('class').split(' ').getLast().substr(6);
					var currentBid = parseInt(subcatItemRel.substr(3));
					setGoogleMapsBigMarker(currentCid, currentFid, currentBid);	
				}
				// Set icons on googlemaps for events and routes
				else if (subcatItemRel.substr(0,3)=='eid' || subcatItemRel.substr(0,3)=='rid') {
					var currentCid = this.getParent('div').getParent('div').getProperty('rel');
					var currentFid = this.getParent('div').getParent('div').getProperty('class').split(' ').getLast().substr(6);
					var currentBid = parseInt(subcatItemRel.substr(3));
					ma = setGoogleMapsBigMarker(currentCid, currentBid, currentBid);					
				}
				// Set route on googlemaps
				if (subcatItemRel.substr(0,3)=='rid') {
					var currentRid = parseInt(subcatItemRel.substr(3));
					// toon de route op de kaart
					setGoogleMapsBigRoute(currentRid);
					// open popupje
					if (ma) GEvent.trigger(ma, "click");
				}
				
			}
		});
		
		// Back-button
		var backButton = value.getElement('.back');
		if(backButton) {
			backButton.addEvent('click', function(e) {
				if (e) e.stop();
				if (!(morphSubcatList || morphSubcatListNew)) {
					var tempelement = this.getParent().getParent().getElement('div.subcat_container');
					if (tempelement) tempelement.setStyle('overflow','hidden');
					morphSubcatList = new Fx.Morph(this.getParent().getParent(),{duration: 'normal', transition: Fx.Transitions.Sine.easeOut});
					morphSubcatList.addEvent('onComplete', function() {
						//tempelement.setStyle('overflow','auto');											
						morphSubcatList = false;							
					});
					morphSubcatList.start({
						'left': [0, 270]
					});
					
					var tempelement2 = previousSubcatMenu.getLast().getElement('div.subcat_container');
					if (tempelement2) tempelement2.setStyle('overflow','hidden');
					previousSubcatMenu = $('container').retrieve('previousSubcatMenu_'+this.getParent().getProperty('rel'));
					previousSubcatMenu.pop();
					$('container').store('previousSubcatMenu_'+this.getProperty('rel'), previousSubcatMenu);
					
					morphSubcatListNew = new Fx.Morph(previousSubcatMenu.getLast(),{duration: 'normal', transition: Fx.Transitions.Sine.easeOut});
					morphSubcatListNew.addEvent('onComplete', function() {
						//tempelement2.setStyle('overflow','auto');											   
						morphSubcatListNew = false;									
					});
					morphSubcatListNew.start({
						'left': [-270, 0]
					});
				}
			});
		}
		
	});
		
	$$('div.subcat_animator.category').each(function(value,key) {
		$('container').retrieve('previousSubcatMenu_'+value.getProperty('rel')).getLast();
		//checkPlattegrondButtons($('container').retrieve('previousSubcatMenu_'+value.getProperty('rel')).getLast());
	});
	return false;
}

// Sets the markers and/or infowindow of the current googlemaps
function setGoogleMapsBigMarker(cid, fid, bid) {
	
	if (gGeoXML) gMapBig.removeOverlay(gGeoXML);
	//gMapsHereInfoWindow.hide();
	// Show 'U bevindt zicht hier' info window

	if (cid == false && fid == false && bid == false) {
		//gMapsHereInfoWindow.show();
		
		// hide the previous infoWindow
		if (current_marker) {// && current_marker != gMapsHereInfoWindow) {
			gMapBig.removeOverlay(current_marker);
		}
		
		// set the new current infowindow
		//current_marker = gMapsHereInfoWindow;
		
		// calculate move to the infoWindow
		var currentPoint = gMapBig.fromLatLngToContainerPixel(gMapBig.getCenter());
		var diffX = currentPoint.x - 49;
		var diffY = currentPoint.y;
		var diff = gMapBig.fromContainerPixelToLatLng(new GPoint(diffX, diffY));
		// Move to center
		gMapBig.panTo(diff);
	}
	// Just the category is given
	else if (cid != false && fid == false && bid == false) {
		// hide the previous infoWindow
		if (current_marker) {
			gMapBig.removeOverlay(current_marker);
		}
		// set the new current infowindow
		current_marker = false;
		
		gMapsActiveMarkers = new Array();
		
		// Array for companies
		var companiesToShow = new Array();
		// Loop trough all companies
		
		if (!gMapsMarkers[cid]) {
			loadGMapsMarkersIfNeeded(cid);
		}
		else {
			setCategoryOnScreen(cid);	
		}
		/*
		if (gMapsMarkers[cid]) {
			gMapsMarkers[cid].each(function(value, key) {
				if (value) {
					value.each(function(val, k) {
						if (val) {
							companiesToShow[k] = val;	
						}
					});
				}
			});
		}
		setCenter(companiesToShow);
		*/
	}
	// Category & Filter is given
	else if (cid != false && fid != false && bid == false) {
		// hide the previous infoWindow
		if (current_marker) {
			gMapBig.removeOverlay(current_marker);
		}
		// set the new current infowindow
		current_marker = false;
		
		// Deactive all active markers
		gMapsActiveMarkers = new Array();
		
		// Array for companies
		var companiesToShow = new Array();

		/*
		if (!gMapsMarkers[cid]) {
			loadGMapsMarkersIfNeeded(cid);
		}
		else {
			setCategoryOnScreen(cid);	
		}
		*/

		// Loop trough all companies
		if (gMapsMarkers[cid] && gMapsMarkers[cid][fid]) {
			gMapsMarkers[cid][fid].each(function(value, key) {
				if (value) {
					companiesToShow[key] = value;			
				}
			});
		}
		setCenter(companiesToShow);
	}
	// Category, Filter and Company is given
	else if (cid != false && fid != false && bid != false) {
		// hide the previous infoWindow
		
		if (current_marker) {
			gMapBig.removeOverlay(current_marker);
		}
		// set the new current infowindow
		current_marker = false;
		
		if (gMapsMarkers[cid] && gMapsMarkers[cid][fid] && gMapsMarkers[cid][fid][bid]) {
			// set the new current infowindow
			var m = gMapsMarkers[cid][fid][bid];
			// Trigger a click on the marker (opens infowindow and moves the map)
			GEvent.trigger(m, "click");
		}
		
		if (m) return m;
	}
	
	return false;
}

function setCategoryOnScreen(cid) {
	var companiesToShow = new Array();
	gMapsMarkers[cid].each(function(value, key) {
		if (value) {
			value.each(function(val, k) {
				if (val) {
					companiesToShow[k] = val;	
				}
			});
		}
	});
	setCenter(companiesToShow);
}

// Sets the route of the current googlemaps
function setGoogleMapsBigRoute(rid) {
	if (gGeoXML) gMapBig.removeOverlay(gGeoXML);
	
	// regio ophalen voor kleur van de lijn
	var regio = $('uitklap');
	
	//console.log('http://www.limburgbeginthier.nl/xml/xml.routes.php?regio='+regio.rel+'&route_id='+rid);
	
	gGeoXML = new GGeoXml('http://www.limburgbeginthier.nl/xml/xml.routes.php?regio='+regio.rel+'&route_id='+rid);
	//console.log(gGeoXML);
	//console.log(gGeoXML.hasLoaded());
	// Add GeoXML to the map
	gMapBig.addOverlay(gGeoXML);
	
	// centreren en inzoomen van de kaart
	GEvent.addListener(gGeoXML, "load", function() {
		if (this.hasLoaded()) {
			if (gMapBig.getBoundsZoomLevel(this.getDefaultBounds()) > 5) {
				if (this.getDefaultBounds()) gMapBig.setCenter(this.getDefaultBounds().getCenter(), gMapBig.getBoundsZoomLevel(this.getDefaultBounds())-1);
			}
		}
	});
	
}

// Returns the iconoptions
function createGoogleMapsBigIcon(iconName) {
	var gMapsIconBig = new GIcon(G_DEFAULT_ICON);
	gMapsIconBig.iconSize = new GSize(32,32);
	gMapsIconBig.image = "/img/icons"+trim(iconName);
	gMapsIconBig.shadow = "";
	gMapsIconBig.iconAnchor = new GPoint(16,30);
	gMapsIconBig.imageMap = Array(5,2,27,2,28,3,29,4,29,24,28,25,27,26,20,26,16,30,12,26,5,26,4,26,3,24,3,4,4,3);
	var markerOptions = { icon:gMapsIconBig };
	return markerOptions;
}

function trim(value) {
	if (value == '' || value == undefined) return "";
	value = value.replace(/^\s+/,'');
	value = value.replace(/\s+$/,'');
	return value;
}

// extraas voor op plattegrond
function initExtra() {
	var v = $$('ul#extras li');
	for (i=0;i<v.length;i++) {
		value = v[i].getElement('a');
		if (value.rel != '') {
			// extras voor op plattegrond
			if (value.rel.substr(0,5) == 'extra') {
				value.addEvent('click', function() {
					zetuit = false;
					if (this && this.hasClass('active')) {
						zetuit = true;
					}
					uncheckExtra();
					toggleExtra('leeg');
					
					if (mgrExtra == false) {
						mgrExtra = new MarkerManager(gMapBig);
					}	
					if (current_marker) {
						gMapBig.removeOverlay(current_marker);
					}
					/*if (openInfoWindow) {
						openInfoWindow.hide();	
						openInfoWindow = false;
					}*/
					
					if (zetuit == false) {
						var v = $$('div.'+this.rel);
						batch_extra = [];
						
						for (i=0;i<v.length;i++) {
							h = v[i].innerHTML.split('||');
							marker = nieuweMarker(h[0], h[1], h[2], h[3], 'klein', -1, -1, -1, ''); 
							batch_extra.push(marker);
						}
						mgrExtra.clearMarkers();
						mgrExtra.addMarkers(batch_extra, 3);
						mgrExtra.refresh();	
						
						this.addClass('active');
						setCenterTotal();
					}
					else {
						mgrExtra.clearMarkers();
						mgrExtra.refresh();
					}
				});
			}
			else {
				// wikipedia, youtube, photo
				value.addEvent('click', function() {
					if (mgrExtra != false) {
						mgrExtra.clearMarkers();
						mgrExtra.refresh();
					}
					if (this && this.hasClass('active')) {
						uncheckExtra();	
						toggleExtra('leeg');
					}
					else {
						uncheckExtra();	
						toggleExtra(this.rel);	
						this.addClass('active');
					}
				});
			}
		}
	}	
}

// uncheck alle extra items (ul li a)
function uncheckExtra() {
	$$('ul#extras li a').removeClass('active');
}

// toggle extra from gmaps
function toggleExtra(type) {
	var layer;
	switch(type) {
		case "wikipedia":	
			layer = new GLayer("org.wikipedia.nl");
			break;
		case "foto":	
			layer = new GLayer("com.panoramio.all");
			break;
		case "video":	
			layer = new GLayer("com.youtube.all");
			break;
		case "":
		case "leeg":
			layer = false;
			break;
	}
	if (current_layer != false) {
		gMapBig.removeOverlay(current_layer);
	}
	if (layer != false) {
		current_layer = layer;
		gMapBig.addOverlay(layer);
	}
}

// maak een nieuwe marker aan met een infowindow
function nieuweMarker(lat, lng, html, type, formaat, bedrijf, filterid, catid, xml, val) {
	
	var marker = new GMarker(new GLatLng(lat, lng), createGoogleMapsBigIcon(type) );
	marker.xml = xml;
	marker.val = val;
	// create the info window for company
	// Add events to the marker
	GEvent.addListener(marker, "click", function(e) {
		if (current_marker) {
			gMapBig.removeOverlay(current_marker);
		}
		
		// route tekenen
		if (this.xml) {
			setGoogleMapsBigRoute(this.xml);	
		}
		// linkermenu actieve waarde zetten
		if (val && $('c'+val)) {	
			activelinks = $$('div.subcat_container a.active');
			if (activelinks) activelinks.removeClass('active');
			$('c'+val).addClass('active');			
		}
		if (formaat == 'groot') var info = new InfowinGroot(new GLatLng(lat, lng), html, ' big');	
		else var info = new Infowin(new GLatLng(lat, lng), html, ' big');	
		current_marker = info;
		gMapBig.addOverlay(current_marker);
		// show the infoWindow from clicked-marker
		current_marker.show();
		// hide the previous infoWindow
		//if (openInfoWindow) { openInfoWindow.hide(); openInfoWindow = false; }
		// set the new current infowindow
		
		
		// get the current position of the current infoWindow
		var currentPoint = gMapBig.fromLatLngToContainerPixel(info.latlng_);
		var diffX = currentPoint.x - 49;
		var diffY = currentPoint.y - 75;
		
		var diff = gMapBig.fromContainerPixelToLatLng(new GPoint(diffX, diffY));
		// Move to new infoWindow
		gMapBig.panTo(diff);
	});
	
	/*b = getUrlRequest('bid');
	if (!b) b = getUrlRequest('rid');
	if (!b) b = getUrlRequest('eid');
	f = getUrlRequest('fid');
	c = getUrlRequest('cid');
	
	if (b && b == bedrijf && catid == c) {
		openInfoWindow = info;	
		current_marker = info;	
		startPunt = new GLatLng(lat, lng);
	}
	
	gMapBig.addOverlay(info);*/
	
	return marker;
}

// zet de kaart in het midden
function setCenter(companiesToShow) {
	// Create boundaries variable
	if (mgr == false) {
		mgr = new MarkerManager(gMapBig);
	}
	else {
		mgr.clearMarkers();
	}
	// Show companiesToShow
	batch = [];
	companiesToShow.each(function(value, key) {
		if (value) {
			batch.push(value);
			gMapsActiveMarkers[key] = value;
		}
	});
	mgr.addMarkers(batch, 3);
	mgr.refresh();
	
	setCenterTotal();
	$('loader').style.display = 'none';
}

// centreer alles op de kaart
function setCenterTotal() {
	if (!batch && !batch_extra) return false;
	bounds = new GLatLngBounds();	
	if (batch) {
		for (i=0; i< batch.length;i++) {
			bounds.extend(batch[i].getPoint());	
		}
	}
	if (batch_extra) {
		for (i=0; i< batch_extra.length;i++) {
			bounds.extend(batch_extra[i].getPoint());	
		}
	}
	var zoomLevel = gMapBig.getBoundsZoomLevel(bounds) - 1;
	if (zoomLevel < 0) {
		zoomLevel = 0;	
	}
	gMapBig.checkResize();
	// Set zoom-level
	gMapBig.setZoom(zoomLevel);
	// Pan-to center of bound
	gMapBig.panTo(bounds.getCenter());
	
}

function openMarker() {
	if (eersteMarker && openeersteMaker)	 {
		eersteMarker.fireEvent('click');	
		eersteMarker = false;
		openeersteMaker = false;
	}
}

// dom leegmaken ivm geheugen
function clearDom(dontFire) {
	//$$('.overzicht_item_big').each( function(value,key) {
	//	value.dispose();
	//});
	$('loader').style.display = 'none';
	
	if (!dontFire) {
		//if (openeersteMaker) {
		
			var cCid = getUrlRequest('cid');
			if (false) {
				if (cCid) $$('li.cid'+cCid)[0].getElement('a').fireEvent('click');
					
				var cFid = getUrlRequest('fid');
				if (cFid) $$('li.filterli'+cFid)[0].fireEvent('click');
				
				var cBid = getUrlRequest('bid');
				var cRid = getUrlRequest('rid');
				var cEid = getUrlRequest('eid');
				
				if (cBid) {
					eersteMarker = $$('div.subcat_container.fid'+cFid+' ul li.bidli'+cBid)[0];
					setTimeout("openMarker()", 2000);
				}
				else if (cRid) {
					 eersteMarker = $$('div#subcat'+cCid+' div.subcat_container ul li.rid'+cRid)[0];
					 setTimeout("openMarker()", 2000);
				}
				else if (cEid) {
					eersteMarker = $$('div#subcat'+cCid+' div.subcat_container ul li.eid'+cEid)[0];
					setTimeout("openMarker()", 2000);
				}
			}
		//}
		//openeersteMaker = false;
	}
}


// animeer item 
function morph(id, width, left, speed) {
	var morphAnimatorNew = new Fx.Morph($(id),{duration: speed, transition: Fx.Transitions.Sine.easeOut});
	morphAnimatorNew.start({
	 'width': width,
	 'left': left
	});
	return morphAnimatorNew;
}

// klap linker balk uit
function klapuit() {
	// check of hoofdcategorie, indien niks geselecteerd, niet uitklappen
	if ($$('#footer_plattegrond ul.filters li a.active').length == 0) {
		if (melding) {
			melding.inject($('categorie'));
			//melding.setStyle('display','block');
		}
	} else {
		if (melding) melding.dispose();
	}
	morph('googlemaps_column', 670, 270, 500);
	morph('shaduw', 17, 270, 500);
	morph('categorie', 270, 0, 500);
	morph('extra', 255, 0, 500);
	
	var myEffect = new Fx.Morph({duration: 'short', transition: Fx.Transitions.Sine.easeOut});
	
	var v = morph('uitklap', 16, 254, 500);					
	v.onComplete = function() {
		$('uitklap').removeClass('ingeklapt');		
		$$('div.subcat_container').setStyle('overflow','auto');
		if (gMapBig) setCenterTotal();
	}
}

// klap linker balk in
function klapin(speed) {
	$$('div.subcat_container').setStyle('overflow','hidden');
	morph('googlemaps_column', 924, 16, speed);
	morph('shaduw', 17, 16, speed);
	morph('categorie', 270, -270, speed);
	morph('extra', 255, -272, speed);
	var v = morph('uitklap', 16, 0, speed);						
	v.onComplete = function() {
		$('uitklap').addClass('ingeklapt');
		if (gMapBig) setCenterTotal();
	}
}

function loadPlattegrondItems(){
	// knop voor in en uitklappen
	$('uitklap').addEvent('click', function(e) {
		e.preventDefault();
				
		// uitklappen
		if (this && this.hasClass('ingeklapt')) { klapuit(); }
		// inklappen
		else { klapin(500); }
	});	
	
	// resize googlemaps hoogte
	var hoogte = window.getCoordinates().height;
	
	if (hoogte < 700) {// 1024
		$('plattegrond').addClass('laag');
		$$('div#footer_plattegrond div.content')[0].addClass('laag');
		var platgrondheight = $$('div#footer_plattegrond div.content')[0].getCoordinates().height;
		$('loader').setStyle('height', platgrondheight);
	}
	else if (hoogte < 900) {// 1280
		$('plattegrond').addClass('middel');
		$$('div#footer_plattegrond div.content')[0].addClass('middel');
		var platgrondheight = $$('div#footer_plattegrond div.content')[0].getCoordinates().height;
		$('loader').setStyle('height', platgrondheight);
	}	
	
}

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5 4(c,b){2 e=3;e.13=c;e.D=c.1k();e.1h=c.1V().1N();b=b||{};e.N=4.1f;2 g=c.29();2 h=g[0].1o();l(2 i=0;i<g.E;i++){2 f=g[i].1o();7(f>h){h=f}}e.p=b.1J||h;e.18=b.1E;e.m=b.15||C;2 d;7(28 b.1s==="24"){d=b.1s}11{d=4.1q}e.1p=w q(-d,d);e.1j=w q(d,-d);e.1Y=d;e.B=[];e.H=[];e.H[e.p]=[];e.s=[];e.s[e.p]=0;X.1e(c,"1U",e,e.1d);e.r=5(a){c.1L(a);e.G--};e.t=5(a){7(e.m){c.1G(a);e.G++}};e.U();e.G=0;e.8=e.V()}4.1f=1C;4.1q=1z;4.1w=1x;4.6.U=5(){2 a=3;2 c=4.1w;l(2 b=0;b<=a.p;++b){a.H[b]=[];a.s[b]=0;a.B[b]=o.2c(c/a.N);c<<=1}};4.6.27=5(){2 a=3;a.v(a.8,a.r);a.U()};4.6.n=5(a,c,b){2 d=3.1h.25(a,c);9 w 23(o.1r((d.x+b.22)/3.N),o.1r((d.y+b.1Z)/3.N))};4.6.10=5(e,a,f){2 b=e.Z();e.1n=a;7(3.18){X.1e(e,"1m",3,3.1l)}2 d=3.n(b,f,q.A);l(2 c=f;c>=a;c--){2 g=3.Y(d.x,d.y,c);g.1i(e);d.x=d.x>>1;d.y=d.y>>1}};4.6.F=5(e){2 a=3;2 c=a.8.J<=e.y&&e.y<=a.8.I;2 f=a.8.M;2 d=f<=e.x&&e.x<=a.8.K;7(!d&&f<0){2 b=a.B[a.8.z];d=f+b<=e.x&&e.x<=b-1}9 c&&d};4.6.1l=5(e,i,g){2 c=3;2 a=c.p;2 f=O;2 h=c.n(i,a,q.A);2 d=c.n(g,a,q.A);1g(a>=0&&(h.x!==d.x||h.y!==d.y)){2 b=c.L(h.x,h.y,a);7(b){7(c.W(b,e)){c.Y(d.x,d.y,a).1i(e)}}7(a===c.D){7(c.F(h)){7(!c.F(d)){c.r(e);f=C}}11{7(c.F(d)){c.t(e);f=C}}}h.x=h.x>>1;h.y=h.y>>1;d.x=d.x>>1;d.y=d.y>>1;--a}7(f){c.u()}};4.6.1T=5(e){2 c=3;2 b=c.p;2 a=O;2 f=e.Z();2 d=c.n(f,b,q.A);1g(b>=0){2 g=c.L(d.x,d.y,b);7(g){c.W(g,e)}7(b===c.D){7(c.F(d)){c.r(e);a=C}}d.x=d.x>>1;d.y=d.y>>1;--b}7(a){c.u()}c.s[e.1n]--};4.6.1S=5(b,a,c){2 d=3.R(c);l(2 i=b.E-1;i>=0;i--){3.10(b[i],a,d)}3.s[a]+=b.E};4.6.R=5(a){9 a||3.p};4.6.1Q=5(a){2 b=0;l(2 z=0;z<=a;z++){b+=3.s[z]}9 b};4.6.1P=5(e,b,a){2 d=3;2 h=w 1O(e,b);2 g=d.n(h,a,q.A);2 f=w 1M(h);2 c=d.L(g.x,g.y,a);7(c!=1b){l(2 i=0;i<c.E;i++){7(e==c[i].1a().1K()&&b==c[i].1a().T()){f=c[i]}}}9 f};4.6.1I=5(e,a,c){2 b=3;2 f=3.R(c);b.10(e,a,f);2 d=b.n(e.Z(),b.D,q.A);7(b.F(d)&&a<=b.8.z&&b.8.z<=f){b.t(e);b.u()}3.s[a]++};19.6.1H=5(a){2 b=3;9(b.M<=a.x&&b.K>=a.x&&b.J<=a.y&&b.I>=a.y)};4.6.Y=5(x,y,z){2 b=3.H[z];7(x<0){x+=3.B[z]}2 c=b[x];7(!c){c=b[x]=[];9(c[y]=[])}2 a=c[y];7(!a){9(c[y]=[])}9 a};4.6.L=5(x,y,z){2 a=3.H[z];7(x<0){x+=3.B[z]}2 b=a[x];9 b?b[y]:1b};4.6.17=5(j,b,c,e){b=o.S(b,3.p);2 i=j.1F();2 f=j.1D();2 d=3.n(i,b,c);2 g=3.n(f,b,e);2 a=3.B[b];7(f.T()<i.T()||g.x<d.x){d.x-=a}7(g.x-d.x+1>=a){d.x=0;g.x=a-1}2 h=w 19([d,g]);h.z=b;9 h};4.6.V=5(){2 a=3;9 a.17(a.13.1R(),a.D,a.1p,a.1j)};4.6.1d=5(){2 a=3;a.16(3,3.1c,0)};4.6.16=5(b,a,c){9 1B.1A(5(){a.1W(b)},c)};4.6.1X=5(){9 3.m?C:O};4.6.1y=5(){9!3.m};4.6.15=5(){3.m=C;3.P()};4.6.20=5(){3.m=O;3.P()};4.6.21=5(){3.m=!3.m;3.P()};4.6.P=5(){2 a=3;7(a.G>0){a.v(a.8,a.r)}7(a.m){a.v(a.8,a.t)}a.u()};4.6.1c=5(){2 a=3;a.D=3.13.1k();2 b=a.V();7(b.2d(a.8)&&b.z===a.8.z){9}7(b.z!==a.8.z){a.v(a.8,a.r);7(a.m){a.v(b,a.t)}}11{a.14(a.8,b,a.1v);7(a.m){a.14(b,a.8,a.1u)}}a.8=b;a.u()};4.6.u=5(){X.2b(3,"1m",3.8,3.G)};4.6.v=5(b,a){l(2 x=b.M;x<=b.K;x++){l(2 y=b.J;y<=b.I;y++){3.Q(x,y,b.z,a)}}};4.6.Q=5(x,y,z,a){2 b=3.L(x,y,z);7(b){l(2 i=b.E-1;i>=0;i--){a(b[i])}}};4.6.1v=5(x,y,z){3.Q(x,y,z,3.r)};4.6.1u=5(x,y,z){3.Q(x,y,z,3.t)};4.6.14=5(c,d,a){2 b=3;b.1t(c,d,5(x,y){a.2a(b,[x,y,c.z])})};4.6.1t=5(j,k,b){2 f=j.M;2 a=j.J;2 d=j.K;2 h=j.I;2 g=k.M;2 c=k.J;2 e=k.K;2 i=k.I;2 x,y;l(x=f;x<=d;x++){l(y=a;y<=h&&y<c;y++){b(x,y)}l(y=o.12(i+1,a);y<=h;y++){b(x,y)}}l(y=o.12(a,c);y<=o.S(h,i);y++){l(x=o.S(d+1,g)-1;x>=f;x--){b(x,y)}l(x=o.12(f,e+1);x<=d;x++){b(x,y)}}};4.6.W=5(a,c,b){2 d=0;l(2 i=0;i<a.E;++i){7(a[i]===c||(b&&a[i]===c)){a.26(i--,1);d++}}9 d};',62,138,'||var|this|MarkerManager|function|prototype|if|shownBounds_|return||||||||||||for|show_|getTilePoint_|Math|maxZoom_|GSize|removeOverlay_|numMarkers_|addOverlay_|notifyListeners_|processAll_|new||||ZERO|gridWidth_|true|mapZoom_|length|isGridPointVisible_|shownMarkers_|grid_|maxY|minY|maxX|getGridCellNoCreate_|minX|tileSize_|false|refresh|processCellMarkers_|getOptMaxZoom_|min|lng|resetManager_|getMapGridBounds_|removeFromArray_|GEvent|getGridCellCreate_|getPoint|addMarkerBatch_|else|max|map_|rectangleDiff_|show|objectSetTimeout_|getGridBounds_|trackMarkers_|GBounds|getLatLng|undefined|updateMarkers_|onMapMoveEnd_|bind|DEFAULT_TILE_SIZE_|while|projection_|push|nePadding_|getZoom|onMarkerMoved_|changed|MarkerManager_minZoom|getMaximumResolution|swPadding_|DEFAULT_BORDER_PADDING_|floor|borderPadding|rectangleDiffCoords_|addCellMarkers_|removeCellMarkers_|MERCATOR_ZOOM_LEVEL_ZERO_RANGE|256|isHidden|100|setTimeout|window|1024|getNorthEast|trackMarkers|getSouthWest|addOverlay|containsPoint|addMarker|maxZoom|lat|removeOverlay|GMarker|getProjection|GLatLng|getMarker|getMarkerCount|getBounds|addMarkers|removeMarker|moveend|getCurrentMapType|call|visible|borderPadding_|height|hide|toggle|width|GPoint|number|fromLatLngToPixel|splice|clearMarkers|typeof|getMapTypes|apply|trigger|ceil|equals'.split('|'),0,{}))
