
var isOpenMap=0;

var GM_APIKEY='ABQIAAAADugInuuNHROG_ZFJ0x6ZvhTZC8eXyDsEvJriNYUDKiZ1-tXy3BQIRPpawfWgEu7D9AmGo5dmxCYrsw';

var map;
var MLFiles = new Array();
var MLTriger = new Array();

var MapCatalogTypes=[];
var MapObjectsSet=[];

var ballon_template = 0;

var maps_variant = 'yandex';

var filterActive={
	price:0,
	places:0,
	apply: function (data){
		if((!filterActive.price  || filterActive.price ==data['Price']) &&
	       (!filterActive.places || data['explode_Places'][filterActive.places])){
				return true;
			}else {
				return false;
			}
	}
	};
	
var mapStartupActions={'show':0,'lr':[]};

mapStartupActions.lr[2]=2;

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


var curloc=window.location.href;

if(curloc.indexOf('/restoran.html') != -1){
	mapStartupActions.show=1;
}



function showMap() {
	if(isOpenMap!=0) {
		jQuery("#citymap").empty();
		jQuery("#citymap").css("display", "none");
		isOpenMap=0;
	} else {
		jQuery("#citymap").css({display:"block",height:'500px'});
		
		jQuery("<div style='width:100%;height:100%;background:#FFF;' id='YMapID'></div>").appendTo(jQuery("#citymap"));
		jQuery("<div id='externalmaprefs' style='display:none'></div>").appendTo(jQuery("#citymap"));
		loadExternalFiles();
		$.ajax({
			url:"/ajax/mapcontent.php",
			scriptCharset:"windows-1251",
			async:false,
			success:function(data){
	     $("#externalmaprefs").html(data);
		 
		 
         $("#darkdotup").insertBefore("#main");
		 
		 StartMaps();
		}
		});
		isOpenMap=1;
       }
}

function add_script(src){
	var fileref=document.createElement("script");
	fileref.type="text/javascript";
  	fileref.src=src;
  	document.getElementsByTagName("head")[0].appendChild(fileref);
}

function add_css(src){
	var fileref=document.createElement("link");
  	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
  	fileref.setAttribute("href", src);
 	if (typeof fileref!="undefined") {
  		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}

function loadExternalFiles() {
	add_css("/styles/map.css");
	add_css("/styles/smoothDivScroll.css");
}

function innerGoogleLoad(){
	if(window.google && window.google.load){
			   google.load("maps", "2", {"callback" : function(){
			setTimeout(function(){GapiLoaded();},1);
			},"language" : "ru","hl":"ru","base_domain":"maps.google.ru"});
	 return true;
	}
	setTimeout(function(){innerGoogleLoad()},1);
	return false;
}

function StartMaps(){
	if(maps_variant=='yandex'){
	  setTimeout(function(){setTimeout(function(){
		YMaps.load(function(){setTimeout(function(){YapiLoaded();},1)});
		},1);});
	}
	if(maps_variant=='google'){
	  if(!window.google || !window.google.load){
		add_script("http://www.google.ru/jsapi?hl=ru&key="+GM_APIKEY)
	  }
	 innerGoogleLoad();
 	}
}

function geoPoint(x,y){
	if(maps_variant=='yandex')return new YMaps.GeoPoint(x,y);
	else                      return new GLatLng(y,x);
}

function set_initCenter(){
	if(map.getZoom()==11){
		map.panTo(geoPoint(37.606,55.754));
	}
	else{
		map.setCenter(geoPoint(37.606,55.754),11);
	}
}

function YapiLoaded() {
  	    map = new YMaps.Map($("#YMapID")[0]);		
		ballon_template = new YMaps.LayoutTemplate(MyBalloonLayout);		
        set_initCenter();		
        map.addControl(new YMaps.SmallZoom());
        map.addControl(new YMaps.TypeControl(), new YMaps.ControlPosition(YMaps.ControlPosition.TOP_LEFT, new YMaps.Size(10, 10)));
        map.addControl(new CatalogNavigator('/ajax/z/catalog.php'));
		//, new YMaps.ControlPosition(YMaps.ControlPosition.TOP_RIGHT, new YMaps.Size(0, 0)));
		
		(function(){var makeStyle=function(key,hint,balloon){var s = new YMaps.Style();if(hint){s.hintContentStyle={template:"tili#"+hint};}if(balloon){s.balloonContentStyle={template:"tili#"+balloon};}YMaps.Styles.add("tili#"+key,s);};var makeTemplate=function(key, template){var t=new YMaps.Template(template);YMaps.Templates.add("tili#"+key,t);};makeStyle("style0","","");})();
		
		tili_parks();
}

function GapiLoaded() {
  	    map =  new GMap2($("#YMapID")[0]);
	//	map.getContainer
        set_initCenter();		
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new CatalogNavigator('/ajax/z/catalog.php'));
					   //new YMaps.ControlPosition(YMaps.ControlPosition.TOP_RIGHT, new YMaps.Size(0, 0)));		
		tili_parks();
}


