var maps = new Array();
var map = null;

var GoogleMapContentList = new Array();

function addGoogleMapContent(func){
	GoogleMapContentList[GoogleMapContentList.length] = func; 
}

function reloadGoogleMapContent(divId){
		//alert(pntInspect(GoogleMapContentList));
	for(var i=0; i<GoogleMapContentList.length;i++){
		try {
			GoogleMapContentList[i].call();
		} catch(e) {
			if(pntIsDefined(GoogleMapContentList[i][1])){
				//alert(divId);
				//alert(GoogleMapContentList[i][1]);
				if(GoogleMapContentList[i][1] == divId){
					GoogleMapContentList[i][0].call();
				}
			}
		}
	}		
}

function loadGoogleMapContentIntoPage(){	
	for(var i=0; i<googleMapsArray.length;i++){
		addGoogleMapContent(googleMapsArray[i]);
	}		
	reloadGoogleMapContent();
}



/* initializes googleMaps */
function initGoogleMaps(startLat, startLong, zoomLevel, divId, legendDiv){	
	maps[divId] = new GoogleMapHandler(startLat, startLong, zoomLevel, divId);
	maps[divId].legendDiv = (pntIsDefined(legendDiv) ? legendDiv : null);
	return maps[divId];
}




/*-----------------------------------------------------
									GoogleMapHandler class
-------------------------------------------------------*/

/* constructor */
function GoogleMapHandler(startLat, startLong, zoomLevel, divId){
	this.initRegister();	
	this.initDefaultValues();
	this.initMap(startLat, startLong, zoomLevel, divId);
	this.initModes();
	this.initAddons();
	this.initIcons();
	this.initListeners();
}

GoogleMapHandler.prototype.doSearch = function(inputField) {
	// smerige hack om mijn map terug te krijgen

	if(!pntIsDefined(inputField)) return false;
	
	map = this.map;
	map.inputField = inputField;
	var gClientGeocoder = new GClientGeocoder();
	var latlng = gClientGeocoder.getLatLng(inputField.value, this.searchOnGDirectionsAddOverlay);
}

GoogleMapHandler.prototype.searchOnGDirectionsAddOverlay = function(latLng){
	if(!pntIsDefined(latLng)){
		map.inputField.style.background = "#ffcaca";
	} else {
		map.inputField.style.background = "#ffffff";
		map.setCenter(latLng, 11);	
	}
	
}                    

/* initializes all the different modes */
GoogleMapHandler.prototype.initDefaultValues = function() {
	this.defaultZoomLevel = 11;
}


	/* initializes all addons */
GoogleMapHandler.prototype.initAddons = function() {
	////this.googleMapLoadingController = new GoogleMapLoadingController(this);
	//this.getMap().addControl(this.googleMapLoadingController);
}

/* initializes all the different modes */
GoogleMapHandler.prototype.initModes = function() {
	this.googleMapPointSelectionMode = new GoogleMapPointSelectionMode(this);	
	this.googleMapPhotoMode = new GoogleMapPhotoMode(this);
	this.googleMapDirectionMode = new GoogleMapDirectionMode(this);
	
	
	// set default mode
	//this.setCurrentMode(this.googleMapPointSelectionMode);
}

/* initializes the map */
GoogleMapHandler.prototype.initMap = function(startLat, startLong, zoomLevel, divId) {
	if(!pntIsDefined(divId)) divId="googleMaps";
	var container = document.getElementById(divId);
	if (!container) return false;
	this.map = new GMap2(container);
	this.map.googleMapHandler= this;
	this.map.setCenter(new GLatLng(startLat, startLong), zoomLevel);

  this.map.enableScrollWheelZoom();
  
  var gLargeMapControl = new GLargeMapControl();
  var gMapTypeControl = new GMapTypeControl();
  var gSmallZoomControl = new GSmallZoomControl();
  var gScaleControl = new GScaleControl();
  var gSmallMapControl = new GSmallMapControl();
	var gHierarchicalMapTypeControl = new GHierarchicalMapTypeControl();
	
  
  
	this.register['Controls']['gLargeMapControl'] = gLargeMapControl;	
	this.register['Controls']['gMapTypeControl'] = gMapTypeControl;
	this.register['Controls']['gSmallZoomControl'] = gSmallZoomControl;	
	this.register['Controls']['gScaleControl'] = gScaleControl;
	this.register['Controls']['gSmallMapControl'] = gSmallMapControl;		
	this.register['Controls']['gHierarchicalMapTypeControl'] = gHierarchicalMapTypeControl;	
	
  this.map.disableDoubleClickZoom();
  
/*  
  		pn('<div id="googleMapsSearchBar">
		<input maxlength="40" type="text" class="googleMapsSearchBarIput" id="googleMapsSearchBarIput"  value=""  />
		<input type="button" class="googleMapsSearchBarIput" value="" onclick(map.doSearch(document.getElementById(\'googleMapsSearchBarIput\');)) />
		</div>');
*/


	
  
  
}

/* initializes all icon types */
GoogleMapHandler.prototype.initIcons = function(){	
	this.iconSavedLocation = new GIcon(G_DEFAULT_ICON);
	this.iconSavedLocation.image = pntAppUrl+"images/googleMaps/flagRed.png";
	this.iconSavedLocation.shadow = pntAppUrl+"images/googleMaps/flagShadow.png";
	this.iconSavedLocation.iconSize = new GSize(26, 28);
  this.iconSavedLocation.shadowSize = new GSize(40, 28);
  this.iconSavedLocation.infoWindowAnchor = new GPoint(10,30);
  this.iconSavedLocation.description = 'Opgeslagen locatie';
	
	this.locationSelected = new GIcon(G_DEFAULT_ICON);
	this.locationSelected.image = pntAppUrl+"images/googleMaps/flagGreen.png";
	this.locationSelected.shadow = pntAppUrl+"images/googleMaps/flagShadow.png";
	this.locationSelected.iconSize = new GSize(26, 28);
  this.locationSelected.shadowSize = new GSize(40, 28);
  this.locationSelected.description = 'Geselecteerde locatie';
}

GoogleMapHandler.prototype.initListeners = function(){
	GEvent.addListener(this.getMap(),"click", this.mapClickHandler);
	GEvent.addListener(this.getMap(),"load", this.mapLoadHandler);
	GEvent.addListener(this.getMap(),"infowindowclose", this.mainInfowindowclose);
	GEvent.addListener(this.getMap(),"singlerightclick", this.mapSingleRightClickHandler); 
}

