 
var EgyptMarker = Class.create();
EgyptMarker.prototype = {
	map: false,
	marker: false,
	text: false,
	ext: false,
	type: 0,
	geoLat: 0,
	geoLong: 0,
	eventListenerClick: false,
	eventListenerMouseout: false,
	
		
	initialize: function(geoLat, geoLong, map, mmanager, type, text, ext, showExt) 
	{
		this.text 		= text;
		this.type 		= type;
		this.geoLat 	= geoLat;
		this.geoLong 	= geoLong;	
		this.ext 		= ext;		
		this.map 		= map;
		
		this.marker 	= new GMarker(new GLatLng( geoLat, geoLong ), {icon: mmanager.getIcon(type)} );
		this.marker.egyptemarker = this;
		
		// events
		this.showTooltip();
	},
	
	

	
	showTooltip: function ()
	{	
		
		var city = this.text.replace(/ /, "");
		
		$('mapTT' + city).hide();
		
		if (this.type < 4)	$('mapTT' + city).className = 'mapTTDest';
		else $('mapTT' + city).className = 'mapTTInfo';
		
		var txt = this.text + ' ';
		var f = txt.charAt(0).toUpperCase();		
		$('mapTTtext' + city).innerHTML = f + txt.substr(1);
		
		$('mapTTicon' + city).setStyle( {backgroundImage: 'url(http://assets.egypte.nl/site/layout/map/iconT'+ this.type +'.png)'} );
		
		this.eventListenerClick 	= this.clickTooltip.bindAsEventListener(this);
		this.eventListenerMouseout 	= this.hideTooltip.bindAsEventListener(this);
		$('mapTT' + city).observe('click', 	this.eventListenerClick);
//		$('mapTT').observe('mouseout', 	this.eventListenerMouseout);

		var point	= map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(), map.getZoom());
		var offset	= map.getCurrentMapType().getProjection().fromLatLngToPixel(this.marker.getPoint(), map.getZoom());
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x, -offset.y + point.y )); 
		pos.apply($('mapTT' + city));
		
		Effect.Appear( $('mapTT' + city) , {duration: 2.5});
	},
	
	
	hideTooltip: function()
	{
		$('mapTT').stopObserving('click', this.eventListenerClick);
		$('mapTT').stopObserving('mouseout', this.eventListenerMouseout);		
		$('mapTT').hide();
	},
	
	
	clickTooltip: function() 
	{
		if (this.type == 1) {
			this.map.setCenter(new GLatLng( this.geoLat, this.geoLong), 5);
		} 
	
		if (this.type == 2) {				
			document.location = "" + this.text.replace(/ /, "_").toLowerCase() + "/";	
		} 
		
		if (this.type == 3) {			
			this.showExtend();			
		}
	}	
}


// EgyptMarkerManager
var EgyptMarkerManager = Class.create();
EgyptMarkerManager.prototype = {
	markers 		: [],
	markerManager 	: null,
	map 			: null,
	icons			: [],	
	
	initialize: function(map)
	{
		this.markerManager = new MarkerManager(map);
		
		GEvent.addListener(map, "movestart", function()  { $('mapExt').hide(); $('mapTT').hide(); } );  
		GEvent.addListener(map, "zoomend", function()  { $('mapExt').hide(); $('mapTT').hide(); } );    
	},
	
	
	add : function(marker) 
	{
		this.markers.push(marker);
		var r = marker.text.replace(/ /, "");
		// Tooltip
		if ($('mapTT' + r)) {
			$('mapTT' + r).hide();				
			$('map_canvas').appendChild($('mapTT' + r));
		}
	},
	
	
	getMarkersByType : function(type)
	{
		var result = [];
		var resulti = 0;
		this.markers.each(function(emarker) 
			{
				if (emarker.type == type) result[resulti++] = emarker.marker;
				
			}
		);
		return result;
	},
	
	
	addMarkersToMap : function()
	{
		// type 1
		this.markerManager.addMarkers(this.getMarkersByType(1), 1, 4); 
		
		// type 2
		this.markerManager.addMarkers(this.getMarkersByType(2), 4, 8); 
				
		// type 3
		this.markerManager.addMarkers(this.getMarkersByType(3), 9, 15); 
		
		// type 4
		this.markerManager.addMarkers(this.getMarkersByType(4), 9, 15); 
		
		
		this.markerManager.refresh();
	},
	
	
	getIcon : function(type)
	{
		var domain = window.location.href.split(".");
				
		if (!this.icons[type]) {
			var icon = new GIcon();
			icon.image = '';
			icon.iconAnchor = new GPoint(0, 28);
			icon.infoWindowAnchor = new GPoint(0, 28);
			icon.iconSize = new GSize(25, 28);
			
			this.icons[type] = icon;
		}
		return this.icons[type];
	}
}