function laadWinkel(id)
{
	var loc = window.location.toString();
	var arr = loc.split("?");
	var root = arr[0].split("/");
	root.pop();
	arr[0] = root.join("/");
	window.location = arr[0] + "/winkels?plaats=" + id;
}

$(document).ready(function() {
	if (GBrowserIsCompatible())
	{
		$("#vestiging_inhoud").find("a:first").click();
	};
});

function displWinkel(id)
{
	var plaats = $("#winkel_" + id + " .plaats").html();
	var adres = $("#winkel_" + id + " .straat").html();
	var pc = $("#winkel_" + id + " .pc").html();
	var pos;
	getPosition(id,adres,pc,plaats);
}

var map = null;
var marker;
function showMap() {
	if (GBrowserIsCompatible())
	{
		//nieuwe map
		map = new GMap2(document.getElementById('map'));
		
		map.setMapType(G_NORMAL_MAP );
		map.setCenter(new GLatLng(52.199,5.393), 7);
	}
}

function createMarker(lat,long,html)
{
	var point = new GLatLng(lat, long, html);
	marker = new GMarker(point);
	GEvent.addListener(marker, 'click', function()
	{
		marker.openInfoWindowHtml(html);
	});
	
	map.addOverlay(marker);
	map.setCenter(new GLatLng(lat,long), 16);
}

function getPosition(id,adres,pc,plaats)
{
	var pos;
	queryLatLng( adres, pc, plaats, function(position)
	{
		pos = position;
		
		$(".winkel_foto img").css("display","block");
		$(".winkel_foto img").attr("src", $("#winkel_" + id + " .img").html());
		$("#w_openingstijdentitel").css("display","block");
		$("#naw #w_naam").html( $("#winkel_" + id + " .naam").html() );
		var html =    $("#winkel_" + id + " .straat").html() + "<br/>"
					+ $("#winkel_" + id + " .pc").html() + " " + $("#winkel_" + id + " .plaats").html() + "<br/>"
					+ "Tel.: " + $("#winkel_" + id + " .tel").html() + "<br/>"
					+ $("#winkel_" + id + " .winkelcentrum").html();
		
		createMarker(pos.posLat,pos.posLng,adres + "<br>" + pc + "<br>" + plaats);
		$("#naw #w_adres").html( html );
		$("#naw #w_tijd").html( $("#winkel_" + id + " .tijd").html() );
	});
	return false;
}

$(document).ready(function(){
	showMap();
});
