var map, centerLatitude = 51.3691369, centerLongitude = 6.1709755, startZoom = 16, icon = new GIcon();
var prefix = location.protocol + '//'  +location.host + '/templates/opdeparade.nl/images/';
icon.image = prefix + 'category-bg-blue.gif';
icon.iconSize = new GSize(11, 11);
icon.iconAnchor = new GPoint(11, 11);


//create the ToolTip overlay object
function ToolTip(marker,html,width) {
	this.html_ = html;
	this.width_ = (width ? width + 'px' : 'auto');
	this.marker_ = marker;
}

ToolTip.prototype = new GOverlay();
ToolTip.prototype.initialize = function(map) {
	var div = document.createElement("div");
	div.style.display = 'none';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	this.map_ = map;
	this.container_ = div;
}

ToolTip.prototype.remove = function() {
	this.container_.parentNode.removeChild(this.container_);
}

ToolTip.prototype.copy = function() {
	return new ToolTip(this.html_);
}
ToolTip.prototype.redraw = function(force) {
	if (!force) return;
	var pixelLocation = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
	this.container_.innerHTML = this.html_;
	
	this.container_.style.cssText = 'position: absolute; font: bold 10px/10px verdana, arial, sans; border: 1px solid black; background: yellow; padding: 4px; white-space: nowrap;';
	this.container_.style.left = pixelLocation.x + "px";
	this.container_.style.top = pixelLocation.y + "px";
	this.container_.style.width = this.width_;
	if(this.width_ != 'auto') this.container_.style.overflow = 'hidden';
	this.container_.style.display = 'block';
}

GMarker.prototype.ToolTipInstance = null;

GMarker.prototype.openToolTip = function(content) {
	//don't show the tool tip if there is a custom info window
	if(this.ToolTipInstance == null) {
		this.ToolTipInstance = new ToolTip(this,content)
		map.addOverlay(this.ToolTipInstance);
	}
}
GMarker.prototype.closeToolTip = function() {
	if(this.ToolTipInstance != null) {
		map.removeOverlay(this.ToolTipInstance);
		this.ToolTipInstance = null;
	}
}


function showMarker(url, name, latitude, longitude, alias) {

var marker = new GMarker(new GLatLng(latitude, longitude), icon);
	if(marker) {
		
		switch(alias) {
			
			case 'winkels':
				icon.image = prefix + 'category-bg-yellow.gif';
				break;
				
			case 'dienstverlening':
				icon.image = prefix + 'category-bg-red.gif';
				break;
				
			case 'reisbureaus':
				icon.image = prefix + 'category-bg-purple.gif';
				break;
				
			case 'uitzendbureaus':
				icon.image = prefix + 'category-bg-pink.gif';
				break;				

			case 'eetgelegenheden':
				icon.image = prefix + 'category-bg-blue.gif';
				break;
				
			case 'cafes':
				icon.image = prefix + 'category-bg-green.gif';
				break;				

			default:
				icon.image = prefix + 'category-bg-red.gif';
				break;
		}
		map.addOverlay(marker);

		GEvent.addListener(marker, 'click', function() {
			//alert(url);
			location.href = url;
	
		});
		GEvent.addListener(marker,'mouseover',function() {
			marker.openToolTip(name);
		});
		GEvent.addListener(marker,'mouseout',function() {
			marker.closeToolTip();
		});		
		
		
	}
}


function extLink() {
	var i, a = document.getElementsByTagName('a');
	for(i=0;i<a.length;i++) {
		if(a[i].className == 'ext') {
			a[i].target = '_blank';
		}
	}
}
window.onload = function() {
	if(document.getElementById('map') && GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById('map'));
		map.addControl(new GSmallMapControl());
		var i;
		for(i in markers) {
			showMarker(markers[i].url, markers[i].name, markers[i].latitude, markers[i].longitude, markers[i].alias);
		}
		map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);				
	}
	extLink();
}
