/*------------------  ICONS DEFINITION -------------------*/
function myedemIcons() {
	this.startIcon = new google.maps.Icon();
	this.startIcon.image = "/img/map/startIcon.png";
	this.startIcon.shadow = "/img/map/flagIcon_shadow.png";
	this.startIcon.iconSize = new google.maps.Size(32, 40);
	this.startIcon.shadowSize = new google.maps.Size(46, 39);
	this.startIcon.iconAnchor = new google.maps.Point(6, 39);
	this.startIcon.infoWindowAnchor = new google.maps.Point(15, 3);
	
	this.finishIcon = new google.maps.Icon();
	this.finishIcon.image = "/img/map/finishIcon.png";
	this.finishIcon.shadow = "/img/map/flagIcon_shadow.png";
	this.finishIcon.iconSize = new google.maps.Size(32, 40);
	this.finishIcon.shadowSize = new google.maps.Size(46, 39);
	this.finishIcon.iconAnchor = new google.maps.Point(6, 39);
	this.finishIcon.infoWindowAnchor = new google.maps.Point(15, 3);
	
	this.waypointIcon = new google.maps.Icon();
	this.waypointIcon.image = "/img/map/waypointIcon.png";
	this.waypointIcon.shadow = "/img/map/flagIcon_shadow.png";
	this.waypointIcon.iconSize = new google.maps.Size(32, 40);
	this.waypointIcon.shadowSize = new google.maps.Size(46, 39);
	this.waypointIcon.iconAnchor = new google.maps.Point(6, 39);
	this.waypointIcon.infoWindowAnchor = new google.maps.Point(15, 3);
	
	this.segmentpointIcon = new google.maps.Icon();
	this.segmentpointIcon.image = "/img/map/segmentpointIcon.png";
	this.segmentpointIcon.iconSize = new google.maps.Size(10, 10);
	this.segmentpointIcon.iconAnchor = new google.maps.Point(5, 5);
	this.segmentpointIcon.infoWindowAnchor = new google.maps.Point(5, 5);
	
	this.meetpointIcon = new google.maps.Icon();
	this.meetpointIcon.image = "/img/map/meetpoint.png";
	this.meetpointIcon.iconSize = new google.maps.Size(24,30);
	this.meetpointIcon.iconAnchor = new google.maps.Point(4,26);	
}

/*------------------  MAP TYPE CONTROL -------------------*/
FancyMapTypeControl = function(options) {
	function FancyMapTypeControl(options) {
		if (options)
			this.options = options;
		else
			this.options = [];
		if (typeof this.options.normal == "undefined") this.options.normal = true;
		if (typeof this.options.hybrid == "undefined") this.options.hybrid = true;
		if (typeof this.options.physical == "undefined") this.options.physical = false;
		if (typeof this.options.earth == "undefined") this.options.earth = false;
	}
	// Создание унаследованного "класса"
	FancyMapTypeControl.prototype = new GControl();
	
	// Инициализация
	FancyMapTypeControl.prototype.initialize = function(map) {	
		this.container = document.createElement("div");
		this.buttonMap = new Button({
			id:			'btnMap',
			handler:	function(){
				map.setMapType(G_NORMAL_MAP); 
			},
			disabled:	false,
			title:		'карта',
			icon:		'/img/icons/map.png'});		
		this.buttonHybrid = new Button({
			id:			'btnHybrid',
			handler:	function(){
				map.setMapType(G_HYBRID_MAP); 
			},
			disabled:	false,
			title:		'спутник',
			icon:		'/img/icons/world.png'});	
		this.buttonPhysical = new Button({
			id:			'btnPhysical',
			handler:	function(){
				map.setMapType(G_PHYSICAL_MAP); 
			},
			disabled:	false,
			title:		'ландшафт',
			icon:		'/img/icons/map_add.png'});			
		this.buttonEarth = new Button({
			id:			'btnEarth',
			handler:	function(){
				map.setMapType(G_SATELLITE_3D_MAP); 
			},
			disabled:	false,
			title:		'планета',
			icon:		'/img/icons/world_add.png'});	
		if (this.options.normal)
			this.container.appendChild(this.buttonMap);
		if (this.options.hybrid)
			this.container.appendChild(this.buttonHybrid);	
		if (this.options.physical)	
			this.container.appendChild(this.buttonPhysical);			
		if (this.options.earth)	
			this.container.appendChild(this.buttonEarth);
		
		map.getContainer().appendChild(this.container);
		return this.container;
	}
	
	// Позиция слоя по умолчанию
	FancyMapTypeControl.prototype.getDefaultPosition = function() {
		return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 7));
	}
	
	return new FancyMapTypeControl(options);
}

/*------------------  MAP BUTTONS -------------------*/
function Button(params) {
	t = document.createElement('div');
	t.disabled		= false;
	
	t.onclick		= function() {if (!this.disabled) this.handler()};
	t.setIcon		= function(img_path) {this.style.backgroundImage = 'url('+img_path+')'}
	t.setDisabled	= function(){this.disabled = true}
	t.setEnabled	= function(){this.disabled = false}
	
	
	t.style.border				= "1px outset #ccc";
	t.style.padding				= "2px";
	t.style.marginBottom		= "3px";
	t.style.textAlign			= "center";
	t.style.width				= "16px";
	t.style.height				= "16px";
//	t.style.cursor				= "pointer";
	t.style.display				= 'inline-block';
	t.style.backgroundColor		= 'white';
	t.style.backgroundPosition	= 'center center';
	t.style.backgroundRepeat	= 'no-repeat';
	
	if (params) {
		if (params.id) t.id = params.id;
		if (params.handler) t.handler = params.handler;
		if (params.disabled) t.disabled = params.disabled;
		if (params.icon) t.setIcon(params.icon);
		if (params.title) t.title = params.title;
	}
	
	return t;
}
