var Ymap,
	GMap,
	DGMap,
	BingMap,
	typemap = '',
	s_map_provider='',
	s_map_type='',
	mapname = 'map',
	markers = [],
	new_markers = [],
	ymap_collection = [],
	gmap_collection = [],
	dgmap_collection = [],
	bingmap_collection = [],
	//map_center = [31.76, 35.64], // определена в вызывающем скрипте
	map_zoom = 13,
	only_active = false,
	infowindow,
	f = [],
	first_load = true,
	centerAndZoom;
var mytl;
var bounds;// = new YMaps.GeoCollectionBounds(); //paveleg


var categories = [
	{id: 1, alias: "Ans", name: "Архитектурный ансамбль"},
	{id: 2, alias: "Belltower", name: "Колокольня"},
	{id: 3, alias: "Cathedral", name: "Собор"},
	{id: 4, alias: "Chapel", name: "Часовня"},
	{id: 5, alias: "Church", name: "Церковь"},
	{id: 6, alias: "Citadel", name: "Кремль"},
	{id: 7, alias: "emp", name: "тип не установлен"},
	{id: 8, alias: "Monastery", name: "Монастырь"},
	{id: 9, alias: "MWA", name: "Музей деревянной архитектуры"},
	{id: 10, alias: "Other", name: "Прочие объекты"},
	{id: 11, alias: "Skit", name: "Скит"},
	{id: 12, alias: "TwoChurches", name: "Архитектурный комплекс"}];

if (points_src == 'mlist')
	map_zoom = 4;
if (points_src == 'wood')
	map_zoom = 4;
if (points_src == 'old')
	map_zoom = 4;

ymaps.ready(function(){
	$('#categories .button a').bind('click', function(event){
		if ($(this).hasClass("active")) {
			$(this).removeClass("active");
			$('#categories .cat-list').hide();
		} else {
			$(this).addClass("active");
			$('#categories .cat-list').show();
		}
	});

	$('html').bind('click', function(event){
		if($(event.target).parents().index($('#categories')) == -1){
			if ($('#categories .button a').hasClass("active")) {
				$('#categories .button a').removeClass("active");
				$('#categories .cat-list').hide();
			}
		}

		if($(event.target).parents().index($('#maps')) == -1){
			if ($('#maps .button a').hasClass("active")) {
				$('#maps .button a').removeClass("active");
				$('#maps .map-list').hide();
			}
		}

		if($(event.target).parents().index($('#maptype')) == -1){
			if ($('#maptype .button a').hasClass("active")) {
				$('#maptype .button a').removeClass("active");
				$('#maptype .maptype-list').hide();
			}
		}
	});

	$('#maps .button a').bind('click', function(event){
		if ($(this).hasClass("active")) {
			$(this).removeClass("active");
			$('#maps .map-list').hide();
		} else {
			$(this).addClass("active");
			$('#maps .map-list').show();
		}
	});

	$('#maps li a').bind('click', function(){
		if ($('#maps .button a').hasClass("active")) {
			$('#maps .button a').removeClass("active");
			$('#maps .map-list').hide();
		} else {
			$(this).addClass("active");
			$('#maps .map-list').show();
		}
		$('#maps .button a span').html($(this).html());
		if ($(this).hasClass('active'))
			return false;

		$('#maps li a').removeClass('active');
		$(this).addClass('active');

	});

	$('#maptype .button a').bind('click', function(event){
		if ($(this).hasClass("active")) {
			$(this).removeClass("active");
			$('#maptype .maptype-list').hide();
		} else {
			$(this).addClass("active");
			$('#maptype .maptype-list').show();
		}
	});

	$('#maptype li a').bind('click', function(){
		if ($('#maptype .button a').hasClass("active")) {
			$('#maptype .button a').removeClass("active");
			$('#maptype .maptype-list').hide();
		}
		$('#maptype .button a span').html($(this).html());
		if ($(this).hasClass('active'))
			return false;

		$('#maptype li a').removeClass('active');
		$(this).addClass('active');
	});

	$('#fullscr a').toggle(function() {
		$("#map-wrapper").css({ width: "100%", height: "100%", position: "fixed", top: "0px", left: "0px", "z-index": 100});
		$("#MyMap").css({ width: "100%", height: "100%"}).removeClass('map-article');
		$(this).find('span').text("Свернуть");
		RedrawMap();
	},
	function() {
		$("#map-wrapper").css({ top: "", left: "", position: "relative", width: "100%", height: "94%"}); 
		$("#MyMap").css({ width: "100%", height: "100%"}).addClass('map-article');
		$(this).find('span').text("Развернуть");
		RedrawMap();
	});
	
s_map_provider = readCookie('s_map_provider');
	s_map_type = readCookie('s_map_type');
	$('#maps .button a').click();
	switch(s_map_provider){
		case 'ymap':
			ymaps.ready(function(){ YMapInit() });
			break;
		case 'gmap':
			$('#maps li a')[1].click();
			break;
		case 'osmap':
			$('#maps li a')[2].click();
			break;
		case 'wikimap':
			$('#maps li a')[3].click();
			break;
		case 'dgmap':
			$('#maps li a')[4].click();
			break;
		case 'bingmap':
			$('#maps li a')[5].click();
			break;
	}
	
	$('#maptype .button a').click();
	switch(s_map_type){
		case 'map':
			$('#maptype li a')[0].click();
			break;
		case 'sat':
			$('#maptype li a')[1].click();
			break;
		case 'hyb':
			$('#maptype li a')[2].click();
			break;
	}


	for (i=0; i < categories.length; i++){
		AddMenuItem(categories[i]);
	}

	$('#categories input').bind('change', function(){
		switch(typemap){
			case 'ymap':
				YMapLoadMapEvent();
				break;
			case 'gmap': case 'osmap': case 'wikimap':
				GMapLoadMapEvent();

				break;
			case 'dgmap':
				clearDGMap();
				DGMapLoadMapEvent();
				break;
			case 'bingmap':
				clearBingMap();
				BingMapLoadMapEvent();
				break;
		}
	});
});