//Catalog Navigator control

function CatalogNavigator (listurl) {
	
			this.getDefaultPosition = function() {
			  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(0,0));
			}
            this.initialize = function(map) {
				this.onAddToMap(map,0);
			}
            this.onAddToMap = function (map, position) {
				    var _this=this;
                    this.container =$("<div id='WeddingMapNavigator'></div>");
					
                    
                    this.map = map;
                    this.position = position;// || new YMaps.ControlPosition(YMaps.ControlPosition.TOP_RIGHT, new YMaps.Size(10, 10));

                    this.container.css({
                        position: "absolute",
                        zIndex: 1000,
                        listStyle: 'none',
						right:'0px',
						top:'10px'
                    });
					
					this.container.html($("#store_map_navigator").html());					
					$("#store_map_navigator").html("");
                    setTimeout(function(){
						$(".WeddingControl",this.container).click(function(){							
							var innerText=$(this).next();
							var holder=$(this);
							$(".WeddingControl",this.container).stop();
							$(".WeddingControl",this.container).removeClass("active");
							
							jQuery.each($(".WeddingContainer",this.container), function(i, field){
                              if(field==innerText.get(0)){
								if(field.style.display=='block'){
									innerText.slideUp();
								}
								else{
									innerText.slideDown();
									holder.addClass('active');
								}
							  }
							  else{								
								$(field).slideUp();
							  }
	                        });							
						});
					})
                    this._loadControlList();
                    
                    //this.position.apply(this.container);
                    
                    this.container.appendTo(this.map.getContainer());
            };

            this.remove = function () { this.onRemoveFromMap();}
            this.onRemoveFromMap = function () {
                this.container.remove();
                this.container = this.map = null;
            };

            this.printable = function(){return false;}
            this._loadControlList = function () {
                var _this = this;
                $.get(listurl, null, function(data,status){_this._parseCatalogItems(data,status)}, "json");
            };

            this._parseCatalogItems = function(data, status) {
            	if(status=='success') {
					var i;
					for( i in data){
					 _addCatalogItem(i,data[i],this.container);
					}
            	} else {
            		alert("Error load catalog");
            		this.onRemoveFromMap();
            	}
				
				var i;
				for(i in mapStartupActions.lr){
					_clickOnCatalogItemHotSpot(i);
				}
            };

	}
//
function _addCatalogItem(i, obj, parent) {
	var title=obj.name;
	if(obj.short_name)
	 title=obj.short_name;
	var toolicon=obj.tool_icon;
	var id=obj.id_catalog;
	var cid = id;
	if(!toolicon){
	 toolicon="def_tool.png";
	}
	var li = $("<li class=\"catalog cid"+cid+"\"><a href=\"#\">" + title + "</a><i>загрузка...</i></li>");
	var anc = li.find("a");
	anc.css("background-image" ,"url(/images/icons/" + toolicon +")");
	anc.css("background-repeat", "no-repeat");
	
	MLTriger[cid]=0;
	anc.bind("click", function () {_clickOnCatalogItemHotSpot(cid); return false;});
	li.appendTo($("#CatalogNavigator",parent));
	MapCatalogTypes[id]=obj;
};

