	currentMarker = 0;
	function MapComponent(){
	 	this.GMap = null;
	 	this.inMarkers = [];
	 	return true;
	}
	 
	MapComponent.prototype.init = function(){
	    if (GBrowserIsCompatible()) {
			this.GMap = new GMap2($('#map').get(0));
			this.GMap.setCenter(new GLatLng(37.4419, -122.1419), 13);
			this.GMap.addControl(new GSmallMapControl());
			GEvent.addListener(this.GMap, "zoomend", function(){
				if (currentMarker)
   		    		this.removeOverlay(currentMarker.overlay);
		    });
			
			
			var len = aSearchData.length;
			for (var i=0;i<len;i++){
				var oMarker = new MarkerComponent();
				oMarker.longitude = parseFloat(aSearchData[i].lng);
				oMarker.latitude  = parseFloat(aSearchData[i].lat);
				oMarker.Map  = this.GMap;
				oMarker.searchItem = aSearchData[i];
				oMarker.rank = parseInt(aSearchData[i].rank);
				oMarker.parent = this;
				oMarker.init(oMarker.rank);
				this.addInMarker(oMarker);
			}
			
			this.showMarkers(); 
      	}
	}
	
	MapComponent.prototype.showMarkers = function(){
		var j = this.inMarkers.length - 1;
	    var oBounds = new GLatLngBounds();
	    while (j >= 0) {
	    	this.GMap.addOverlay(this.inMarkers[j].marker);
	    	oBounds.extend(new GLatLng(this.inMarkers[j].latitude, this.inMarkers[j].longitude));
	        j--;
	    }
	    
	    this.GMap.setZoom(this.GMap.getBoundsZoomLevel(oBounds));
	    this.GMap.setCenter(oBounds.getCenter());
	}
	
	MapComponent.prototype.addInMarker = function(marker){
		this.inMarkers.push(marker);
	}
	
	
	function MarkerComponent(){
	 	this.point = null;
	 	this.longitude = '';
		this.latitude = '';
		this.iconType = null;
		this.icon = null;
		this.component_id = null;
		this.Map = null
		this.htmlContent = null;
		this.parent = null;
		this.oInfoWindowOptions = {maxWidth:300};
		this.searchItem = null;
		this.rank = null;
	 }
	 
	 MarkerComponent.prototype.init = function(id){
		    this.point = new GLatLng(parseFloat(this.latitude), parseFloat(this.longitude));
		    //this.iconType = ;
		    this.marker = this.createMarker(false);
		    this.setNormalMarkerImportance();
		    this.component_id = id;
		    this.setBehaviours();
		 }
		
	MarkerComponent.prototype.createMarker = function(withZoom){
		 return new GMarker(this.point, markerOptions = { icon:this.getIcon(true), zIndexProcess:importanceOrder });
	}
		
	MarkerComponent.prototype.getIcon = function(hOver){
		
		if (!isHomePage)
		{
			var tinyIcon = new GIcon();
			tinyIcon.image = "http://1ekoophuis.nl/wp-content/themes/koophuis/images/icon-map-" + this.rank +".png";
			tinyIcon.shadow = "http://1ekoophuis.nl/wp-content/themes/koophuis/images/icon-map-shadow.png";
			tinyIcon.iconSize = new GSize(43, 53);
			tinyIcon.shadowSize = new GSize(63, 22);
			tinyIcon.iconAnchor = new GPoint(6, 30);
			tinyIcon.infoWindowAnchor = new GPoint(1, 30);
		}
		else
		{
			var tinyIcon = new GIcon();
			tinyIcon.image = "http://1ekoophuis.nl/wp-content/themes/koophuis/images/icon-map-eerstekoophuis.png";
			tinyIcon.shadow = "http://1ekoophuis.nl/wp-content/themes/koophuis/images/icon-map-shadow.png";
			tinyIcon.iconSize = new GSize(43, 53);
			tinyIcon.shadowSize = new GSize(63, 22);
			tinyIcon.iconAnchor = new GPoint(6, 30);
			tinyIcon.infoWindowAnchor = new GPoint(1, 30);
		}
		
		return tinyIcon;    
	}
		
	MarkerComponent.prototype.setBehaviours = function(){
		    this.marker.parent = this;
		    
		    GEvent.addListener(this.marker, "click", function(){
		    });
		    
		    GEvent.addListener(this.marker, 'mouseover', function(){
		    	this.parent.setHighMarkerImportance();
		    	this.parent.showInfoWindow();
		    	this.setLatLng(this.getLatLng());
		    });
		    GEvent.addListener(this.marker, 'mouseout', function(){
		    	this.parent.setNormalMarkerImportance();
		    	this.setLatLng(this.getLatLng());	
		    });
	}
	
	MarkerComponent.prototype.showInfoWindow = function(){
		//this.marker.openInfoWindowHtml(this.htmlContent);
		if (typeof CustomPopupOverlay !== 'undefined') {
		    if (currentMarker) {
		      this.Map.removeOverlay(currentMarker.overlay);
		    }
		    
		    if (!this.overlay) {
		      this.htmlContent = '<strong>' + this.searchItem.name + '</strong><div class="mapprice">&euro; ' + this.searchItem.min_price + ' / &euro; ' + this.searchItem.max_price + '</div><div><a href="' + this.searchItem.link + '" target="_blank">Bekijken</a></div>';	
		      this.overlay = new CustomPopupOverlay(this.marker, this.htmlContent, this.Map);
		    }
		    
		    currentMarker = this;
		    this.Map.addOverlay(this.overlay);
		    
		}
	}
	
	MarkerComponent.prototype.setNormalMarkerImportance = function(){
			this.marker.importance = GOverlay.getZIndex(this.marker.getPoint().lat()) + 1000000000;
	}
		
	MarkerComponent.prototype.setHighMarkerImportance = function(){
		this.marker.importance = GOverlay.getZIndex(this.marker.getPoint().lat()) + 10000000000;
	}
	
	CustomPopupOverlay = function(marker, html, map) {
	  this.marker = marker;
	  this.html = html;
	  this.map=map;
	}
	CustomPopupOverlay.prototype = new GOverlay();
	CustomPopupOverlay.prototype.initialize = function(map) {
	  var div = document.createElement("div");
	  div.className = 'gmap-info-container';
	  div.style.position = "absolute";
	  div.innerHTML = this.html;
	
	  // offsets based on popup div dimensions
	  var offsetX = 370;
	  var offsetY = 30;
	
	  div.style.top = (map.fromLatLngToDivPixel(this.marker.getLatLng()).y - offsetY) + 'px';
	  div.style.left = (map.fromLatLngToDivPixel(this.marker.getLatLng()).x + 35 ) + 'px';
	
	  //div.onclick = closeOverlay;
	
	  this._map = map;
	  this._div = div;
	
	  //map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	  map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);
	  //jQuery('.gmap-info-closebutton').bind('click', { map: map }, closeOverlay);
	}
	CustomPopupOverlay.prototype.remove = function(){
	  	this._div.parentNode.removeChild(this._div);
	}
	CustomPopupOverlay.prototype.redraw = function() {
	  //haven't had need for this yet
	}
	
	function importanceOrder (marker, b) {
    	return marker.importance;
    }
	 
	 $(document).ready(function(){
	 	oMap = new MapComponent();
	 	oMap.init();
	 });