function AddMenuItem(category) {
	$('<input checked type="checkbox" id="cat'+category.id+'" value="'+category.id+'"> <label for="cat'+category.id+'">' + category.name + '</label>')
	.appendTo($("<li></li>").appendTo($('#categories ul')));
}

function setMapType(type) {
	switch(typemap){
		case 'ymap':
			setYMapType(type);
			break;
		case 'gmap':
			setGMapType(type);
			break;
		case 'bingmap':
			setBingMapType(type);
			break;
	}
}

function getCategories(marker) {
	var cat_id = 0;

	for (j=0; j<categories.length; j++){
		if(marker.category_id == categories[j].alias){
			cat_id = categories[j].id;
			break;
		}
	}
	return cat_id ? cat_id : 7;
}


function YMapInit (){
	DGMapDestroy();
	GMapDestroy();
	BingMapDestroy()

	markers = [];

	if (typemap == 'ymap') {
		Ymap.setType('yandex#satellite');
		return;
	}

	typemap = 'ymap';
	createCookie('s_map_provider', typemap, 100);

	$('#maptype').show();
	$('.maptype-list li:first a').click();

	Ymap = new ymaps.Map('MyMap', {
		center: map_center,
		zoom: map_zoom,
		behaviors: ['default'],
		type: 'yandex#map'
	}, {
		minZoom: 4
	});
	Ymap.controls.add('scaleLine');
	Ymap.behaviors.disable("scrollZoom");

	$('.ZoomPlus').bind('click', function(){
		Ymap.setZoom(Ymap.getZoom() + 1, {checkZoomRange: true});
	});

	$('.ZoomMinus').bind('click', function(){
		Ymap.setZoom(Ymap.getZoom() - 1, {checkZoomRange: true});
	});

	Ymap.events.add('boundschange', function (event) {
		map_center = Ymap.getCenter();
		map_zoom = Ymap.getZoom();
	});

	for (i=0; i < categories.length; i++){
		ymap_collection[categories[i].id] = new ymaps.GeoObjectCollection();
		Ymap.geoObjects.add(ymap_collection[categories[i].id]);
	}

	YMapLoadMapEvent();

// ###
}


function YMapLoadMapEvent(){
	loadMarkers();
}


function setYMapType(type){
	if (typemap != 'ymap')
		return;

	if (type == 'sat')
		Ymap.setType('yandex#satellite');
	if (type == 'map')
		Ymap.setType('yandex#map');
	if (type == 'hyb')
		Ymap.setType('yandex#hybrid');
}


function YmapMarkers(){
    var category_id, coords = [];
	for (i=0; i < markers.length; i++) {
		category_id = getCategories(markers[i]);
		marker = YMapCreatePlacemark(markers[i]);
		ymap_collection[category_id].add(marker);
	}
}