GoogleMapHandler.prototype.initRegister = function(){
	this.register = new Array();
	this.register['isInfoWindowOpen'] = false;
	this.register['markers'] = new Array();
	this.register['Controls'] = new Array();	
	this.register['legendIcons'] = new Array();
}



/*-----------------------------------------------------
									 getters and setters 
-------------------------------------------------------*/

/* sets Callback Field */
GoogleMapHandler.prototype.setCallbackField = function(callbackField) {
	if(window.opener != null)
		this.callbackField = window.opener.document.getElementById(callbackField);
	else
		this.callbackField = document.getElementById(callbackField);
	if(typeof this.callbackField == "undefined"){
		alert('callback is undefined!!!');
	}
}

/* returns Callback Field */
GoogleMapHandler.prototype.getCallbackField = function() {
	return this.callbackField;
}

/* returns the map */
GoogleMapHandler.prototype.getMap = function() {
	return this.map;
}

/* sets last known location. This is the last location that was selected on the map*/
GoogleMapHandler.prototype.setLastKnownLocation = function(LastKnownLocation) {
	this.LastKnownLocation = LastKnownLocation;
}

/* returns  last known location. This is the last location that was selected on the map*/
GoogleMapHandler.prototype.getLastKnownLocation = function() {
	return this.LastKnownLocation;
}

/* sets the currentMode. */
GoogleMapHandler.prototype.setCurrentMode = function(mode) {
	this.currentMode = mode;
}

/* returns the currentMode. */
GoogleMapHandler.prototype.getCurrentMode = function() {
	return this.currentMode;
}

/* returns the currentMode. */
GoogleMapHandler.prototype.getDefaultZoomlevel = function() {
	return this.defaultZoomLevel;
}


/*-----------------------------------------------------
									Functions
-------------------------------------------------------*/

GoogleMapHandler.prototype.printLegenda = function() {
	if(pntIsDefined(this.legendDiv)){

		var divEl = document.getElementById(this.legendDiv);
		if(!pntIsDefined(divEl)) return;
		
		divEl.style.display = 'block';
		var icons = this.register['legendIcons'];
		if(pntIsDefined(divEl) && pntIsDefined(icons)){
			divEl.innerHTML = '';
			for(var i=0; i<icons.length; i++){
				var icon = icons[i];
				
				var item = document.createElement('div');
				item.className = 'item';
				
				/* image */
				var itemIcon = document.createElement('div');
				itemIcon.className = 'itemIcon';
				item.appendChild(itemIcon);
				
				var image = document.createElement('img');
				var src = icon.image.replace('png','gif');
				image.setAttribute('src',src);				
				image.setAttribute('alt',icon.description);				
				itemIcon.appendChild(image);
				/* image  END */
				
				//alert(pntInspect(icon));
				/* text */
				var itemText = document.createElement('div');
				itemText.className = 'itemText';
				itemText.innerHTML = icon.description;
				item.appendChild(itemText);				
				/* image  END */
				
				divEl.appendChild(item);
				
				var itemClear = document.createElement('div');
				itemClear.className = 'itemClear';
				divEl.appendChild(itemClear);
			}
		}
	}
	
}

/* performs the callback to the widget field and fills it with the last selected location*/
GoogleMapHandler.prototype.performCallback = function() {
	/* call this function on specific modes */
	this.getCurrentMode().performCallback();
}

/* generates new icon by type */
GoogleMapHandler.prototype.newIcon = function(latlng, markerIcon, onclickHandler, identifier){	
	if(!pntIsDefined(identifier)) identifier = null;
	markerOptions = { icon:markerIcon };
  var marker = new GMarker(latlng,markerOptions);  
	marker.googleMapHandler = this;
	marker.identifier = identifier;
  if(pntIsDefined(onclickHandler)) GEvent.addListener(marker, "click", onclickHandler);
  else GEvent.addListener(marker, "click", function(){});
	this.map.addOverlay(marker);
	
	marker.deleteOnChange = false;
	this.register['markers'][this.register['markers'].length] = marker;
	return marker;
}


GoogleMapHandler.prototype.goToMarker = function(identifier){
	var markers = this.register['markers'];
	for(var i=0; i<markers.length; i++){
		var marker = markers[i];
		if(marker.identifier == identifier){
			this.map.setCenter(marker.getLatLng());
		}
	}
}


GoogleMapHandler.prototype.initNewIcon = function(functionName, description){
		
	if(!pntIsDefined(functionName) || !pntIsDefined(description)){
		alert("functionName or description is missing!");
		return false;
	}
	
	this.register[functionName] = new GIcon(G_DEFAULT_ICON);
	this.register[functionName].googleMapHandler = this;
	this.register[functionName].image = pntAppUrl+"images/googleMaps/"+functionName+".png";

	this.register[functionName].iconSize = new GSize(32, 32);
	this.register[functionName].shadow = "";
	this.register[functionName].imageMap = new Array(0,0,0,100,100,100,100,0);
  this.register[functionName].description = description;

	this.register['legendIcons'][this.register['legendIcons'].length] = this.register[functionName];	
}

/* clear action so that remaining object or variables can be deleted */
GoogleMapHandler.prototype.clearRegister = function(){	
	this.clearMarkers();
}

/* deletes all markers that are not really needed */
GoogleMapHandler.prototype.clearMarkers = function(){	
	var markers =	this.register['markers'];
	for(var i=0; i<markers.length; i++){
		marker = markers[i];
		if(marker.deleteOnChange) {
			marker.remove();
		}
	}
}

/* Center map to location */
/* Function currently not in use */
GoogleMapHandler.prototype.centerMap = function(startLat, startLong){
	
	this.map.setCenter(new GLatLng(startLat, startLong), this.map.getZoom());
	return;
	currentStartLatLng  = this.getMap().getCenter();
	currentEndLatLng = new GLatLng(startLat, startLong);
	
	var map = this.getMap();
	
	var distance = currentStartLatLng.distanceFrom(currentEndLatLng);

	var numRepeats = Math.round(distance/65);
	
	latDelta = Math.abs(map.getCenter().lat() - currentEndLatLng.lat())/numRepeats;
	lngDelta = Math.abs(map.getCenter().lng() - currentEndLatLng.lng())/numRepeats;

	latDelta = parseFloat(latDelta);
	lngDelta = parseFloat(lngDelta);
	if((map.getCenter().lat() - currentEndLatLng.lat()) < 0)
		lat = map.getCenter().lat() - latDelta;
	else {
		lat = map.getCenter().lat() + latDelta;
	}
	
	if((map.getCenter().lat() - currentEndLatLng.lat()) < 0)
		lng = parseFloat(map.getCenter().lng()) - lngDelta;
	else {
		lng = parseFloat(map.getCenter().lng()) + lngDelta;
	}
	
	this.timerHandler(30, numRepeats, (lat/numRepeats), (lng/numRepeats));
}


