		
function RightMapProperties() {
	this.mapObjects = null;
	this.defaultIcon = null;
	this.imageIndex = 0;
	this.imageUrls = [
		'/kepek/map/20_red.png',
		'/kepek/map/20_green.png',
		'/kepek/map/20_blue.png',
		'/kepek/map/20_gray.png',
		'/kepek/map/20_purple.png',
		'/kepek/map/20_orange.png',
		'/kepek/map/20_yellow.png',
		'/kepek/map/20_white.png',
		'/kepek/map/20_black.png'
	];
	this.control = null;
	this.minimaZoom = 18;
}
		
		
RightMapProperties.prototype.addRecord = function( record, imageindex  ) {
	var icon;
	if ( imageindex instanceof GIcon ) {
		icon = imageindex;
	} else {
		if ( imageindex == undefined || typeof imageindex != "number" )
			imageindex = 8;
		icon = new GIcon( this.defaultIcon, this.imageUrls[ imageindex ] );
	}
   	if ( this.mapObjects != null ) 
   		this.mapObjects.addRecord( record, icon );
}  


RightMapProperties.prototype.showRecord = function( record, imageindex  ) {
   	if ( this.mapObjects != null ) {
   		this.addRecord( record, imageindex );
  		this.mapObjects.showRecord( record.key );
   	}
}  

		      
RightMapProperties.prototype.delRecord = function( key ) {
   	if ( this.mapObjects != null ) {
   		this.mapObjects.map.closeInfoWindow();
   		return this.mapObjects.delRecord( key );
   	}
   	else return false;
}

RightMapProperties.prototype.setIcon = function( obj ) {
	if( ! this.activeFleck ) 
		this.activeFleck = document.getElementById("fleck0");
	obj.className = "selectedFleck";
	this.activeFleck.className = "unselectedFleck";
	this.activeFleck = obj;
}
		
RightMapProperties.prototype.zoomIn = function() {
	if ( this.mapObjects != null )
		this.mapObjects.map.zoomIn();
}
		
RightMapProperties.prototype.zoomOut = function() {
	if ( this.mapObjects != null )
		this.mapObjects.map.zoomOut();
}
		
RightMapProperties.prototype.panDirection = function( dx, dy ) {
	if ( this.mapObjects != null )
			this.mapObjects.map.panDirection( dx, dy );
}
		
RightMapProperties.prototype.setNormalMap = function() {
	if ( this.mapObjects == null ) return false;
	this.mapObjects.map.setMapType(G_NORMAL_MAP);
	document.getElementById('normal').className = "selectedmode";
	document.getElementById('satellite').className = "unselectedmode";
	document.getElementById('hybrid').className = "unselectedmode";
}
		
RightMapProperties.prototype.setSatelliteMap = function() {
	if ( this.mapObjects == null ) return false;
	this.mapObjects.map.setMapType(G_SATELLITE_MAP);
	document.getElementById('normal').className = "unselectedmode";
	document.getElementById('satellite').className = "selectedmode";
	document.getElementById('hybrid').className = "unselectedmode";
}
		
RightMapProperties.prototype.setHybridMap = function() {
	if ( this.mapObjects == null ) return false;
	this.mapObjects.map.setMapType(G_HYBRID_MAP);
	document.getElementById('normal').className = "unselectedmode";
	document.getElementById('satellite').className = "unselectedmode";
	document.getElementById('hybrid').className = "selectedmode";                        
}
		
RightMapProperties.prototype.otherFunctions = function() {
	if ( this.control == null ) {
		this.mapObjects.map.addControl( this.control = new TFleckControl( this.imageIndex ) );
		temp = this;
		this.control.onFleckClick = function( index ) { temp.imageIndex = index; }
	} else {
		this.mapObjects.map.removeControl( this.control );
		this.control = null;
	}	
}

RightMapProperties.prototype.loadHandler = function( oldHandler ) {
	temp = this;
	return function() {
		if ( typeof oldHandler == "function" )
			oldHandler();
		temp.createMap();
		if ( typeof window.initMap == "function" )
			window.initMap();
	}
}

RightMapProperties.prototype.unloadHandler = function( oldHandler ) {
	temp = this;
	return function() { 
		if ( temp.mapObjects != null )
			GUnload();
		if ( typeof oldHandler == "function" )
			oldHandler();
	}
}


RightMapProperties.prototype.createMap = function() {
	var map = new GMap2(document.getElementById("rightGoogleMap"));

	this.defaultIcon = new GIcon();
	this.defaultIcon.image = this.imageUrls[0];
	this.defaultIcon.iconSize = new GSize(12, 20);
	this.defaultIcon.shadowSize = new GSize(22, 20);
	this.defaultIcon.iconAnchor = new GPoint(6, 20);
	this.defaultIcon.infoWindowAnchor = new GPoint(5, 1);

	var europeCenter = new GLatLng( (59.80063426102869 + 36.24427318493909) / 2.0, (28.212890625 - 9.755859375) / 2.0 );
	var europeBounds = new GLatLngBounds( new GLatLng( 36.24427318493909, 9.755859375 ),  new GLatLng( 59.80063426102869, 28.212890625 ) );
	map.setCenter( europeCenter, map.getBoundsZoomLevel(europeBounds), G_NORMAL_MAP );
	this.mapObjects = new TMapObjects( map );
}
		
		
RightMapProperties.prototype.zoomTo = function() {
	if ( this.mapObjects == null ) return;
	var center, zoom, bounds = this.mapObjects.getBounds(), map = this.mapObjects.map;
	if ( bounds != null ) {
		center = new GLatLng( ( bounds.getSouthWest().lat() + bounds.getNorthEast().lat() ) / 2, ( bounds.getSouthWest().lng() + bounds.getNorthEast().lng() ) / 2 );				
		zoom = map.getBoundsZoomLevel( bounds );
	} else {
		center = new GLatLng( (59.80063426102869 + 36.24427318493909) / 2.0, (28.212890625 - 9.755859375) / 2.0 );
		zoom = map.getBoundsZoomLevel( new GLatLngBounds( new GLatLng( 36.24427318493909, 9.755859375 ),  new GLatLng( 59.80063426102869, 28.212890625 ) ) );
	}
	if ( typeof this.minimalZoom == "number" && this.minimalZoom < zoom )
		zoom = this.minimalZoom;
	map.setCenter( center, zoom );
}

window.MAP = new RightMapProperties();
window.onload = window.MAP.loadHandler( window.onload );
window.onunload = window.MAP.unloadHandler( window.onunload );