function YMapCreatePlacemark(marker) {
    var ml=Number(marker.lat).toFixed(6);
    var l=lat.toFixed(6);
    var mll=Number(marker.lng).toFixed(6);
    var ll=long.toFixed(6);

    if ((ml==l) && (mll==ll))
    {
      // если это тот самый маркер, которому мы запрашиваем ближайших, то поменяем ему значок
      balloonContentBody1='';
      iconImageHref1="../_i/main_marker.png";
      iconImageOffset1=-12;
      iconImageOffset2=-39,
      iconImageSize1=24;
      iconImageSize2=39;
    }
    else
    {
      // иначе - обычный маркер
      balloonContentBody1='<a href="'+ marker.url +'">' + marker.title + '</a>' + (marker.address ? '<br> Адрес: ' + marker.address : '');
      iconImageHref1="../_i/"+marker.active+marker.category_id+".png";
      iconImageOffset1=-9;
      iconImageOffset2=-23,
      iconImageSize1=18;
      iconImageSize2=23;
    }
	placemark = new ymaps.Placemark([marker.lat, marker.lng], {
	    	hintContent: marker.title,
		    balloonContentBody: balloonContentBody1,
    		hasHint: true,
	    	MaxWidth: 200
    	}, {
    		iconImageHref: iconImageHref1,
	    	iconImageOffset: [iconImageOffset1, iconImageOffset2],
		    iconImageSize: [iconImageSize1, iconImageSize2],
    	});
	placemark.id = marker.id;
	return placemark;
}


function clearYMap() {
	for (i=0; i < categories.length; i++){
		ymap_collection[categories[i].id].removeAll();
	}
}


function YMapDestroy(){
	if (!Ymap)
		return;
	$('.ZoomPlus, .ZoomMinus').unbind('click');
	Ymap.destroy();
	Ymap = null;
	ymap_collection = [];
}


function DGMapInit() {
	YMapDestroy();
	BingMapDestroy()
	GMapDestroy();
	DG.then(function() {
		typemap = 'dgmap';
		createCookie('s_map_provider', typemap, 100);

		$('#maptype').hide();

		DGMap = DG.map('MyMap', {
			"center": map_center,
           		"zoom": map_zoom,
			fullscreenControl: false,
                    	zoomControl: false
		});
				

		DG.control.scale().addTo(DGMap);

		$('.ZoomPlus').bind('click', function(){
			DGMap.setZoom(DGMap.getZoom() + 1);
		});

		$('.ZoomMinus').bind('click', function(){
			DGMap.setZoom(DGMap.getZoom() - 1);
		});

		DGMap.on('dragend', function(){
			map_center = [DGMap.getCenter().lat, DGMap.getCenter().lon];
			map_zoom = DGMap.getZoom();
		});

		for (i=0; i < categories.length; i++){
			dgmap_collection[categories[i].id] = DG.layerGroup();
		}

		DGMapLoadMapEvent();
		
	});
}


function DGMapLoadMapEvent(){
	loadMarkers();
}

function clearDGMap() {
	for (i=0; i < categories.length; i++){
		dgmap_collection[categories[i].id].clearLayers();
	}
}

function DGMapDestroy() {
	if (!DGMap)
		return;
	$('.ZoomPlus, .ZoomMinus').unbind('click');
	DGMap.remove();
	DGMap = null;
	dgmap_collection = [];
}


function DGMapsMarkers(){

	for (i=0; i < markers.length; i++) {

		var category_id = getCategories(markers[i]);

		var filteredObj = false;

		dgmap_collection[category_id].eachLayer(function(layer) {
			if (layer.id == markers[i].id){
				filteredObj = true;
			}
		});

		if (!filteredObj) {
			marker = DGMapCreatePlacemark(markers[i]);
			dgmap_collection[category_id].addLayer(marker).addTo(DGMap);
		}

	}
}