/* Function currently not in use */
GoogleMapHandler.prototype.timerHandler = function(timeout, numRepeats, lat, lng) {
	alert('Expired function');
	var map = this.getMap();
	var newLat = parseFloat(map.getCenter().lat())+parseFloat(lat);
	var newLng = parseFloat(map.getCenter().lng())+parseFloat(lng);


	if(numRepeats>0) {
		window.setTimeout(function() {
			map.panTo(new GLatLng(newLat,newLng));
			this.timerHandler(timeout, numRepeats-1, lat, lng)
		}, timeout);
	}
}

/* 	
	loads data into google maps. 
	the data is mode specific so all the data is passed to the specific mode.
*/
GoogleMapHandler.prototype.load = function(data) {
	this.getCurrentMode().load(data);
}


/*-----------------------------------------------------
									Default Handlers
-------------------------------------------------------*/
  
/* this is the click handler that handles the click a the map */
GoogleMapHandler.prototype.mapClickHandler = function(overlay, latlng) {
	/* call this function on specific modes */
	this.googleMapHandler.getCurrentMode().mapClickHandler(overlay, latlng);
}

/* This handles a infoWindowCloseAction */
GoogleMapHandler.prototype.mainInfowindowclose = function() {
	this.googleMapHandler.register['isInfoWindowOpen'] = false;
	this.googleMapHandler.clearRegister();
}

/* This handles the map single right click event */
GoogleMapHandler.prototype.mapSingleRightClickHandler = function(point, src, overlay) {
	/* call this function on specific modes */
	this.googleMapHandler.getCurrentMode().mapSingleRightClickHandler(point, src, overlay);
}

/* 	
	This funcion is called right after the maps has been loaded.
	This function is mode specific so all the data is passed to the specific mode.
*/
GoogleMapHandler.prototype.mapLoadHandler = function (){
	this.googleMapHandler.getCurrentMode().mapLoadHandler();
}





/*-----------------------------------------------------
									point selection Mode class
-------------------------------------------------------*/


/* constructor */
function GoogleMapPointSelectionMode(googleMapHandler){
	this.googleMapHandler = googleMapHandler;	
}


	/*-----------------------------------------------------
													Functions
	-------------------------------------------------------*/

/* performs the callback to the widget field and fills it with the last selected location*/
GoogleMapPointSelectionMode.prototype.performCallback = function() {
	field = this.googleMapHandler.getCallbackField();
	if(!field) return false;
	field.value = this.googleMapHandler.getLastKnownLocation();	
	window.close();
}

GoogleMapPointSelectionMode.prototype.load = function(data) {
	this.googleMapHandler.newIcon(data, this.googleMapHandler.iconSavedLocation, this.savedLocationHandler);
}

GoogleMapPointSelectionMode.prototype.activate = function() {	
	this.defineControls();
	this.googleMapHandler.register['legendIcons'][this.googleMapHandler.register['legendIcons'].length] = this.googleMapHandler.iconSavedLocation;
  this.googleMapHandler.register['legendIcons'][this.googleMapHandler.register['legendIcons'].length] = this.googleMapHandler.locationSelected;
	this.googleMapHandler.printLegenda();
}

GoogleMapPointSelectionMode.prototype.defineControls = function() {	
  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gLargeMapControl']);
  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gMapTypeControl']);  
	this.googleMapSearchController = new GoogleMapSearchController(this.googleMapHandler);
	this.googleMapHandler.getMap().addControl(this.googleMapSearchController);
}



	/*-----------------------------------------------------
													Handlers
	-------------------------------------------------------*/
	function pntInspect(what) {
    var output = '';
    for (var i in what)
        output += i+ ' = ' + what[i] + '\r\n';
    return(output);
}

/* this is the click handler that handles the click a the map */
GoogleMapPointSelectionMode.prototype.mapClickHandler = function(overlay, latlng) {
	
	if(!this.googleMapHandler.register['isInfoWindowOpen']){
		this.googleMapHandler.setLastKnownLocation(latlng);
		var marker = this.googleMapHandler.newIcon(latlng, this.googleMapHandler.locationSelected, true);
		marker.deleteOnChange = true;
		var myHtml = 'Wilt u de gekozen locatie gebruiken?<br />'+
		'<div class="infoWindowButtonsWrapper">'+
		'	<div class="infoWindowButtons">'+
		'		<img class="selectLocation" onclick="googleMapHandler.performCallback()" src="'+pntAppUrl+'images/googleMaps/confirm.gif"/>'+
		'		<img class="selectLocation" onclick="GEvent.trigger(googleMapHandler.getMap(), \'click\');" src="'+pntAppUrl+'images/googleMaps/cancel.gif"/>'+
		'	</div>'+
		'</div>';
	  this.googleMapHandler.getMap().openInfoWindow(latlng, myHtml);	  	
	}
}



/* Handles a marker onclick. this one handles a saved location marker */
GoogleMapPointSelectionMode.prototype.savedLocationHandler = function(){	
	this.googleMapHandler.register['isInfoWindowOpen'] = true;
	this.openInfoWindow('Dit is de opgeslagen locatie.'+
	'<div class="infoWindowButtonsWrapper">'+
		'	<div class="infoWindowButtons">'+
		'		<img class="selectLocation" onclick="GEvent.trigger(googleMapHandler.getMap(), \'click\');" src="'+pntAppUrl+'images/googleMaps/cancel.gif"/>'+
		'	</div>'+
		'</div>'
		);
}

/* This handles the map single right click event */
GoogleMapPointSelectionMode.prototype.mapSingleRightClickHandler = function(point, src, overlay) {
	/* do nothing */
}

/* 	
	This funcion is called right after the maps has been loaded.
*/
GoogleMapPointSelectionMode.prototype.mapLoadHandler = function (){
}










/*-----------------------------------------------------
									direction Mode class
-------------------------------------------------------*/


/* constructor */
function GoogleMapDirectionMode(googleMapHandler){
	this.googleMapHandler = googleMapHandler;
	this.pointes = new Array();
	this.init();
}

GoogleMapDirectionMode.prototype.init = function(){
	this.initModes();
	this.initIcons();
	
}

GoogleMapDirectionMode.prototype.autoLoad = function(){
	var caller = this.googleMapHandler.getCallbackField();
	if(typeof caller == "undefined") return false;
	this.load(caller.value);
}

