// ---------------------------------------------------------------------
// JAVASCRIPT	: Kamper GUI, Google MAP library
// REVISION		: v1.1 9 juni 2008
//				  v1.2 13 nov 2009 - vMode FOTO added, popup PHOTO only	
// ---------------------------------------------------------------------
//

/* EXAMPLE CODE
// Images MAP : /images/
// 3 type of images : 1) icon, icon, schadow, thumbnail img pop-up

var map=null, markManager=null, focusPoint=null;

window.onload = function() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("googleMap"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var rowID = kgui_findID("myHome");
		focusPoint = new GLatLng(DB[rowID].lat, DB[rowID].lng);
		map.setCenter( focusPoint, DB[rowID].zoom );
		kgui_showGroup("dietplus");

		// KGUI, activatie / deactivate when Scanning for LOCATION, on click
		GEvent.addListener(map, "click", function(marker, point) { map.openInfoWindow( point, "lat:"+Math.round(point.y*100000+3)/100000+",lng:"+Math.round(point.x*100000+8)/100000 , {maxWidth:200} );});
	} else alert ( "ERROR : Uw browser wordt niet ondersteund door Google maps!" ) ;
}

// -- HTML Code

<style type="text/css">
<!--
#googleMap {
	height: 480px;
	width: 640px;
	border: 1px solid #FF0000;
}
-->
</style>
<div id="googleMap"></div>
*/

var DBpoly = new Array ({id:"",t:"",desc:"",points:"gox_Ionbc@`AkBfFgIn@tCv@s@d@pCe@^zDiD]kCUUcA}DwArBo@mAtEyGd@tAbBqBpBeB`FuBx@xEj@e@`@xCqC`NgBxDjBbGqKlNcFrGoByLgGnB{@gN",levels:"BBBBBBBBBBBBBBBBBBBBBBBBBBBBB",gr:"regio",Polyline:null,listener:null});

var map=null, markManager=null, focusPoint=null;
var omtrekCirkel=null;
var cookieNo=1; 
var imagePath="/kamperkogge/images/";