function DGMapCreatePlacemark(marker) {
    var ml=Number(marker.lat).toFixed(6);
    var l=lat.toFixed(6);
    var mll=Number(marker.lng).toFixed(6);
    var ll=long.toFixed(6);
    var icon1;
    var contentHtml1;

    if ((ml==l) && (mll==ll))
    {
      // если это тот самый маркер, которому мы запрашиваем ближайших, то поменяем ему значок
      contentHtml1='';

	var myIcon = DG.icon({
		iconUrl: "../_i/main_marker.png",
		iconSize: [24, 39]
	});

    }
    else
    {
      contentHtml1='<a href="'+ marker.url +'">' + marker.title + '</a><br> Адрес: ' + marker.address;
	var myIcon = DG.icon({
		iconUrl: "../_i/"+marker.active+marker.category_id+".png",
		iconSize: [18, 23]	});

    }

	placemark = DG.marker([marker.lat, marker.lng], {
		icon: myIcon
	});
	placemark.bindPopup(contentHtml1);
	placemark.id = marker.id;
	return placemark;
}


function BingMapInit() {
	YMapDestroy();
	DGMapDestroy();
	GMapDestroy();

	typemap = 'bingmap';
	createCookie('s_map_provider', typemap, 100);

	$('#maptype').show();
	$('.maptype-list li:first a').click();

	BingMap = new Microsoft.Maps.Map(document.getElementById("MyMap"), {
		credentials: "AhMxI-TDc_nibt__iO2CetXghM6jYexPJNhiQevP-GV2qioSn2eMbh_WZIvB4dpg",
		center: new Microsoft.Maps.Location(map_center[0], map_center[1]),
		zoom: map_zoom,
		enableSearchLogo: false,
		enableClickableLogo: false,
		showDashboard: false,
		showMapTypeSelector: false,
		showScalebar: true,
		mapTypeId: Microsoft.Maps.MapTypeId.road,
		labelOverlay: Microsoft.Maps.LabelOverlay.hidden
	});

	$('.ZoomPlus').bind('click', function(){
		BingMap.setView({zoom: BingMap.getZoom() + 1});
	});

	$('.ZoomMinus').bind('click', function(){
		BingMap.setView({zoom: BingMap.getZoom() - 1});
	});

	Microsoft.Maps.Events.addHandler(BingMap, 'viewchangeend', function(e){
		map_center = [BingMap.getCenter().latitude, BingMap.getCenter().longitude];
		map_zoom = BingMap.getZoom();
	});

	for (i=0; i < categories.length; i++){
		bingmap_collection[categories[i].id] = new Microsoft.Maps.EntityCollection();
		BingMap.entities.push(bingmap_collection[categories[i].id]);
	}

	BingMapLoadMapEvent();
}


function BingMapLoadMapEvent(){
	loadMarkers();
}


function setBingMapType(type){
	if (typemap != 'bingmap')
		return;

	createCookie('s_map_type', type, 100);
	if (type == 'sat'){
		BingMap.setMapType(Microsoft.Maps.MapTypeId.aerial);
		BingMap.setOptions({labelOverlay: Microsoft.Maps.LabelOverlay.hidden});
	}
	if (type == 'map'){
		BingMap.setMapType(Microsoft.Maps.MapTypeId.road);
	}
	if (type == 'hyb') {
		BingMap.setMapType(Microsoft.Maps.MapTypeId.aerial);
		BingMap.setOptions({labelOverlay: Microsoft.Maps.LabelOverlay.visible})
	}
}

function BingMapsMarkers(){
	for (i = 0; i < markers.length; i++) {

		var filteredObj = false;
		var category_id = getCategories(markers[i]);

		for(c = 0; c < bingmap_collection[category_id].getLength(); c++) {
			if (bingmap_collection[category_id].get(c).id === markers[i].id){
				filteredObj = true;
				break;
			}
		}

		if (!filteredObj) {
			marker = BingMapCreatePlacemark(markers[i]);
			bingmap_collection[category_id].push(marker);
		}
	}
}


function BingMapCreatePlacemark(marker) {
    var ml=Number(marker.lat).toFixed(6);
    var l=lat.toFixed(6);
    var mll=Number(marker.lng).toFixed(6);
    var ll=long.toFixed(6);

    if ((ml==l) && (mll==ll))
    {
      // если это тот самый маркер, которому мы запрашиваем ближайших, то поменяем ему значок
	  	icon1="../_i/main_marker.png";
    }
    else
    {
		icon1="../_i/"+marker.active+marker.category_id+".png";
	}

	var options = {
		icon: icon1,
		typeName: "bingmarker"
	};
	placemark = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(marker.lat, marker.lng), options);
	placemark.id = marker.id;
	return placemark;
}