GoogleMapDirectionMode.prototype.initModes = function() {
	this.googleMapDirectionViewMode = new GoogleMapDirectionViewMode(this.googleMapHandler);
	this.googleMapDirectionEditMode = new GoogleMapDirectionEditMode(this.googleMapHandler);
	// set default mode
	this.setCurrentMode(this.googleMapDirectionViewMode);
}

GoogleMapDirectionMode.prototype.initIcons = function() {	
}
		

	/*-----------------------------------------------------
													Functions
	-------------------------------------------------------*/

GoogleMapDirectionMode.prototype.activate = function() {	
	this.defineControls();
	this.googleMapHandler.printLegenda();

}

GoogleMapDirectionMode.prototype.defineControls = function() {	
	this.currentMode.defineControls();
}

/* sets the currentMode. */
GoogleMapDirectionMode.prototype.setCurrentMode = function(mode) {
	this.currentMode = mode;
}

/* returns the currentMode. */
GoogleMapDirectionMode.prototype.getCurrentMode = function() {
	return this.currentMode;
}

/* performs the callback to the widget field and fills it with the last selected location*/
GoogleMapDirectionMode.prototype.performCallback = function() {
	field = this.googleMapHandler.getCallbackField();
	if(!field) return false;
	field.value = "";
	for(var i=0; i < this.googleMapHandler.googleMapDirectionMode.getPoints().length; i++){
		field.value += this.googleMapHandler.googleMapDirectionMode.getPoints()[i].lat();	
		field.value += "," + this.googleMapHandler.googleMapDirectionMode.getPoints()[i].lng() + ",";	
	}
	
	window.opener.loadData();
	window.close();
}

GoogleMapDirectionMode.prototype.addPoint = function(latlng) {
	this.pointes[this.pointes.length] = latlng;
}

GoogleMapDirectionMode.prototype.clearPoints = function() {
	this.pointes = new Array();
}

GoogleMapDirectionMode.prototype.getPoints = function() {
	return this.pointes;
}

GoogleMapDirectionMode.prototype.menuDeletePoint = function(args) {
	this.googleMapHandler.googleMapDirectionMode.deletePoint(args);	
	this.googleMapHandler.googleMapDirectionMode.googleMapMenuController.closeMenu();	
}

GoogleMapDirectionMode.prototype.deletePoint = function(args) {	
	if(this.getPoints().length==1){
		//googleMapDirectionMode.clearAll();
		this.clearPoints();
		this.googleMapHandler.getMap().removeOverlay(args[0]);	
	} else{
		this.clearPoints();
	
		for (var i=0; i < this.newMarkers.length; i++) {
			if(args[0] != this.newMarkers[i]) {
				this.addPoint(this.newMarkers[i].getLatLng());
			}
		}
		this.drawDirections();	
	}
}

GoogleMapDirectionMode.prototype.drawDirections = function(){
	this.googleMapHandler.getMap().clearOverlays();
	if(this.pointes.length==1){
		var point = this.pointes[0];
		var marker = new GMarker(point,{icon:this.getCurrentMode().firstPoint, draggable:true, title:'Draggable'});
		marker.googleMapDirectionMode = this;
		marker.googleMapHandler = this.googleMapHandler;
		GEvent.addListener(marker, "dragend", this.getCurrentMode().firstPointMarkerDragedHandler);		
		GEvent.addListener(marker, "click", this.getCurrentMode().markerClickHandler);
		this.googleMapHandler.getMap().addOverlay(marker);
		
	} else {
		var points = "";
		for (var i=0; i < this.pointes.length; i++){
			var point = this.pointes[i];
			if(i<1) {
				points += "from: " + point.lat() + ", " + point.lng();
			} else {
				points += " to: " + point.lat() + ", " + point.lng();
			}		
		}
		this.directions.load(points,{"getSteps":true,"getPolyline":true});
	}
}

GoogleMapDirectionMode.prototype.load = function(data, color) {
	

	//alert('loading in GoogleMapDirectionMode');
	if(!pntIsDefined(this.directions)){

		this.directions = new GDirections(this.googleMapHandler.getMap());
		this.directions.googleMapHandler = this.googleMapHandler;
		this.directions.color = color;
		GEvent.addListener(this.directions, "error", this.handleErrors);
		GEvent.addListener(this.directions, "addoverlay", this.onGDirectionsAddOverlay); // added to trigger marker swap		
		GEvent.addListener(this.directions, "load", this.pointGDirectionsOnload); 
	}
	this.clearPoints();
	
	if(data)
		this.clearPoints();
		data = data.substr(0, data.length-1);
		
		var points = data.split(",");
		
		if(typeof points == "undefined") return false;
		for (var i=0; i < points.length; i++){
			if(i%2==1){
				var lat = points[i-1];
				var lng = points[i];
				this.addPoint(new GLatLng(lat,lng));
			}
		}
		
		if (points.length >1) {
			this.drawDirections();
		}
}

GoogleMapDirectionMode.prototype.loadDirections = function(routes, centerPoint, zoomlevel) {
	
	//this.googleMapHandler.googleMapLoadingController.startLoading();
	this.clearPoints();	
		this.googleMapHandler.getMap().clearOverlays();
	//alert('loading in GoogleMapDirectionMode');
	//if(!pntIsDefined(this.directions)){
	
	var totalLat = 0;
	var totalLng = 0;
	var totalPoints = 0;
		
	for (var i=0; i < routes.length; i++){
		var tmpArray = new Array();
		
		if(!pntIsDefined(this.directions)){
			this.directions = new GDirections(this.googleMapHandler.getMap());
			this.directions.googleMapHandler = this.googleMapHandler;
			GEvent.addListener(this.directions, "error", this.handleErrors);
			GEvent.addListener(this.directions, "addoverlay", this.onGDirectionsAddOverlay); // added to trigger marker swap
		}
		
		var route = routes[i][0];
		var routeColor = routes[i][1];
		var routeLink = routes[i][2];
		
		routeCor = route.substr(0, route.length-1);
	
		var points = routeCor.split(",");
		if(typeof points == "undefined") return false;
		if(points.length>0){
			for (var j=0; j < points.length; j++){
				if(j%2==1){
					var lat = points[j-1];
					totalLat += parseInt(lat);
					var lng = points[j];
					totalLng += parseInt(lng);
					totalPoints++;
					
					var latLng = new GLatLng(lat,lng);
					latLng.color = routeColor;
					latLng.link = routeLink;
					tmpArray[tmpArray.length] = latLng;
				}
			}
		}
		this.addPoint(tmpArray);
	}
	
	this.drawMultiDirections();
	//alert(totalLat/totalPoints);
	//alert(totalLng/totalPoints);
	//alert(totalPoints);
	//setTimeout("alert('Three seconds has passed.');",3000);
	//alert('123');
	//this.googleMapHandler.map. = totalLat/totalPoints
	//this.googleMapHandler.map. = totalLng/totalPoints
	//this.googleMapHandler.map. = totalLng/totalPoints
	this.googleMapHandler.map.setCenter(new GLatLng(totalLat/totalPoints,totalLng/totalPoints),zoomlevel);
}