/*
var DB = new Array (
{id:"KoggeHomeParkeer",t:"Koggewerf parkeren",desc:"",lat:52.5626,lng:5.90981,gr:"homebase",tmb:"mark_parkeren.png",icon:"mark_parkeren.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"KoggeHomeBusTrein",t:"Openbaar vervoer",desc:"",lat:52.56002,lng:5.92157,gr:"homebase",tmb:"mark_busTrein.png",icon:"mark_busTrein.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"KoggeHome",t:"Koggewerf",desc:"Thuisbasis van de Kamper Kogge.<br>Havenweg 7<br>8262 BZ Kampen",lat:52.56334,lng:5.91159,gr:"homebase",tmb:"mark_kogge_home.png",icon:"mark_kogge_home.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:15,marker:null,listener:null},

{id:"rkkerk",t:"R.K. kerk",desc:"Bijzondere oecumenische dienst in de R.K.Buitenkerk<br>Zondagmorgen 17 mei om 11.00 uur<br>Buiten Nieuwstraat 101",lat:52.5617,lng:5.91236,gr:"rkkerk",tmb:"mark_myHome.png",icon:"mark_myHome.png",shad:"mark_myHomeSchaduw.png",lnk:"",zoom:15,marker:null,listener:null},

{id:"StartOmmeland",t:"IJsselkade",desc:"Vertrekpunt Kamper Kogge Ommelandvaart 7 juni 2004",lat:52.56002,lng:5.91686,gr:"Ommelandvaart",tmb:"mark_kogge_home.png",icon:"mark_kogge_home.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:8,marker:null,listener:null},
{id:"Stavoren",t:"Stavoren",desc:"Ommelandvaart 7,8 juni 2004",lat:52.88594,lng:5.35755,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Terschelling1",t:"Terschelling",desc:"Ommelandvaart 8,11 juni 2004",lat:53.35881,lng:5.21705,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Laeso",t:"Laeso",desc:"Ommelandvaart gepland 25,26 juni 2004. I.v.m. altenatieve route overgeslagen.",lat:57.2833,lng:11.08262,gr:"Ommelandvaart",tmb:"mark_kogge_NOvisit.png",icon:"mark_kogge_NOvisit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Anholt",t:"Anholt",desc:"Ommelandvaart gepland 26,27 juni 2004. I.v.m. altenatieve route overgeslagen.",lat:56.71083,lng:11.51585,gr:"Ommelandvaart",tmb:"mark_kogge_NOvisit.png",icon:"mark_kogge_NOvisit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Esbjerg",t:"Esbjerg",desc:"Ommelandvaart 13,14 juni 2004 wegens slecht voor alternatieve route gekozen.",lat:55.30896,lng:6.92403,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Helgoland",t:"Helgoland",desc:"Ommelandvaart 14,15 juni 2004",lat:54.17283,lng:7.89454,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Cuxhaven",t:"Cuxhaven",desc:"Ommelandvaart 15,16 juni 2004",lat:53.86414,lng:8.71329,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Brunsbuttel",t:"Brunsbuttel",desc:"Ommelandvaart langs Brunsbuttel het Kielerkanaal in, 16 juni 2004",lat:53.88121,lng:9.12988,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Kielerkanaal",t:"Kielerkanaal",desc:"Ommelandvaart, 16 juni en 27 juli 2004 gesleept door het volgschip de Carlot door het Kielerkanaal",lat:54.32071,lng:9.71207,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Kerteminde",t:"Kerteminde",desc:"Ommelandvaart, 17,18 juni 2004 Kogge en de Carlot afgemeerd in Kerteminde bij Odense.",lat:55.44674,lng:10.65588,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Skagen",t:"Skagen",desc:"Ommelandvaart i.v.m. alternatieve route 19,24 juni 2004.",lat:57.71928,lng:10.591,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Helsingborg",t:"Helsingborg",desc:"Ommelandvaart 26,28 juni 2004",lat:56.0453,lng:12.69002,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Malmo",t:"Malmo",desc:"Ommelandvaart 28 juni, 4 juli 2004",lat:55.61492,lng:12.99489,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Stralsund",t:"Stralsund",desc:"Ommelandvaart 6,8 juli 2004",lat:54.31329,lng:13.09941,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Rostock",t:"Rostock",desc:"Ommelandvaart 9,11 juli 2004",lat:54.09196,lng:12.13739,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Wismar",t:"Wismar",desc:"Ommelandvaart 12,14 juli 2004",lat:53.89645,lng:11.45308,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Lubeck",t:"Lubeck",desc:"Ommelandvaart 15,16 juli 2004",lat:53.88955,lng:10.70153,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Rudkoebing",t:"Rudkoebing",desc:"Ommelandvaart 17 juli 2004",lat:54.94082,lng:10.70714,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Svendborg",t:"Svendborg",desc:"Ommelandvaart 18,20 juli 2004",lat:55.06004,lng:10.61546,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Aeroskoebing",t:"Aeroskoebing",desc:"Ommelandvaart 21,22 juli 2004",lat:55.06004,lng:10.61546,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Kiel",t:"Kiel",desc:"Ommelandvaart 24,26 juli 2004",lat:54.3266,lng:10.16297,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"Bremerhaven",t:"Bremerhaven",desc:"Ommelandvaart 28,31 juli 2004",lat:53.53393,lng:8.57784,gr:"Ommelandvaart",tmb:"mark_kogge_visit.png",icon:"mark_kogge_visit.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null},
{id:"KoggeOmEind",t:"Koggewerf",desc:"Ommelandvaart vervroegde thuiskomst op 2 augustus 2004 09:00 uur",lat:52.56334,lng:5.91159,gr:"Ommelandvaart",tmb:"mark_kogge_home.png",icon:"mark_kogge_home.png",shad:"mark_koggeschaduw.png",lnk:"",zoom:14,marker:null,listener:null}
); 
*/

// ---------------------------------------------------------------------
// FOTO OVERLAY
// Version v1.0 13-11-2009
// ZIE : http://code.google.com/intl/nl/apis/maps/documentation/overlays.html#Custom_Overlays
// This file 'kgui_googlemap.js', must be called after loading the googlemap library. Bottom HTML file.
// ---------------------------------------------------------------------

function myPhoto(imageName, locXY) {
	this.imageName_ = imageName;	// onthouden intern
	this.locXY_     = locXY;		// GLatLng
} // myPhoto()
myPhoto.prototype = new GOverlay();		// Aanvulling standaard GOverlay()

// Creates the DIV representing this rectangle.
myPhoto.prototype.initialize = function(map) {
	// Create the DIV representing our Photo rectangle
	var div = document.createElement("div");
	div.style.position = "absolute";
	div.setAttribute('class', "gmapThumbGB");
//  div.style.border = this.weight_ + "px solid " + this.color_;
//	div.style.backgroundColor = "#FFFFFF";

	var img = document.createElement("img");
	img.setAttribute('src', this.imageName_);
	img.setAttribute('alt', 'alternate text');
	img.setAttribute('width', '60px');
	img.setAttribute('height', '45px');
//	span.innerHTML = "<b>HTML Span tag</b> created by using Javascript DOM dynamically.";
	div.appendChild(img);

	// Our rectangle is flat against the map, so we add our selves to the
	// MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
	// below the marker shadows)
	map.getPane(G_MAP_MAP_PANE).appendChild(div);		// 

	this.map_ = map;		// Function Parameter, map.addOverlay ( new myPhoto ( DB[0].tmb, gebied ) );
	this.div_ = div;		// Just created <DIV>
	this.img_ = img;		// Just created <IMG>
} // myPhoto.prototype.initialize()

