﻿MapChangerControl = function(){};
YMapChangerControl = function() {
    this.element = document.createElement("DIV");
    this.element.style.position = 'absolute';
    this.element.style.zIndex = '1000';
}

CreateControls = function(){

	MapChangerControl.prototype = new GControl();
	MapChangerControl.prototype.setButtonStyle_ = function(button){
		button.style.color = "#5d6d4a";
		button.style.backgroundColor = "#fefefe";
		button.style.font = "small tahoma";
		button.style.border = "1px solid #444444";
		button.style.borderTopWidth = "0px";
		button.style.padding = "2px";
		button.style.marginBottom = "3px";
		button.style.textAlign = "center";
		button.style.width = "130px";
		button.style.cursor = "pointer";
	}
	MapChangerControl.prototype.initialize = function(map){
		var container = document.createElement("div");
		
		var zoomInDiv = document.createElement("div");
		this.setButtonStyle_(zoomInDiv);
		container.appendChild(zoomInDiv);
		zoomInDiv.appendChild(document.createTextNode("В режим карты ↓"));
		GEvent.addDomListener(zoomInDiv, "click", function(){
			Maps.Helper.changeMap();
		});
		GEvent.addDomListener(zoomInDiv, "mouseover", function(){
			this.style.color = "#d87310";
		});
		GEvent.addDomListener(zoomInDiv, "mouseout", function(){
			this.style.color = "#5d6d4a";
		});
		
		map.getContainer().appendChild(container);
		return container;
	}
	MapChangerControl.prototype.getDefaultPosition = function(){
		return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(110, 0));
	}
	
	YMapChangerControl = function(){
		this.element = document.createElement("DIV");
		this.element.style.position = 'absolute';
		this.element.style.zIndex = '1000';
	}
	YMapChangerControl.prototype = {
		onAddToMap: function(map, position){
			this.map = map;
			this.position = position || new YMaps.ControlPosition(YMaps.ControlPosition.TOP_LEFT, new YMaps.Size(110, 0));
			this._init();
		},
		
		onRemoveFromMap: function(){
			if (this.element.parentNode) {
				this.map.getContainer().removeChild(this.element);
			}
			this.map = null;
		},
		
		_init: function(map){
			var zoomInDiv = document.createElement("div"), zoomOutDiv = document.createElement("div"), _this = this;
			
			this._setButtonStyle(zoomInDiv);
			this.element.appendChild(zoomInDiv);
			zoomInDiv.appendChild(document.createTextNode("В режим спутника ↓"));
			
			zoomInDiv.onclick = function(){
				Maps.Helper.changeMap();

			};
			
			zoomInDiv.onmouseover = function(){
				this.style.color = "#d87310";
			}
			
			zoomInDiv.onmouseout = function(){
				this.style.color = "#5d6d4a";
			}
			
			this.position.apply(this.element);
			this.map.getContainer().appendChild(this.element);
		},
		
		_setButtonStyle: function(button){
			style = {
				color: '#5d6d4a',
				backgroundColor: '#fefefe',
				font: 'small Tahoma',
				border: '1px solid #444444',
				borderTopWidth: '0px',
				padding: '2px',
				marginBottom: '3px',
				textAlign: 'center',
				width: '130px',
				cursor: 'pointer'
			};
			for (var k in style) {
				button.style[k] = style[k];
			}
		}
	}
	
	YMapPanoramio = function(){
		this.element = document.createElement("DIV");
		this.element.style.position = 'absolute';
		this.element.style.zIndex = '1000';
	}
	YMapPanoramio.prototype = {
		onAddToMap: function(map, position){
			this.map = map;
			this.position = position || new YMaps.ControlPosition(YMaps.ControlPosition.TOP_LEFT, new YMaps.Size(250, 0));
			this._init();
		},
		
		onRemoveFromMap: function(){
			if (this.element.parentNode) {
				this.map.getContainer().removeChild(this.element);
			}
			this.map = null;
		},
		
		_init: function(map){
			var zoomInDiv = document.createElement("div"), zoomOutDiv = document.createElement("div"), _this = this;
			
			this._setButtonStyle(zoomInDiv);
			this.element.appendChild(zoomInDiv);
			zoomInDiv.appendChild(document.createTextNode("Фотографии"));
			
			zoomInDiv.onclick = function(){
				if (PanoramioPhoto.isShown) {
					PanoramioPhoto.markers.hide();
					this.style.backgroundColor = '#fefefe';
					this.style.color = '#5d6d4a';
				}else {
					Maps.Helper.showPanoramioPhotos();
					this.style.backgroundColor = '#FFA000';
					this.style.color = '#ffffff';					
				}
				PanoramioPhoto.isShown = !PanoramioPhoto.isShown;
			};
			
			zoomInDiv.onmouseover = function(){
				if (!PanoramioPhoto.isShown)
					this.style.color = "#d87310";
			}
			
			zoomInDiv.onmouseout = function(){
				if (!PanoramioPhoto.isShown)
					this.style.color = "#5d6d4a";
			}
			
			this.position.apply(this.element);
			this.map.getContainer().appendChild(this.element);
		},
		
		_setButtonStyle: function(button){
			style = {
				color: '#5d6d4a',
				backgroundColor: '#fefefe',
				font: 'small Tahoma',
				border: '1px solid #444444',
				borderTopWidth: '0px',
				padding: '2px',
				marginBottom: '3px',
				textAlign: 'center',
				width: '130px',
				cursor: 'pointer'
			};
			for (var k in style) {
				button.style[k] = style[k];
			}
		}
	}	
	
}