GoogleMapDirectionMode.prototype.drawMultiDirections = function(){
	this.googleMapHandler.getMap().clearOverlays();
	var multiPoints = this.pointes;
	var point = null;

	for (var j=0; j < multiPoints.length; j++){
		var points = "";
		for (var i=0; i < multiPoints[j].length; i++){
			point = multiPoints[j][i];
			if(i<1) {
				points += "from: " + point.lat() + ", " + point.lng();
			} else {
				points += " to: " + point.lat() + ", " + point.lng();
			}
		}
		directions = new GDirections(this.googleMapHandler.getMap());
		if(pntIsDefined(point)){
			directions.color = point.color;
			directions.link = point.link;
		} else {
			directions.color = "#000000";
			directions.link = "#";
		}
		directions.googleMapHandler = this.googleMapHandler;
		GEvent.addListener(directions, "addoverlay", this.multiPointOnGDirectionsAddOverlay); // added to trigger marker swap
		GEvent.addListener(directions, "load", this.multipointGDirectionsOnload); 
		
		var testing = directions.load(points,{"getSteps":true,"getPolyline":true,"preserveViewport":true});
	}

}



	/*-----------------------------------------------------
													Handlers
	-------------------------------------------------------*/
	
GoogleMapDirectionMode.prototype.pointGDirectionsClickHandler = function () {
	window.location = this.link;
}

GoogleMapDirectionMode.prototype.multipointGDirectionsOnload = function () {
  var poly = this.getPolyline(); 
  poly.link = this.link;
  GEvent.addListener(poly, "click", this.googleMapHandler.currentMode.pointGDirectionsClickHandler); 
  var color = this.color;
  if(!pntIsDefined(color)){
  	color = "000000";
  }
  poly.color = '#'+color;
}

GoogleMapDirectionMode.prototype.pointGDirectionsOnload = function () {
  var poly = this.getPolyline(); 
  var color = this.color;
  if(!pntIsDefined(color)){
  	color = "000000";
  }
  poly.color = '#'+color;
}


GoogleMapDirectionMode.prototype.multiPointOnGDirectionsAddOverlay = function (dir) {
	//this.directions = dir;
	this.googleMapHandler.googleMapDirectionMode.newMarkers = new Array();
	this.googleMapHandler.googleMapDirectionMode.oldMarkers = new Array();
	
	for (var i=0; i<=this.getNumRoutes(); i++)  {
		this.googleMapHandler.googleMapDirectionMode.oldMarkers[i] = this.getMarker(i);
		this.googleMapHandler.getMap().removeOverlay(this.googleMapHandler.googleMapDirectionMode.oldMarkers[i]);
	}
}

/* this is the click handler that handles the click a the map */
GoogleMapDirectionMode.prototype.mapClickHandler = function(overlay, latlng) {
	this.getCurrentMode().mapClickHandler(overlay, latlng);
}

/* This handles the map single right click event */
GoogleMapDirectionMode.prototype.mapSingleRightClickHandler = function(point, src, overlay) {
	this.getCurrentMode().mapSingleRightClickHandler(point, src, overlay);
}


/* This handles error events on directions */
GoogleMapDirectionMode.prototype.handleErrors = function (err) {
	this.googleMapHandler.googleMapDirectionMode.getCurrentMode().handleErrors(err);
}


/* This handles a addOverlay event on directions */
GoogleMapDirectionMode.prototype.onGDirectionsAddOverlay = function () {
	this.googleMapHandler.googleMapDirectionMode.getCurrentMode().onGDirectionsAddOverlay(this);
}

/* 	
	This funcion is called right after the maps has been loaded.
*/
GoogleMapDirectionMode.prototype.mapLoadHandler = function (){
	alert('test');
	//this.googleMapHandler.googleMapLoadingController.stopLoading();
}








/*-----------------------------------------------------
									Direction View Mode class
-------------------------------------------------------*/


/* constructor */
function GoogleMapDirectionViewMode(googleMapHandler){
	this.googleMapHandler = googleMapHandler;
	this.initIcons();
}

GoogleMapDirectionViewMode.prototype.initIcons = function() {	
	
}

	/*-----------------------------------------------------
													Functions
	-------------------------------------------------------*/

GoogleMapDirectionViewMode.prototype.defineControls = function() {
	if(pntIsDefined(this.googleMapHandler.getMap())){		
		/*
		 var gLargeMapControl = new GLargeMapControl();
  var gMapTypeControl = new GMapTypeControl();
  var gSmallZoomControl = new GSmallZoomControl();
  var gScaleControl = new GScaleControl();
  */
	  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gSmallMapControl']);
	  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gHierarchicalMapTypeControl']);
	  
	  
	}
}


	/*-----------------------------------------------------
													Handlers
	-------------------------------------------------------*/

	
/* this is the click handler that handles the click a the map */
GoogleMapDirectionViewMode.prototype.mapClickHandler = function(overlay, latlng) {
	
}

/* This handles the map single right click event */
GoogleMapDirectionViewMode.prototype.mapSingleRightClickHandler = function(point, src, overlay) {
	
}

/* This handles error events */
GoogleMapDirectionViewMode.prototype.handleErrors = function (err) {
	
}

/* This handles a addOverlay event on directions */
GoogleMapDirectionViewMode.prototype.onGDirectionsAddOverlay = function (dir) {
	//this.directions = dir;
	if(!pntIsDefined(this.googleMapHandler.googleMapDirectionMode.directions)) return;
	this.googleMapHandler.googleMapDirectionMode.newMarkers = Array();
	this.googleMapHandler.googleMapDirectionMode.oldMarkers = Array();
	
	for (var i=0; i<=this.googleMapHandler.googleMapDirectionMode.directions.getNumRoutes(); i++)  {
		this.googleMapHandler.googleMapDirectionMode.oldMarkers[i] = this.googleMapHandler.googleMapDirectionMode.directions.getMarker(i);
		this.googleMapHandler.getMap().removeOverlay(this.googleMapHandler.googleMapDirectionMode.oldMarkers[i]);
	}
}








/*-----------------------------------------------------
									Direction Edit Mode class
-------------------------------------------------------*/


/* constructor */
function GoogleMapDirectionEditMode(googleMapHandler){
	this.googleMapHandler = googleMapHandler;
	this.initIcons();
	
	
}