// Remove the main DIV from the map pane
myPhoto.prototype.remove = function() {
	this.div_.parentNode.removeChild(this.div_);
} // myPhoto.prototype.remove()

// Copy our data to a new Rectangle
myPhoto.prototype.copy = function() {
	return new myPhoto(this.imageName_, this.locXY_, this.backgroundColor_, this.opacity_);
} //myPhoto.prototype.copy()

// Redraw the rectangle based on the current projection and zoom level
myPhoto.prototype.redraw = function(force) {
	// We only need to redraw if the coordinate system has changed
	if (!force) return;

	var myPoint = this.map_.fromLatLngToDivPixel(this.locXY_);
	// Now position our DIV based on the DIV coordinates of our boundss
	this.div_.style.left = myPoint.x + "px";
	this.div_.style.top = (myPoint.y-12) + "px"; 	// Correctie gmap_thmb_bg IMAGE BACKGROUND pointer
}

// ======================================================

function kgui_clickOptie (obj) {
	var lat,lng;

	switch (obj.name) {
		case "mapopties" :
			if (obj.checked) kgui_showGroup(obj.value);
			else kgui_removeGroup(obj.value);
			break;

		default :
			alert ("kgui_clickOptie ("+obj.name+") wordt niet afgehandeld");
			break;
	}
} // kgui_clickOptie()

function kgui_showGroup(vGroep,vMode) {		// v1.1 13-11-2009 vMode 'FOTO' | 'ADRES' added
// Toont alle MARKERS van een groep, zie 'gr:' optie.
// indien vGroep = ALL dan wordt alles getoond en niet gekeken naar de  'gr:' optie.
	var len=DB.length, retVal=0;
	if ( vGroep == "ALL" ) { // Zet alles op de map.
		for (var i=0; i<len; i++) kgui_addSymbolToMap(DB[i].id,vMode);
		retVal = len;
	} else { // Doorzoek de lijst op specifieke groepen.
		for (var i=0; i<len; i++)
			if ( DB[i].gr.indexOf(vGroep) >=0 ) {
				kgui_addSymbolToMap(DB[i].id,vMode);
				retVal++;}}
	return retVal; // Geef terug het aantal object dat op de kaart is gezet.
} // kgui_showGroup()

function kgui_removeGroup(vGroep) {	// v1.0
// Verwijdert een groep 'vGroep' of alle MARKERS van de map.
	var len=DB.length, retVal=0;
	if ( vGroep == "ALL" ) { // Verwijder alles op de map.
		for (var i=0; i<len; i++) {
			if (DB[i].marker!=null) { map.removeOverlay(DB[i].marker); DB[i].marker = null; retVal++; }
			if (DB[i].listener!=null) { GEvent.removeListener(DB[i].listener); DB[i].listener = null; }
		}
	} else // Doorzoek de lijst op specifieke groepen.
		for (var i=0; i<len; i++)
			if ( DB[i].gr.indexOf(vGroep) >=0 ) { 
				if (DB[i].marker!=null) { map.removeOverlay(DB[i].marker); DB[i].marker = null; retVal++; }
				if (DB[i].listener!=null) { GEvent.removeListener(DB[i].listener); DB[i].listener = null; }
			}
	return retVal; // Geef terug het aantal object dat op de kaart is verwijderd.
} // kgui_removeGroup()

function kgui_flipMapOpties(vObjID) {	// v1.0
	if (vObjID.checked) kgui_showGroup(vObjID.value);
	else kgui_removeGroup(vObjID.value);
} // kgui_flipMapOpties()

