var map = null;
var t;

//Laad map
function GetMap() {
	map = new VEMap('myMap');
	map.LoadMap();
	map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
	var points = [new VELatLong(53.379232615442604, 6.339111328124986), new VELatLong(50.49945210396774, 3.164062500000014)];
	map.SetMapView(points);
	map.AttachEvent("onmouseover", hideinfobox_map);
}

//Verberg infobox
function hideinfobox_map() {
	return true;
}

// Resize map
function resize() {
	var breede_inhoud = parseInt(document.getElementById("inhoud").style.width)-2;
	var hoogte_inhoud = parseInt(document.getElementById("inhoud").style.height)-2;
	var Vpos = parseInt(document.getElementById('handel').offsetLeft)+10;
	var breede = breede_inhoud - Vpos;
	var hoogte = hoogte_inhoud;
    map.Resize(breede, hoogte);
}

// Verwijder alle localties
function verwijder_locatie() {
	map.DeleteAllShapes();
}

// Laad alle locaties
function laad_locatie(i, lat, lon, image, desc) {
	var shape = new VEShape(VEShapeType.Pushpin,new VELatLong(lat, lon));
	shape.SetCustomIcon('<div align="center" id="pin_map" style="background:url('+image+') no-repeat;">'+i+'</div>');
	shape.SetTitle(''+i+'');          
	shape.SetDescription(desc);
	map.AddShape(shape);
	window ['id'+i] = shape.GetID();
	map.AttachEvent("onmouseover", ByMouseOver);
	map.AttachEvent("onmouseout", ByMouseOut);
	map.AttachEvent("onclick", ByMouseClick);
}

// Laad alle locaties
function laad_locatie2(i, lat, lon, image, desc) {
	var shape = new VEShape(VEShapeType.Pushpin,new VELatLong(lat, lon));
	shape.SetCustomIcon('<div align="center" id="pin_map" style="background:url('+image+') no-repeat;">'+i+'</div>');
	shape.SetTitle(''+i+'');          
	shape.SetDescription(desc);
	map.AddShape(shape);
	window ['id'+i] = shape.GetID();
}

function ByMouseOver(e) {
	if (e != '[object Object]') {
		shape = map.GetShapeByID(e);
	} else {
		shape = map.GetShapeByID(e.elementID);
		scroll_menu(shape);
	}

	if (shape != null) {
		var obj = document.getElementById("extra_info");
		var obj_map = document.getElementById("myMap");
		var afstand = map.LatLongToPixel(shape.GetIconAnchor());
		if (document.getElementById("myMap").style.display != 'none') {
			obj.style.display = 'block';
		}
		var offset_max = parseInt(obj_map.clientWidth)-(parseInt(obj.clientWidth));
		var offset = afstand.x+4;
		if (offset < offset_max) {
			obj.style.left = afstand.x+map.GetLeft()+4+'px';
			inhoud_box(shape, 'rechts');
		} else {
			obj.style.left = afstand.x+map.GetLeft()+4-parseInt(obj.clientWidth)-40+'px';
			inhoud_box(shape, 'links');
		}
		obj.style.top = afstand.y-(parseInt(obj.clientHeight)/2)+'px';
		if (shape.GetTitle() != '') {
			menu_over(shape.GetTitle());
			ZIndex(shape, 1);
		}
	}
}

function ByMouseOut(e) {
	if (e != '[object Object]') {
		shape = map.GetShapeByID(e);
	} else {
		shape = map.GetShapeByID(e.elementID);
		scroll_stop();
	}
	if (shape != null) {	
		if (shape.GetTitle() != '') {
			menu_out(shape.GetTitle());
			ZIndex(shape, -1);
		}
	}
	document.getElementById("extra_info").style.display = 'none';
}

function ByMouseClick(e) {
	shape = map.GetShapeByID(e.elementID);
	if (shape.GetTitle() != '') {
		detail(shape.GetTitle(), 'Bedrijfsinfo');
	}
}

function ZIndex(shape, delta) {
	var shapeElem = document.getElementById(shape.GetPrimitive(0).iid);
	if (shapeElem && shapeElem.style)
	shapeElem.style.zIndex = parseInt(shapeElem.style.zIndex) + delta;
}

function inhoud_box(shape, pos) {
	if (pos == 'rechts') {
		var inhoud = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="pijl_rechts"><img src="/site/images/pijl_box_r.gif" /></td><td><div id="info_box_rechts">'+shape.GetDescription()+'</div></td></tr></table>';
		document.getElementById("extra_info").innerHTML = inhoud;
	} else {
		var inhoud = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><div id="info_box_links">'+shape.GetDescription()+'</div></td><td class="pijl_links"><img src="/site/images/pijl_box_l.gif" /></td></tr></table>';
		document.getElementById("extra_info").innerHTML = inhoud;
	}
}
