function initialize()
{
	var gmapShow = typeof(gmap_show) != 'undefined' ? gmap_show : false;
	var gmapHotelMini = typeof(gmap_hotel_mini) != 'undefined' ? gmap_hotel_mini : false;
	var gmapShiowInfo = typeof(gmap_show_info) != 'undefined' ? gmap_show_info : false;
	var gmapZoom = typeof(gmap_zoom) != 'undefined' ? gmap_zoom : false;
	var gmapOnLoadShowFull = typeof(gmap_on_load_show_full) != 'undefined' ? gmap_on_load_show_full : false;

	if (gmapShow && GBrowserIsCompatible())
	{
		var options = {
			  'gmapShow': 		gmapShow
			, 'gmapHotelMini':	gmapHotelMini
			, 'gmapShiowInfo':	gmapShiowInfo
			, 'maxDiv':			'full_map_place'
			, 'sourceDiv':		'map_canvas'
			, 'centerLat':		gmap_lat
			, 'centerLng':		gmap_lng
			, 'gmapZoom':		gmapZoom

		};
		gmap = new My_GMap_Obj(options);
		gmap.createMarker(gmap_lat, gmap_lng, gmap_info);
		if (gmapOnLoadShowFull)
		{
			resize_map();
		}
	}
	else
	{
		if (document.getElementById("map_canvas"))
		{
			document.getElementById("map_canvas").style.display = 'none';
		}
	}
}

function resize_map()
{
	if (typeof(gmap) != 'undefined') 
	{
		gmap.sourceDiv.parentNode.style.display = 'none';
		gmap.resizeMap();
	}
}

var My_GMap_Obj = function(options)
{
	var thisClass = this;
	this.baseIcon = null;
	this.gmapShow = null;
	this.gmapHotelMini = null;
	this.markers = new Array();


	this.init = function (options)
	{
		this.gmapShow 		= options.gmapShow 		? options.gmapShow 								: false;
		this.gmapHotelMini 	= options.gmapHotelMini	? options.gmapHotelMini 						: false;
		this.gmapShiowInfo 	= options.gmapShiowInfo	? options.gmapShiowInfo 						: false;
		this.minDiv 		= options.minDiv 		? document.getElementById(options.minDiv) 		: false;
		this.maxDiv 		= options.maxDiv 		? document.getElementById(options.maxDiv) 		: false;
		this.sourceDiv 		= options.sourceDiv 	? document.getElementById(options.sourceDiv) 	: false;

		this.centerLat 		= options.centerLat 	? options.centerLat 							: false;
		this.centerLng 		= options.centerLng 	? options.centerLng 							: false;
		this.gmapZoom 		= options.gmapZoom 		? options.gmapZoom	 							: this.gmapHotelMini ? 12 : 13;

		this.gMap = new GMap2(this.sourceDiv);
		this.setControls();
		this.initBaseIcon();

		if (this.gmapHotelMini && this.maxDiv)
		{
			GEvent.addListener(this.gMap, "click", resize_map);
		}
	}

	this.resizeMap = function()
	{
		if (thisClass.gmapHotelMini)
		{
			thisClass.gmapZoom = 13;
			thisClass.gmapHotelMini = !thisClass.gmapHotelMini;
			//карта пропадает
			thisClass.sourceDiv.style.display = 'none';
			//карта перемещается в большой контейнер
			thisClass.maxDiv.appendChild(thisClass.sourceDiv);
			//убираются старые события
			GEvent.clearInstanceListeners(thisClass.gMap);
			//ресайзим карту
			thisClass.sourceDiv.style.width = thisClass.maxDiv.style.width;
			thisClass.sourceDiv.style.height = thisClass.maxDiv.style.height;
			//показываем карту
			thisClass.maxDiv.style.display = 'block';
			thisClass.sourceDiv.style.display = 'block';
			//навешиваются новые события
			thisClass.setControlsLarge(true);
		}
		else
		{

		}

		return;
	}

	this.createMarker = function(lat, lng, shortInfo)
	{
		var point = new GLatLng(lat, lng);
		var letteredIcon = new GIcon(this.baseIcon);

		var markerOptions = { icon:letteredIcon };
      	this.markers.push(new GMarker(point, markerOptions));

      	var markerLast = this.markers.length - 1;
		if (this.gmapShiowInfo)
		{
			this.addMarkerInfo(this.markers[markerLast], shortInfo)
		}
		this.gMap.addOverlay(this.markers[markerLast])
	}

	this.addMarkerInfo = function(marker, info)
	{
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(info);
		});
	}

	this.setControls = function()
	{
		if (this.gmapHotelMini)
		{
			this.setControlsSmall(false);
		}
		else
		{
			this.setControlsLarge(false);
		}
	}

	this.setControlsSmall = function(resize)
	{
    	if (resize)
    	{
	        this.gMap.removeControl(new GSmallMapControl());
	    	this.gMap.removeControl(new GMapTypeControl());
	    	this.gMap.removeControl(new GOverviewMapControl());
	    	this.gMap.checkResize();
	    	this.gMap.setCenter(new GLatLng(this.centerLat, this.centerLng), this.gmapZoom);
    	}
    	else
    	{
    		this.gMap.setCenter(new GLatLng(this.centerLat + 0.008, this.centerLng + 0.005), this.gmapZoom);
    	}

    	this.gMap.disableDragging();
	}

	this.setControlsLarge = function(resize)
	{
    	if (resize)
    	{
    		this.gMap.enableDragging();
    		this.gMap.checkResize();
    	}

		this.gMap.setCenter(new GLatLng(this.centerLat, this.centerLng), this.gmapZoom);
        this.gMap.addControl(new GLargeMapControl());
    	this.gMap.addControl(new GMapTypeControl());
    	this.gMap.addControl(new GOverviewMapControl());
	}

	this.initBaseIcon = function()
	{
        this.baseIcon = new GIcon();
        this.baseIcon.image = "http://maps.google.com/intl/ru_ALL/mapfiles/arrow.png";
        this.baseIcon.shadow = "http://maps.google.com/intl/ru_ALL/mapfiles/arrowshadow.png";
        this.baseIcon.iconSize = new GSize(39, 34);
        this.baseIcon.shadowSize = new GSize(39, 34);
        this.baseIcon.iconAnchor = new GPoint(9, 34);
        this.baseIcon.infoWindowAnchor = new GPoint(9, 2);
        this.baseIcon.infoShadowAnchor = new GPoint(18, 25);
	}

	this.init(options);
}