function mapBallonPopup(html){
	$("#darkdotup").css({height:$("body").height()});
	$("#darkdotup").show();
	
	$("#darkdotinner").html(html);
	return $("#darkdotinner");
}

function map_dark_off(){
	$("#darkdotup").hide();
	return false;
}

function _clickOnCatalogItemHotSpot(catid) {
	if(maps_variant!='yandex'){return _clickOnCatalogItem(catid);}
	if(!MapObjectsSet[catid] || !MapObjectsSet[catid].hotSpot)
	  loadMapHotSpot(catid,'hotspot');
	else
	  MapObjectsSet[catid].toggle('hotspot');
}

function _clickOnCatalogItem(catid) {
	if(!MapObjectsSet[catid] || !MapObjectsSet[catid].hasObjects)
	  loadMapCat(catid,'parse');
	else
	  MapObjectsSet[catid].toggle('parse');
}

function loadMapHotSpot(catid){
	if(MapObjectsSet[catid]){
		MapObjectsSet[catid].hide();
		delete MapObjectsSet[catid];							
	}
	MapObjectsSet[catid]=new MapObjectSet(catid,map);
	MapObjectsSet[catid].hotSpot=1;
	MapObjectsSet[catid].show();
}

function loadMapCat(catid){		
	$("#CatalogNavigator li.cid"+catid+" i").addClass("loading");
	 $(".loadingMapCtrl.cid"+catid).addClass("loading");
	var addr=("/ajax/z/list.php?id=" + catid);	
	var params={cache:false,url:addr,
	            success:function(data){
					setTimeout(function(){
						$("#CatalogNavigator li.cid"+catid+" i").removeClass("loading");
						 $(".loadingMapCtrl.cid"+catid).removeClass("loading");
						if(MapObjectsSet[catid]){
							MapObjectsSet[catid].hide();
							delete MapObjectsSet[catid];							
						}
						MapObjectsSet[catid]=new MapObjectSet(catid,map);
						MapObjectsSet[catid].inject(data);
						MapObjectsSet[catid].hasObjects=1;
						MapObjectsSet[catid].show();
					},1);
				},
				dataType:'json',contentType: "application/json"};
	$.ajax(params);
}

BanketContainerShow = function(){
	var i;
	for ( i in MapObjectsSet){
		if(MapObjectsSet[i] && MapObjectsSet[i].shown)
		 MapObjectsSet[i].hide();		 
	}
	
	filterActive1=$("#BanketContainer .mprice").val();
	filterActive2=$("#BanketContainer .nguests").val();
	
	filterActive.price=filterActive1;
	filterActive.places=filterActive2;
	
	_clickOnCatalogItem(2);
	
}

/********************************************************/
/********************************************************/
/********************************************************/

function MapObjectSet(catid,map){
	this.catid  =catid;
	this.shown  =0;
	this.objects=[];
	this.map    =map;
}

MapObjectSet.prototype.selfSelector = function(){
	return "#CatalogNavigator .catalog.cid"+this.catid;
}