GoogleMapDirectionEditMode.prototype.initIcons = function() {
	this.firstPoint = new GIcon(G_DEFAULT_ICON);
	this.firstPoint.image = "http://maps.google.com/intl/nl_ALL/mapfiles/marker_greenA.png";
	this.firstPoint.shadow = "http://maps.google.com/intl/nl_ALL/mapfiles/shadow50.png";
	this.firstPoint.iconSize = new GSize(20, 34);
	this.firstPoint.shadowSize = new GSize(37, 34);
	this.firstPoint.maxHeight = 13;
	this.firstPoint.dragCrossImage = "http://maps.google.com/intl/nl_ALL/mapfiles/drag_cross_67_16.png";
	this.firstPoint.transparent = "http://maps.google.com/intl/nl_ALL/mapfiles/markerTransparent.png";
	this.firstPoint.printImage = "http://maps.google.com/intl/nl_ALL/mapfiles/marker_greenAie.gif";
	this.firstPoint.mozPrintImage = "http://maps.google.com/intl/nl_ALL/mapfiles/marker_greenAff.gif";
	this.firstPoint.printShadow = "http://maps.google.com/intl/nl_ALL/mapfiles/dithshadow.gif";
	
	//this.googleMapHandler.register['legendIcons'][this.googleMapHandler.register['legendIcons'].length] = this.firstPoint;
}

	/*-----------------------------------------------------
													Functions
	-------------------------------------------------------*/

GoogleMapDirectionEditMode.prototype.defineControls = function() {
	if(pntIsDefined(this.googleMapHandler.getMap())){		
		//alert(googleMapHandler.register['Controls']['gLargeMapControl']);
	  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gLargeMapControl']);
	  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gMapTypeControl']);
		this.googleMapSearchController = new GoogleMapSearchController(this.googleMapHandler);
		this.googleMapHandler.getMap().addControl(this.googleMapSearchController);
	}
}

	/*-----------------------------------------------------
													Handlers
	-------------------------------------------------------*/

	
/* this is the click handler that handles the click a the map */
GoogleMapDirectionEditMode.prototype.mapClickHandler = function(overlay, latlng) {
	if(!latlng) return;
	if(this.googleMapHandler.googleMapDirectionMode.getPoints().length >= 25){
		alert('Er kunnen geen nieuwe punten meer worden ingevuld. Verwijder eerst oude punten om een nieuwe toe te voegen.');
		return;
	}
	this.googleMapHandler.googleMapDirectionMode.addPoint(latlng);
	
	this.googleMapHandler.googleMapDirectionMode.drawDirections();
}

GoogleMapDirectionEditMode.prototype.mapSingleRightClickHandler = function(point, src, overlay) {
	if(!this.googleMapHandler.register['menuController']) {
		this.googleMapMenuController = new GoogleMapMenuController(this.googleMapHandler);
		this.googleMapHandler.getMap().addControl(this.googleMapMenuController);	
				
		// add title
		this.googleMapMenuController.addTitle("Main Menu");
		this.googleMapMenuController.addSpacer();

	
		// add buttons
		this.googleMapMenuController.addButton('Opslaan', this.googleMapHandler.googleMapDirectionMode.performCallback);
		this.googleMapMenuController.addSpacer();
		
		this.googleMapMenuController.addButton('Sluiten', this.googleMapMenuController.closeMenu);
	
		this.googleMapHandler.register['menuController'] = this.googleMapMenuController;
		
		this.googleMapHandler.googleMapDirectionMode.googleMapMenuController = this.googleMapMenuController;
		
	} else {
		this.googleMapHandler.register['menuController'].closeMenu();
	}
}

/* This handles error events */
GoogleMapDirectionEditMode.prototype.handleErrors = function (err) {
	if (this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
		alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + this.googleMapDirectionMode.directions.getStatus().code);
	}
	else if (this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code == G_GEO_SERVER_ERROR)
	 	alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code);
	
	else if (this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code == G_GEO_MISSING_QUERY)
	 	alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code);
	
	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 
	else if (this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code == G_GEO_BAD_KEY)
	 	alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code);
	
	else if (this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code == G_GEO_BAD_REQUEST){
		alert("Selecteer een tweede locatie om een route te maken.");
		//alert("A directions request could not be successfully parsed.\n Error code: " + googleMapDirectionMode.directions.getStatus().code);
	}
	
	else if (this.googleMapHandler.googleMapDirectionMode.directions.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS){
		this.googleMapHandler.googleMapDirectionMode.deletePoint(this.googleMapHandler.googleMapDirectionMode.pointes[this.googleMapHandler.googleMapDirectionMode.pointes.length-1]);
		this.googleMapHandler.googleMapDirectionMode.drawDirections();
	}	else {
		alert("An unknown error occurred.");
		alert("Error code: "+this.getStatus().code);	
	}
}

/* This handles a addOverlay event on directions */
GoogleMapDirectionEditMode.prototype.onGDirectionsAddOverlay = function () {
	this.googleMapHandler.googleMapDirectionMode.newMarkers = Array();
	this.googleMapHandler.googleMapDirectionMode.oldMarkers = Array();
	
	for (var i=0; i<=this.googleMapHandler.googleMapDirectionMode.directions.getNumRoutes(); i++)  {
		this.googleMapHandler.googleMapDirectionMode.oldMarkers[i] = this.googleMapHandler.googleMapDirectionMode.directions.getMarker(i);
		this.googleMapHandler.getMap().removeOverlay(this.googleMapHandler.googleMapDirectionMode.oldMarkers[i]);
		
		this.googleMapHandler.googleMapDirectionMode.newMarkers[i] = new GMarker(this.googleMapHandler.googleMapDirectionMode.oldMarkers[i].getLatLng(),{icon:this.googleMapHandler.googleMapDirectionMode.oldMarkers[i].getIcon(), draggable:true, title:this.googleMapHandler.googleMapDirectionMode.oldMarkers[i].getTitle()});
		this.googleMapHandler.googleMapDirectionMode.newMarkers[i].googleMapHandler = this.googleMapHandler;
		this.googleMapHandler.getMap().addOverlay(this.googleMapHandler.googleMapDirectionMode.newMarkers[i]);
	
		GEvent.addListener(this.googleMapHandler.googleMapDirectionMode.newMarkers[i], "dragend", this.googleMapHandler.googleMapDirectionMode.googleMapDirectionEditMode.markerDragedHandler);		
		GEvent.addListener(this.googleMapHandler.googleMapDirectionMode.newMarkers[i], "click", this.googleMapHandler.googleMapDirectionMode.googleMapDirectionEditMode.markerClickHandler);
	}
}