function kgui_addSymbolToMap(vID,vMode) { // v1.1 vMode 'FOTO' | 'ADRES' added
	var rowID = kgui_findID(vID);

	if (rowID<0) alert("ERROR : kgui_findID("+vID+") niet gevonden!");
	else if (DB[rowID].marker==null) {
		var mark      = null;
		var markPoint = new GLatLng(DB[rowID].lat, DB[rowID].lng);
		var markOpt   = new Object;
		var markIcon  = new GIcon();

		markIcon.image				= DB[rowID].icon;
		markIcon.iconSize			= new GSize(34,47);
		markIcon.shadow				= DB[rowID].shad;
		markIcon.shadowSize			= new GSize(46,47);
		markIcon.iconAnchor			= new GPoint(22,47);
		markIcon.infoWindowAnchor	= new GPoint(9, 2);
		markIcon.infoShadowAnchor	= new GPoint(18, 25);

		markOpt.title = DB[rowID].t;
		markOpt.clickable = true ;
		markOpt.icon = markIcon ;
		mark = new GMarker( markPoint, markOpt );

		switch (vMode) {
			case "FOTO" :

				// Add PHOTO OVERLAY 
				// map.addOverlay ( new myPhoto ( DB[0].tmb, gebied ) );

				break;
				
			case "ADRES" :
			default :
				// This is buggy in MSIE 5.5
				DB[rowID].listener = GEvent.addListener ( mark, "click", function() {
					var tmp="";
					if(!DB[rowID].lnk=="") tmp = "Website: <a href=\"javaScript:;\" onClick=\"window.document.location='http:\/\/"+DB[rowID].lnk+"';\">"+kgui_stripDomainName(DB[rowID].lnk)+"</a>";
					if( DB[rowID].tmb=="") tmp = "<div id=\"pt\"><b>"+DB[rowID].t+"</b><br>"+DB[rowID].desc+"<br>"+tmp+"</div>";
					else tmp = "<div id=\"pt\"><table><tr><td valign=\"top\"><img src=\""+DB[rowID].tmb+"\" /></td><td valign=\"top\"><b>"+DB[rowID].t+"</b><br>"+DB[rowID].desc+"</td></tr></table>"+tmp+"</div>";
					mark.openInfoWindowHtml( tmp, {maxWidth:200} );
				}); // End New Function Declaratiuon
				break;
		} // EndSwitch vMode

		map.addOverlay(mark); 		// Add to the MAP
		DB[rowID].marker = mark;	// Keep track of all Markers
	}
}// kgui_addSymbolToMap()

function kgui_addPolyToMap(vObjID) { // v1.0
	var rowID = kgui_findPolyID(vObjID.value);
	if (rowID<0) alert("ERROR : kgui_findPolyID("+vID+") niet gevonden!");
	else if (DBpoly[rowID].Polyline==null) {	// Nog niet getekend
		var encodedPolyline = new GPolyline.fromEncoded({
			color: "#FF0000",
			weight: 8,
			points: DBpoly[rowID].points,
			levels: DBpoly[rowID].levels,
			zoomFactor: 32,
			numLevels: 4
		});
		map.addOverlay(encodedPolyline);
		DBpoly[rowID].Polyline = encodedPolyline;
	} else {
		map.removeOverlay(DBpoly[rowID].Polyline);
		DBpoly[rowID].Polyline = null;
	}
} // kgui_addPolyToMap()

function kgui_findID(vID) { // v 1.0
	var len=DB.length, retVal=-1; 
	for (var i=0; i<len; i++) if (DB[i].id==vID) {retVal=i; break;} return retVal;
} // kgui_findID()

function kgui_findPolyID(vID) { // v 1.0
	var len=DBpoly.length, retVal=-1; 
	for (var i=0; i<len; i++) if (DBpoly[i].id==vID) {retVal=i; break;} return retVal;
} // kgui_findPolyID()

function kgui_stripDomainName(vURL){ var i=vURL.indexOf("/"); if(i>0) return vURL.substr(0,i); else return vURL; }

function kgui_drawCircle (vCentre,vRadius) { // v 1.0
	var scale = 0.0000148;			// Omrekenen van meters naar Google coordinaten
	// var centerMap = map.getCenter();
	map.setCenter(focusPoint,15); 		// Reset en zoom zodat cirkel is te zien, uitgaande straal 500m.
	if (omtrekCirkel==null) {		// Declaratie 1-malig = circel mogelijk
		var points = new Array();
		for ( var a=0.0, x=0.0, y=0.0; a < Math.PI*2; a+=(Math.PI/15) ) {
			x = vCentre.x + vRadius * Math.sin(a) * scale;
    		y = vCentre.y + vRadius * Math.cos(a) * scale * 0.611; // 0.611 Correctie geschatte kromming aarde
			points.push (new GLatLng(y,x)); }
		points.push (points[0]) ;	// sluiten cirkel 
		omtrekCirkel = new GPolyline(points, "#FF3333", 3);
		map.addOverlay(omtrekCirkel); }
} // kgui_drawCircle()