MapObjectSet.prototype.initHotSpot = function (){
	if(this.TileLayer)return;
	function processTemplate (template, tile, zoom) {
                return template.replace(/%x/ig, tile.getX()).replace(/%y/ig, tile.getY()).replace(/%z/ig, zoom);
    }
	
	// Источник тайлов с изображениями
	var ds = new YMaps.TileDataSource('/htile/'+this.catid+'/png/%z/tile-%x-%y.png', 1, 0);
	ds.getTileUrl = function (tileNumber, zoom) {
		return processTemplate(
			YMaps.TileDataSource.prototype.getTileUrl.call(this, tileNumber, zoom),
			tileNumber,
			zoom
		);
	};
	// Добавляем "картиночный" слой на карту
	this.TileLayer=new YMaps.Layer(ds);
	
	// Источник тайлов с описаниями активных областей
	var os = new YMaps.Hotspots.ObjectSource('/htile/'+this.catid+'/js/%z/tile-%x-%y.js', 'tili-'+this.catid+'-%x-%y-%z');
	os.getTileUrl = function (tileNumber, zoom) {
		return processTemplate(
			YMaps.Hotspots.ObjectSource.prototype.getTileUrl.call(this, tileNumber, zoom),
			tileNumber,
			zoom
		);
	};
	os.getKey = function (tileNumber, zoom) {
		return processTemplate(
			YMaps.Hotspots.ObjectSource.prototype.getKey.call(this, tileNumber, zoom),
			tileNumber,
			zoom
		);
	};
	// Добавляем слой активных областей на карту
	this.hLayer = new YMaps.Hotspots.Layer(os,{hasHint:true,hasBalloon:false});
}

MapObjectSet.prototype.show = function(){
	if(this.shown)return;
	
	set_initCenter();
	
	this.shown=1;
	$(this.selfSelector()).addClass("selected");
	var i;
	if(this.hotSpot){
		this.initHotSpot();
		this.map.addLayer(this.TileLayer);
		this.map.addLayer(this.hLayer);
		if(!this.hotClick){
			this.hotClick=YMaps.Events.observe(this.hLayer, this.hLayer.Events.Click, function (lay,obj,event) {
				//console.log(obj,a1,a2);
				var Object=new MapObject(obj.getData().metaDataProperty.AnyMetaData);				
				Object.show();
				Object.kamikadze();
				Object.openBalloon();
			});
		}
		this.hotClick.enable();
	}
	else{
		for(i in this.objects)
		 if(this.objects[i])
		   this.objects[i].show();
	}
}

MapObjectSet.prototype.hide = function(){
	if(!this.shown)return;
	$(this.selfSelector()).removeClass("selected");
	this.shown=0;
	var i;
	if(this.hotSpot){
		if(this.TileLayer){
			this.map.removeLayer(this.TileLayer);
			this.map.removeLayer(this.hLayer);
			this.hotClick.disable();
		}
	}
	else{
		for(i in this.objects)
		 if(this.objects[i])
		   this.objects[i].hide();
	}
}

MapObjectSet.prototype.toggle = function(){
	if(!this.shown)this.show();
	else           this.hide();
}

MapObjectSet.prototype.inject = function(data){
	this.objectsData=data;
	
	var i;
	for(i in this.objectsData){
		this.objects.push(new MapObject(this.objectsData[i]))
	}
}

/********************************************************/
/********************************************************/
/********************************************************/

function MapObject(data){
	this.data=data;
	//expand places
	var pset=[];
	if(data['Places']){
	var places=data['Places'].split(';');
	
	var i;
	for(i in places){var ii=places[i]; pset[ii]=ii;}
	}
	this.data['explode_Places']=pset;
		
	this.ext=MapCatalogTypes[data.id_catalog].ext;
}