function BingMapDestroy() {
	if (!BingMap)
		return;
	$('.ZoomPlus, .ZoomMinus').unbind('click');
	BingMap.dispose();
	BingMap = null;
	bingmap_collection = [];
}


function GMapInit() {
	DGMapDestroy();
	YMapDestroy();
	BingMapDestroy();
	
	$('#maptype').show();
	$('.maptype-list li:first a').click();

	if (typemap == 'gmap' || typemap == 'osmap' || typemap == 'wikimap') {
		GMap.overlayMapTypes.setAt("0", null);
		GMap.setMapTypeId(google.maps.MapTypeId.SATELLITE);
		typemap = 'gmap';
		createCookie('s_map_provider', typemap, 100);
		return;
	}
	markers = [];
	typemap = 'gmap';
	createCookie('s_map_provider', typemap, 100);

	var GmapOptions = {
		disableDefaultUI: true,
		scaleControl: true,
		minZoom: 1,
		maxZoom: 17
	}

	GMap = new google.maps.Map(document.getElementById('MyMap'), GmapOptions);
			GMap.setMapTypeId(google.maps.MapTypeId.ROADMAP);
	GMap.setCenter(new google.maps.LatLng(map_center[0], map_center[1]));
	GMap.setZoom(map_zoom);

	infowindow = new google.maps.InfoWindow({
		content: '',
		maxWidth: 300
	});

	$('.ZoomPlus').bind('click', function(){
		GMap.setZoom(GMap.getZoom() + 1)
	});

	$('.ZoomMinus').bind('click', function(){
		GMap.setZoom(GMap.getZoom() - 1)
	});

	google.maps.event.addListener(GMap, "idle", function () {
		map_center = [GMap.getCenter().lat(), GMap.getCenter().lng()];
		map_zoom = GMap.getZoom();
    });
	
	setTimeout(function(){GMapLoadMapEvent(); }, 500);
}


function GMapLoadMapEvent(){
	loadMarkers();
}


function setGMapType(type){
	if (typemap != 'gmap')
		return;
	createCookie('s_map_type', type, 100);

	if (type == 'sat')
		GMap.setMapTypeId(google.maps.MapTypeId.SATELLITE);
	if (type == 'map')
		GMap.setMapTypeId(google.maps.MapTypeId.ROADMAP);
	if (type == 'hyb')
		GMap.setMapTypeId(google.maps.MapTypeId.HYBRID);
}


function OSMapInit() {
	if (typemap != 'gmap') {
		GMapInit();
	}
	typemap = 'osmap';
	createCookie('s_map_provider', typemap, 100);
	$('#maptype').hide();

	addOSMLayer();
	GMap.setMapTypeId('osm');
}


function WikiMapInit(){
	if (typemap != 'gmap'){
		GMapInit();
	}
	typemap = 'wikimap';
	createCookie('s_map_provider', typemap, 100);

	$('#maptype').hide();

	GMap.setMapTypeId(google.maps.MapTypeId.SATELLITE);
	addWikiLayer();
}


function addOSMLayer(){
	var openStreet = new google.maps.ImageMapType({
		getTileUrl: function(ll, z) {
			return "http://tile.openstreetmap.org/" + z + "/" + ll.x + "/" + ll.y + ".png";
		},
		tileSize: new google.maps.Size(256, 256),
		isPng: true,
		maxZoom: 18,
		name: "OSM",
		alt: "Open Streetmap tiles"
	});

	GMap.mapTypes.set('osm', openStreet);
}


function addWikiLayer(){
	var Wikimapia = new google.maps.ImageMapType({
		getTileUrl: function(ll, z) {
			num = ll.x % 4 + (ll.y%4) *4;
			rnd = Math.round(Math.random() * 10000000);
			return "http://i"+ num +".wikimapia.org/?x=" + ll.x + "&y=" + ll.y + "&zoom=" + z + "&r="+rnd+"&type=hybrid&lng=1";
		},
		tileSize: new google.maps.Size(256, 256),
		isPng: true,
		maxZoom: 18,
		name: "Wikimapia",
		alt: "Wikimapia",
		opacity: 1.0
	});

	GMap.overlayMapTypes.push(null);
	GMap.overlayMapTypes.setAt("0", Wikimapia);
}