/* This handles a marker draged event*/
GoogleMapDirectionEditMode.prototype.firstPointMarkerDragedHandler = function (){
	this.googleMapHandler.googleMapDirectionMode.clearPoints();
	this.googleMapHandler.googleMapDirectionMode.addPoint(this.getLatLng());
	
	//return this.ra;
}

/* This handles a marker draged event*/
GoogleMapDirectionEditMode.prototype.markerDragedHandler = function (){
	this.googleMapHandler.googleMapDirectionMode.clearPoints();
	for (var i=0; i<this.googleMapHandler.googleMapDirectionMode.newMarkers.length; i++) {
		this.googleMapHandler.googleMapDirectionMode.addPoint(this.googleMapHandler.googleMapDirectionMode.newMarkers[i].getLatLng());
	}
	this.googleMapHandler.getMap().clearOverlays();
	
	this.googleMapHandler.googleMapDirectionMode.drawDirections();
	return this.ra;
}

GoogleMapDirectionEditMode.prototype.markerClickHandler = function (event){

	if(!this.googleMapHandler.register['menuController']) {
		this.googleMapMenuController = new GoogleMapMenuController(this.googleMapHandler);
		this.googleMapHandler.getMap().addControl(this.googleMapMenuController);	

		var icon = this.getIcon();
				
		// add title
		this.googleMapMenuController.addTitle("Routepunt", this.getIcon().printImage);
		this.googleMapMenuController.addSpacer();
		
		// add buttons
		this.googleMapMenuController.addButton('Verwijderen', this.googleMapHandler.googleMapDirectionMode.menuDeletePoint, new Array(this));
		this.googleMapMenuController.addSpacer();
		
		this.googleMapMenuController.addButton('Sluiten', this.googleMapMenuController.closeMenu);
	
		this.googleMapHandler.register['menuController'] = this.googleMapMenuController;
		
		this.googleMapHandler.googleMapDirectionMode.googleMapMenuController = this.googleMapMenuController;
	} else {
		this.googleMapHandler.register['menuController'].closeMenu();
	}
}










/*-----------------------------------------------------
									GoogleMapPhotoMode class
-------------------------------------------------------*/

/* constructor */
function GoogleMapPhotoMode(googleMapHandler){
	this.googleMapHandler = googleMapHandler;
	this.photos = new Array();
	
}


	/*-----------------------------------------------------
													Functions
	-------------------------------------------------------*/
GoogleMapPhotoMode.prototype.activate = function(){
	this.defineControls();
}
GoogleMapPhotoMode.prototype.defineControls = function(){
	if(pntIsDefined(this.googleMapHandler.getMap())){		
	  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gSmallMapControl']);
	  this.googleMapHandler.getMap().addControl(this.googleMapHandler.register['Controls']['gHierarchicalMapTypeControl']);
	}
}

/* performs the callback to the widget field and fills it with the last selected location*/
GoogleMapPhotoMode.prototype.addPhoto = function(fullsrc, thumbSrc, title, height, width, latlng, onclickHandler, rel) {
	var mapPane = this.googleMapHandler.getMap().getPane(G_MAP_MAP_PANE);
	mapPane.googleMapHandler = this.googleMapHandler;
	
	var url = document.createElement('a');

	url.className = 'googleMapPhotoLink';
	url.setAttribute('rel',rel);
	url.setAttribute('title',title);
	url.setAttribute('href',fullsrc);
	url.style.position='absolute';
 	url.style.zIndex=1;
 	url.latlng=latlng;


	var img = document.createElement('img');
	img.className = 'googleMapPhoto';
	img.setAttribute('src',thumbSrc);
	img.setAttribute('width',width);
	img.setAttribute('height',height);
	img.setAttribute('alt','Google Maps');
	url.imgWidth = width;	
	url.imgHeight = height;
	url.img = img;
	
	
	var imgPointer = document.createElement('img');
	imgPointer.className = 'googleMapPhotoPointer';
	
	if(window.XMLHttpRequest){
		imgPointer.setAttribute('src',pntAppUrl+'images/googleMaps/photoPointer.png');	
	}else{
		imgPointer.setAttribute('src',pntAppUrl+'images/googleMaps/photoPointer.gif');
	}

	imgPointer.setAttribute('width',17);
	imgPointer.setAttribute('height',17);
	url.imgPointerWidth = 17;	
	url.imgPointerHeight = 17;
	url.imgPointer = imgPointer;

	url.appendChild(img);	
	mapPane.appendChild(url);
	mapPane.appendChild(imgPointer);
	
	this.googleMapHandler.googleMapPhotoMode.setPhotoPosition(url);
 	GEvent.bind(this.googleMapHandler.getMap(),"zoomend",mapPane,function(){this.googleMapHandler.googleMapPhotoMode.setPhotoPosition(url)});
 	GEvent.bind(this.googleMapHandler.getMap(),"moveend",mapPane,function(){this.googleMapHandler.googleMapPhotoMode.setPhotoPosition(url)});

}



GoogleMapPhotoMode.prototype.setPhotoPosition = function(url){

	var d=this.googleMapHandler.getMap().fromLatLngToDivPixel(url.latlng);
	var zoomlevel = this.googleMapHandler.getMap().getZoom()+1; 
	var step = 5.5555555555555555555555555555556; // = 100/18	
	
	url.img.width=Math.round((url.imgWidth/100)*(step*zoomlevel));
	url.img.height=Math.round((url.imgHeight/100)*(step*zoomlevel));
	url.style.top=(d.y-Math.round(url.img.height))-17+'px';
	url.style.left=(d.x-Math.round(url.img.width))-17+'px';
	
	
	//url.imgPointer.width=Math.round((url.imgPointerWidth/100)*(step*zoomlevel));
	//url.imgPointer.height=Math.round((url.imgPointerHeight/100)*(step*zoomlevel));
	url.imgPointer.style.top=(d.y+4-17)+'px';
	url.imgPointer.style.left=(d.x+1-17)+'px';	
}



	/*-----------------------------------------------------
													Handlers
	-------------------------------------------------------*/

	
/* this is the click handler that handles the click a the map */
GoogleMapPhotoMode.prototype.mapClickHandler = function(overlay, latlng) {
	
}

/* This handles the map single right click event */
GoogleMapPhotoMode.prototype.mapSingleRightClickHandler = function(point, src, overlay) {
	
}














/*-----------------------------------------------------
											MenuController class
-------------------------------------------------------*/
function GoogleMapMenuController(googleMapHandler) {
	this.googleMapHandler = googleMapHandler;
	
}