var map_cached_styles=[];
MapObject.prototype.getStyle = function (){
	var cache_name=maps_variant+this.data.map_icon;
	if(maps_variant=='yandex'){
		if(!map_cached_styles[cache_name]){
			var s = new YMaps.Style();
			s.iconStyle = new YMaps.IconStyle();
			if(this.data.markerImage)
			 s.iconStyle.href=this.data.markerImage;
			else 
			 s.iconStyle.href = "http://odinmillion.ru/images/icons/"+this.data.map_icon;
			s.iconStyle.size = new YMaps.Point(36, 41);
			s.iconStyle.offset = new YMaps.Point(-14, -41);
	
			
			if(ballon_template)
			 s.balloonContentStyle={template :ballon_template}
	
			map_cached_styles[cache_name]=s;
		}
	}
	if(maps_variant=='google'){
		if(!map_cached_styles[cache_name]){
			var s = {};
			s.icon=new GIcon(G_DEFAULT_ICON);
			if(this.data.markerImage)
			 s.icon.image=this.data.markerImage;
			else 
			 s.icon.image = "http://odinmillion.ru/images/icons/"+this.data.map_icon;
			 
			s.icon.shadow='';
            s.icon.iconSize  =new GSize(36,41);
            s.icon.iconAnchor=new GPoint(14,41);  
				
			map_cached_styles[cache_name]=s;
		}
	}
	return map_cached_styles[cache_name];
	
}


MapObject.prototype.getCenter = function(){
	return geoPoint(this.data.lng,this.data.lat);
}


MapObject.prototype.getPanoramaBlock = function( panorama ){
	 return '<div class="panoramaset"><div class="panoramain">'+
	 '<iframe src="/panorama/u'+this.data['id_user']+'/index.html" frameborder=0 style="width:560px;height:340px" scrolling="no"></iframe>'+
	 '<BR><center><a href=# class=panclose>закрыть</a></center></div>'+
	 '<a href=# class="panoopen"><img src="/panorama/u'+this.data['id_user']+'/index.jpg"></a></div>';

}

MapObject.prototype.getPanoramaOuter = function (){
	 if(this.data.panorama_file){
		var ret=this.getPanoramaBlock();
		return ret;
	 }
	 else
	  if(this.data.panorama){
		return '<iframe src="'+this.data.panorama+'.html" frameborder=0 style="width:560px;height:340px" scrolling="no"></iframe>';
	  }
	 return '';
}

MapObject.prototype.getBannerContent = function(){
	var ret='<div class="bannercontent">';
	
	
   var m3_u = (location.protocol=='https:'?'https://adv2.directad.ru/www/delivery/ajs.php':'http://adv2.directad.ru/www/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   setDocumentWriteTarget(".balCon .bannercontent");
   
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=60");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");	
	ret+="</div>";
	return ret;
}

MapObject.prototype.getBallonHtml = function (){
	var ret='';
	ret+="<div class='balCon'>";
	//ret+="<a class=closer style='float:right' href='#' onclick='return map_dark_off();'>X</a>"
    ret+="<h1>"+this.data.company_name+"</h1>";
	if(!this.data.disableBanners)
	  ret+=this.getBannerContent();
	if(this.data.logo)
	ret+="<img class=ilogo src='/uploads/"+this.data.logo+"'>";	
	
	ret+="<div class='infoframe'>";
	if(this.data.company_phone)
		ret+="<p>"+this.data.company_phone+"</p>";
	if(this.data.company_address)
		ret+="<p>"+this.data.company_address +"</p>";
	if(this.data.company_site)
		ret+="<p><a href='"+this.data.company_site+"' target=_blank>"+this.data.company_site+"</a></p>";
		
		var i;
		for(i in this.ext)
		if(this.data[i]){
			var ext=this.ext[i];
			var value=this.data[i];
			if(this.ext[i].type=='enum'){
				value=ext['enum'][value];
			}
			if(value)
			 ret+="<p>"+this.ext[i].name+":<span>"+value+"</span></p>";
		}
	ret+="</div>";
	//ret+="<br class=clear />";
	
	if(this.data.id_catalog!=2 && this.data.company_description)
	 ret+="<p>"+this.data.company_description+"</p>";
	
	var images='';
	var i;
	for(i in this.data.images){
		images+="<a href='/uploads/"+this.data.images[i].photo+"' rel='ballonimages' title='' target=_blank><img src='/uploads/2_"+this.data.images[i].photo+"'></a>";
	}
	ret+="<table class='balmedia' width='100%'><tr><td class='panorama' align='center'>";
	ret+=this.getPanoramaOuter();
	ret+="</td><td>";
	if(images){
		ret+='<div class="gallery">'+
	         '<div class="scrolling scrollingHotSpotLeft"></div>'+
			 '<div class="scrolling scrollingHotSpotRight"></div>'+
			 '<div class="scrollWrapper">'+
			 '<div class="scrollableArea" ><div class="innerWidther">'+
	         images+
			 "</div></div></div</div>";
	}

	ret+="</td></tr></table>";
	
	
	ret+="</div>";
	return ret;
}