function GMapsMarkers(){
	for (i=0; i < markers.length; i++) {

		var filteredObj = false;

		for(c=0; c<gmap_collection.length; c++) {
			if (gmap_collection[c].id === markers[i].id){
				filteredObj = true;
				break;
			}
		}
		if (!filteredObj) {
			var category_id = getCategories(markers[i]);
			marker = GMapCreatePlacemark(markers[i], category_id);
			gmap_collection.push(marker);
		}

	}
}


function infoCallback(infowindow, marker) {
  return function() {
	infowindow.open(GMap, marker);
  };
}


function GMapCreatePlacemark(marker, category_id) {
    var ml=Number(marker.lat).toFixed(6);
    var l=lat.toFixed(6);
    var mll=Number(marker.lng).toFixed(6);
    var ll=long.toFixed(6);

    if ((ml==l) && (mll==ll))
    {
      // если это тот самый маркер, которому мы запрашиваем ближайших, то поменяем ему значок
	  	icon1="../_i/main_marker.png";
    }
    else
    {
		icon1="../_i/"+marker.active+marker.category_id+".png";
	}

	placemark = new google.maps.Marker({
		position: new google.maps.LatLng(marker.lat, marker.lng),
		map: GMap,
		title: marker.title,
		icon: icon1
	});
	placemark.id = marker.id;
	placemark.category_id = category_id;
	var infowindow = new google.maps.InfoWindow({maxWidth: 300});
	infowindow.setContent('<a href="'+ marker.url +'">' + marker.title + '</a><br> Адрес: ' + marker.address);
	google.maps.event.addListener(placemark, 'click', infoCallback(infowindow, placemark));

	return placemark;
}


function GMapToggleMarker(catgory_id, display) {
	for (i=0; i<gmap_collection.length; i++){
		if (gmap_collection[i].category_id === catgory_id){
			if (display == 0)
				gmap_collection[i].setVisible(true);
			else
				gmap_collection[i].setVisible(false);
		}
	}
}


function clearGMap() {
	for (i=0; i<gmap_collection.length; i++){
		gmap_collection[i].setMap(null);
	}
	gmap_collection = [];
}


function GMapDestroy() {
	if (!GMap)
		return;
	$('.ZoomPlus, .ZoomMinus').unbind('click');
	GMap = null;
	gmap_collection = [];
}

function WikiMap2Init() {
}


function loadMarkers() {
	t="http://"+window.location.hostname+"/_k/ajax/mapquery_json.php?lat="+lat+"&long="+long+"&callback=?";
	if (points_src == 'mlist')
		t="http://"+window.location.hostname+"/mlist/json.txt";
	if (points_src == 'wood')
		t="http://"+window.location.hostname+"/wood/json.txt";
	if (points_src == 'old')
		t="http://"+window.location.hostname+"/oldbelief/json.txt";

	if (ajax == true)
		$.ajax({
			url: t,
			cache: false,
			dataType: "json",
			success: function(data) {
				createMarkers(data);
			}
		});
	else
		createMarkers(points);
}


function createMarkers(data){
    var findObject;
    var marker;
    var category_id;
    var filter;

    markers = [];
	f = [];
	$('.cat-list input:checked').each(function(){
		f.push($(this).val());
	});
	var a = $('#actfilter').is(':checked') ? 1 : 0;
	for(i=0; i < data.length; i++){
		marker = data[i];
		findObject = true;

		if (marker.active == 2)
			marker.active = 0;

		if (a && marker.active == 0)
			findObject = false;

		category_id = getCategories(marker);
		filter = false;
		for (c=0; c<f.length; c++){
			if (category_id == f[c]){
				filter = true;
				break;
			}
		}

		if (findObject && filter)
			markers.push(marker);
	}
	switch(typemap){
		case 'ymap':
			clearYMap();
			YmapMarkers();		
			break;
		case 'gmap': case 'osmap': case 'wikimap':
			clearGMap();
			GMapsMarkers();
			break;
		case 'dgmap':
			DGMapsMarkers();
			break;
		case 'bingmap' :
			BingMapsMarkers();
			break;
	}
}
function RedrawMap() {
	switch(typemap){
		case 'ymap':
			Ymap.container.fitToViewport();
			break;
		case 'gmap': case 'osmap': case 'wikimap':
			google.maps.event.trigger(GMap, "resize");
			break;
		case 'dgmap':
			DGMap.redraw();
			break;
		case 'bingmap':
			BingMap.setView({height: $('#MyMap').height(), width: $('#MyMap').width()});
			break;
}
}