var GoogleMapMenuController;



function initGoogleMapMenuController() {
	GoogleMapMenuController.prototype = new GControl();

	
	GoogleMapMenuController.prototype.initialize = function() {
	  var container = document.createElement("div");
	  container.id = "googleMapsMenuContainer";
	  
	  this.googleMapHandler.getMap().getContainer().appendChild(container);	
	  this.setContainer(container);
	  return container;
	}
		
	
	GoogleMapMenuController.prototype.setContainer = function(container) {
		this.container = container
	}
	
	GoogleMapMenuController.prototype.getContainer = function() {
		return this.container;
	}
	
	GoogleMapMenuController.prototype.addButton = function(text, singleClickhandler, args) {
		if(!text || !singleClickhandler) return;
	
		var container = this.getContainer();
	 	var button = document.createElement("div");
	  button.className = "googleMapsMenuContainerButton";
	  button.googleMapHandler = this.googleMapHandler;
	  
	  container.appendChild(button);
	  button.appendChild(document.createTextNode(text));
	 	if (typeof args == 'undefined' ) {
	  	GEvent.addDomListener(button, "click", singleClickhandler);  
	  } else {
	  	button.onclick = function() { singleClickhandler(args); } 
	  }
	}
	
	GoogleMapMenuController.prototype.addSpacer = function() {
		
		var container = this.getContainer();
	 	var spacer = document.createElement("div");
	  spacer.className = "googleMapsMenuContainerspacer";  
	  container.appendChild(spacer);
	}
	
	GoogleMapMenuController.prototype.addTitle = function(value, icon) {
		var container = this.getContainer();
	 	var textContainer = document.createElement("div"); 	
	  textContainer.className = "googleMapsMenuContainertitleContainer"; 
	
	 	var text = document.createElement("div")
	 	text.innerHTML += value;
	 	text.className = "googleMapsMenuContainertitle";
	 	
	 	textContainer.appendChild(text); 
	  if (typeof icon != "undefined" && icon != "") {
	 		textContainer.innerHTML += '<div class="googleMapsMenuContainertitleImageContainer"><img class="googleMapsMenuContainertitleImage" src="'+icon+'" /></div>';
	 	}
	 
		container.appendChild(textContainer);
	  var clearDiv = document.createElement("div");
	  
	  clearDiv.className = "clearDiv";  
	  container.appendChild(clearDiv);
	}
	
	GoogleMapMenuController.prototype.closeMenu = function() {
		this.googleMapHandler.getMap().removeControl(this.googleMapHandler.register['menuController']);
		this.googleMapHandler.register['menuController'] = null;
	}
	
	GoogleMapMenuController.prototype.getDefaultPosition = function() {
	  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 35));
	}

}




/*-----------------------------------------------------
											SearchController class
-------------------------------------------------------*/
function GoogleMapSearchController(googleMapHandler) {
	this.googleMapHandler = googleMapHandler;
	
}

var GoogleMapSearchController;


function initGoogleMapSearchController() {
	GoogleMapSearchController.prototype = new GControl();

	GoogleMapSearchController.prototype.initialize = function() {
	  var container = document.createElement("div");
	  container.id = "googleMapsSearchBar";
	  
	  var imageContainer = document.createElement("div"); 	
	 	imageContainer.id="googleMapsSearchBarImage"; 	
	 	imageContainer.className="googleMapsSearchBarImage";
	 	
	 	var image = document.createElement("img");
	 	image.src=pntAppUrl+"images/googleMaps/searchButton.gif";
	 	image.googleMapHandler = this.googleMapHandler;
	 	image.onclick = function() {this.googleMapHandler.doSearch(document.getElementById('googleMapsSearchBarInput')); }
	 	imageContainer.appendChild(image);
	 	
	 	var queryFieldContainer = document.createElement("div"); 	
	 	queryFieldContainer.id="googleMapsSearchBarInput"; 
	 	queryFieldContainer.className="googleMapsSearchBarInput";
	 	
	 	var queryField = document.createElement("input"); 	
	 	queryField.id="googleMapsSearchBarInputQueryField"; 	
	 	queryField.type="text";
	 	queryField.googleMapSearchController = this;
	 	queryField.onkeydown = function(event) {this.googleMapSearchController.keyDownHandler(event, document.getElementById('googleMapsSearchBarInputQueryField')); }
	 	queryFieldContainer.appendChild(queryField);
	 	
	  container.appendChild(queryFieldContainer);
	  container.appendChild(imageContainer);
	  this.googleMapHandler.getMap().getContainer().appendChild(container);	
	  this.setContainer(container);
	  return container;
	}

	
	GoogleMapSearchController.prototype.keyDownHandler = function(e, el) {
		var keynum = 0;
		//alert(pntInspect(e));
		//alert(pntInspect(window.event));
		if(window.event) {
	  	keynum = window.event.keyCode;
	  } else if(e.which) {
	 	 	keynum = e.which;
	  }
	  
		if(keynum == 13) {
			this.googleMapHandler.doSearch(el);
		}
	}
	
	GoogleMapSearchController.prototype.setContainer = function(container) {
		this.container = container
	}
	
	GoogleMapSearchController.prototype.getContainer = function() {
		return this.container;
	}
	
	
	GoogleMapSearchController.prototype.getDefaultPosition = function() {
	  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 19));
	}
	

    
}




/*


/*-----------------------------------------------------
											GoogleMapLoadingController class
-------------------------------------------------------*/
/*
function GoogleMapLoadingController(googleMapHandler) {
	this.googleMapHandler = googleMapHandler;
	
}

GoogleMapLoadingController.prototype = new GControl();


GoogleMapLoadingController.prototype.initialize = function() {
  var container = document.createElement("div");
  container.id = "googleMapsLoadingBar";
  container.innerHTML = ''+
	'<div id="googleMapsContentLoading">'+
		'<div id="googleMapsContentLoadingInnerWrapper">'+
			'<div id="googleMapsContentLoadingInner">'+
				'<div id="googleMapsContentLoadingInnerLoadingBar"></div>' +
			'</div>'+ 
		'</div>'+ 
	'</div>';
	
  this.container = container;
  return container;
  
}

GoogleMapLoadingController.prototype.startLoading = function() {
	this.googleMapHandler.getMap().getContainer().appendChild(this.container);	
}

GoogleMapLoadingController.prototype.stopLoading = function() {
	this.googleMapHandler.getMap().getContainer().removeChild(this.container);	
}


GoogleMapLoadingController.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 19));
}


*/

pntAppendToInit(initGoogleMapMenuController);
pntAppendToInit(initGoogleMapSearchController);