MapObject.prototype.jquery = function(div){
	
	tb_init($(".gallery a",div));	
	
	if(0){
	$(".gallery",div).smoothDivScroll({
		scrollingSpeed: 6,
		mouseDownSpeedBooster: 3,
		//autoScroll: "onstart",
		autoScrollDirection: "backandforth",
		autoScrollSpeed: 1,
		visibleHotSpots: "onstart",
		hotSpotsVisibleTime: 9
	});
	}
	
	this.gallery=new MyGallery($(".gallery",div));
	
	$(".panclose",div).click(function(){
		$(".panoramain",$(this).parents(".panoramaset")).hide();return false;
		});
	
	$(".panoopen",div).click(function(){
		$(".panoramain",$(this).parents(".panoramaset")).show();return false;
	});
	
	
}



var this_balloon_template=0;
var thistemplatenode='';

MapObject.prototype.openBalloon = function(){
	this.marker.openBalloon();
}

MapObject.prototype.kamikadze = function(){
	var _this=this;
	YMaps.Events.observe(this.marker, this.marker.Events.BalloonClose, function () {
	_this.dropMarker();
	delete _this;
	});
}

MapObject.prototype.show = function(){
	
	if(!filterActive.apply(this.data)) return;
	
	if(!this.marker && maps_variant=='yandex'){
		var s=this.getStyle();
		this.marker = new YMaps.Placemark(this.getCenter(), {style: s, hasHint:1});
		this.marker.name = this.data.company_name;
		this.marker.tiliObj=this;
	}
	
	if(!this.marker && maps_variant=='google'){
		var s=this.getStyle();
		s={icon:s.icon,title:this.data.company_name}
		this.marker = new GMarker(this.getCenter(), s);       
		this.marker.name = this.data.company_name;
		this.marker.tiliObj=this;
		var marker=this.marker;
		GEvent.addListener(marker, 'click', 
            function(){
				thistemplatenode=$("<div></div>");
				thistemplatenode.html(marker.tiliObj.getBallonHtml());
                setTimeout(function(){marker.tiliObj.jquery(thistemplatenode);},1);
				marker.openInfoWindow(thistemplatenode.get(0));
			});

	}
	
	map.addOverlay(this.marker);
}

MapObject.prototype.dropMarker = function(){
	if(this.marker){
		this.hide();
		this.marker.closeBalloon();
		delete this.marker;
		this.marker=0;
	}
}

