var sMaps = {

	map:'',

    showLocation: function (layer,longitude,latitude,zoom,type)
    {
        //make map object
	    sMaps.map = new GMap2(layer);
	    var geocoder = new GClientGeocoder();

	    // add controllers
	    sMaps.map.addControl(new GSmallMapControl());
		sMaps.map.addControl(new GMapTypeControl());
		sMaps.map.addControl(new GOverviewMapControl());

		// set center point
	    sMaps.map.setCenter(new GLatLng(longitude,latitude),zoom,type);

		return sMaps.map;
    },

    showWeather: function (map,longitude,latitude,iconName,name,id,base)
    {
    	var point = new GLatLng(longitude,latitude);
    	var icon = sMaps.getWeatherIcon(iconName);
    	var marker = new GMarker(point,{icon:icon});
    	var div = document.createElement("div");

    	GEvent.addListener(marker, "click", function() {
   			document.location=base+id+'/weer.html';
   		});

   		GEvent.addListener(marker, "mouseover", function() {
   			sMaps.showPopUp(div,id,name,point);
   		});

   		GEvent.addListener(marker, "mouseout", function() {
   		 	div.parentNode.removeChild(div);
		});

		map.addOverlay(marker);
    },

    showCity: function (map,longitude,latitude,id,name,base,url)
    {
    	var point = new GLatLng(longitude,latitude);
    	var icon = sMaps.getIcon('steden');
    	var marker = new GMarker(point,{icon:icon});
		var div = document.createElement("div");

		if(!url) url = '';

   		GEvent.addListener(marker, "click", function() {
   			document.location=base+id+url+'.html';
   		});

   		GEvent.addListener(marker, "mouseover", function() {

   			sMaps.showPopUp(div,id,name,point);
   			marker.setImage('templates/img/icons/st_selected.png');

   		});

   		GEvent.addListener(marker, "mouseout", function() {
   		 	div.parentNode.removeChild(div);
   		 	marker.setImage('templates/img/icons/st_steden.png');
		});

		GEvent.addDomListener($('cName_'+id), "mouseover", function() {

			sMaps.showPopUp(div,id,name,point);
   		 	marker.setImage('templates/img/icons/st_selected.png');
		});

		GEvent.addDomListener($('cName_'+id), "mouseout", function() {

			div.parentNode.removeChild(div);
   		 	marker.setImage('templates/img/icons/st_steden.png');
		});

   		map.addOverlay(marker);
	},

	showPopUp: function (div,id,name,point)
	{
		div.style.position = "absolute";
		div.style.id = id;
		div.innerHTML = '<nobr>'+name+'</nobr>';

		var c1 = map.fromLatLngToDivPixel(point);

		div.style.top = (c1.y-11)+'px';
		div.style.left = (c1.x+20)+'px';

		map.getPane(G_MAP_MARKER_PANE).appendChild(div);

		Element.addClassName(div,'mapAltBox');
	},

    showPosition: function (map,iType,longitude,latitude,title,infoText,showInfo,id)
    {

    	var point = new GLatLng(longitude,latitude);
    	var icon = sMaps.getIcon(iType);
    	var marker = new GMarker(point,{icon:icon});
    	var tabs = sMaps.infoTabs('<strong>'+title+'</strong>'+infoText );
		var div = document.createElement("div");

    	if(infoText)
    	{
    		GEvent.addListener(marker, "click", function() {

    			marker.openInfoWindowTabsHtml(tabs,{maxWidth:250});
				var mapZoom = new GMap2($('mapZoom'));
				mapZoom.setCenter(point , 15,G_HYBRID_MAP);

    		});
    	}

    	if($(iType+'_label_'+id))
    	{
    		GEvent.addDomListener($(iType+'_label_'+id), "click", function() {

			marker.openInfoWindowTabsHtml(tabs,{maxWidth:250});
			var mapZoom = new GMap2($('mapZoom'));
			mapZoom.setCenter(point , 15,G_HYBRID_MAP);

			sMaps.map.setCenter(point,sMaps.map.getZoom());

    		});

    		GEvent.addDomListener($(iType+'_label_'+id), "mouseover", function() {
    			marker.setImage('templates/img/icons/st_selected.png');
				sMaps.showPopUp(div,id,title,point);
			});

			GEvent.addDomListener($(iType+'_label_'+id), "mouseout", function() {
				marker.setImage('templates/img/icons/st_'+iType+'.png');
				div.parentNode.removeChild(div);
			});
    	}

    	GEvent.addListener(marker, "mouseover", function() {
			marker.setImage('templates/img/icons/st_selected.png');
   			sMaps.showPopUp(div,'x0',title,point);
   		});

   		GEvent.addListener(marker, "mouseout", function() {
   			marker.setImage('templates/img/icons/st_'+iType+'.png');
   		 	div.parentNode.removeChild(div);
		});


		map.addOverlay(marker);

		if(showInfo)
		{
			marker.openInfoWindowTabsHtml(tabs,{maxWidth:250});
			var mapZoom = new GMap2($('mapZoom'));
			mapZoom.setCenter(point , 15,G_HYBRID_MAP);
		}


    },

    clear: function ()
    {
    	sMaps.map.clearOverlays();
    },

    infoTabs: function (text)
    {
    	var information = new GInfoWindowTab("Informatie", text);
		var location = new GInfoWindowTab("Locatie", '<div id="mapZoom" style="width:250px;height:100px;"></div>');
		var tabs = [information,location];

		return tabs;
    },

    getIcon: function (type)
    {
    	var icon = new GIcon();
		icon.image = "templates/img/icons/st_"+type+".png";
		icon.iconSize = new GSize(24, 24);
		icon.iconAnchor = new GPoint(12, 12);
		icon.infoWindowAnchor = new GPoint(12,12);

		return icon;
    },

    getWeatherIcon: function (type)
    {
    	var icon = new GIcon();
		icon.image = "templates/img/icons/weer/small/"+type+".png";
		icon.iconSize = new GSize(38, 38);
		icon.iconAnchor = new GPoint(19, 19);
		icon.infoWindowAnchor = new GPoint(19,19);

		return icon;
    }
}