MapObject.prototype.hide = function(){
	map.removeOverlay(this.marker);
}



 //let it hack :)
 var document_write_target='';
 var document_write_text='';
 
 var document_write_timeout=0;
 
 function setDocumentWriteTarget(targ){
	if(!document_write_target)
	 documentWriteOverload();
	else
	 document_write_flush();
	 
	document_write_target=targ; 
 }
 
 function documentWriteOverload(){
	document.write=function(a){
	   document_write_text+=a;
	   clearTimeout(document_write_timeout);
	   document_write_timeout=setTimeout(function(){document_write_flush()},1);
	}
 }
 
 document_write_flush = function()
 {
	   target=document_write_target;
       clearTimeout(document_write_timeout);
       if(document_write_text){
		
		var intarget=target;
		var intext="<div>"+document_write_text+"</div>";
		document_write_text='';
		var element=$(intext);
		$(target).append(element);
		document_write_flush(target);	
       }       
 }
 
 // Класс для создания макета для содержимого балуна
        function MyBalloonLayout (context, map, owner) {
            this.balloon = $("<div></div>");
            this.context = context;
        }

        MyBalloonLayout.prototype = {
           // Вызывается при открытии балуна
            onAddToParent : function (parentNode) {
                this.balloon.appendTo(parentNode);
				this_balloon_template =  this.balloon;
                this.update();
            },

            // Вызывается при закрытии балуна
            onRemoveFromParent : function () {
                this.balloon.remove();
            },

            // Обновление содержимого балуна
            update : function () {
                // Получаем стиль метки
                this.balloon.html(this.context.tiliObj.getBallonHtml());
				var _this=this;
                setTimeout(function(){_this.context.tiliObj.jquery(_this.balloon);},1);
            }
        }
		
function MapParksSet(){
	this.catid='parks';
}

MapParksSet.prototype=new MapObjectSet();

MapParksSet.prototype.selfSelector = function(){
	return "#WalkContainer .catalog.cid"+this.catid;
}

MapParksSet.prototype.load= function(data){
	var lines=data.split("\n");
	MapCatalogTypes[this.catid]={ext:{}};
	var i;
	var set=[];
	for(i in lines){
		var line=lines[i].split(",");
		var dl={};
		dl.company_name=line[0]
		dl.lat=parseFloat(line[2].trim());
		dl.lng=parseFloat(line[1].trim());
		dl.panorama=line[3].trim();
		dl.id_catalog=this.catid;
		dl.disableBanners=1;
		dl.markerImage='/images/markers/mark_parks.png';
		set.push(dl);
	}
	
	this.inject(set);	
}



function load_parks_data(catid,data){
	MapObjectsSet[catid]=new MapParksSet();
	MapObjectsSet[catid].load(data);
	MapObjectsSet[catid].show();
}

function tili_parks_load(asname){
	var addr=("/ajax/parks.php");	
	var params={cache:false,url:addr,
	            success:function(data){
					setTimeout(function(){
						load_parks_data(asname,data);
					},1);
				},
				contentType: "text/plain"};
	$.ajax(params);
}

function tili_parks(){
	catid='tili_parks';
	if(!MapObjectsSet[catid])
	  tili_parks_load(catid);
	else
	 MapObjectsSet[catid].toggle();
	 
	return false; 
}


$(document).ready(function(){
 if(mapStartupActions.show) showMap();
});


function MyGallery(selector){
	this.sel=selector;
	this.gal=$(".scrollWrapper",this.sel);

	this.scroll_tm=0;
    this.init();
}

MyGallery.prototype.init = function(){
	var _this=this;
	var __thisthis=this;
	$(".scrollingHotSpotLeft" ,this.sel).mousedown(function(){_this.scroll(-1);});
	$(".scrollingHotSpotRight",this.sel).mousedown(function(){
		_this.scroll(1);
	});
	$(".scrolling",this.sel).mouseup(function(){_this.stop();});
	$(".scrolling",this.sel).mouseleave(function(){_this.stop();});
}



MyGallery.prototype.scroll = function(dir){
	this.stop();
	var _this=this;
	clearTimeout(this.scroll_tm);
	this.scroll_tm=setTimeout(function(){
		_this.scrolling(dir)
	},1);
	
}

MyGallery.prototype.scrolling = function(dir){
	var off =this.gal.scrollLeft();
	var noff=off+4*dir;
	var w=$(".innerWidther",this.gal).width()-$(".scrollWrapper",this.sel).width();
	if(dir<0 && noff<1){}
	else if(dir>0 && noff>w){}
	else{
		this.gal.scrollLeft(noff);
	}
	this.scroll(dir);
}

MyGallery.prototype.stop = function(){
	//this.gal.stop();
	clearTimeout(this.scroll_tm);
}