if(!Control)var Control={};Control.Slider=Class.create({initialize:function(handle,track,options){var slider=this;if(Object.isArray(handle)){this.handles=handle.collect(function(e){return $(e)});}else{this.handles=[$(handle)];}
this.track=$(track);this.options=options||{};this.axis=this.options.axis||'horizontal';this.increment=this.options.increment||1;this.step=parseInt(this.options.step||'1');this.range=this.options.range||$R(0,1);this.value=0;this.values=this.handles.map(function(){return 0});this.spans=this.options.spans?this.options.spans.map(function(s){return $(s)}):false;this.options.startSpan=$(this.options.startSpan||null);this.options.endSpan=$(this.options.endSpan||null);this.restricted=this.options.restricted||false;this.maximum=this.options.maximum||this.range.end;this.minimum=this.options.minimum||this.range.start;this.alignX=parseInt(this.options.alignX||'0');this.alignY=parseInt(this.options.alignY||'0');this.trackLength=this.maximumOffset()-this.minimumOffset();this.handleLength=this.isVertical()?(this.handles[0].offsetHeight!=0?this.handles[0].offsetHeight:this.handles[0].style.height.replace(/px$/,"")):(this.handles[0].offsetWidth!=0?this.handles[0].offsetWidth:this.handles[0].style.width.replace(/px$/,""));this.active=false;this.dragging=false;this.disabled=false;if(this.options.disabled)this.setDisabled();this.allowedValues=this.options.values?this.options.values.sortBy(Prototype.K):false;if(this.allowedValues){this.minimum=this.allowedValues.min();this.maximum=this.allowedValues.max();}
this.eventMouseDown=this.startDrag.bindAsEventListener(this);this.eventMouseUp=this.endDrag.bindAsEventListener(this);this.eventMouseMove=this.update.bindAsEventListener(this);this.handles.each(function(h,i){i=slider.handles.length-1-i;slider.setValue(parseFloat((Object.isArray(slider.options.sliderValue)?slider.options.sliderValue[i]:slider.options.sliderValue)||slider.range.start),i);h.makePositioned().observe("mousedown",slider.eventMouseDown);});this.track.observe("mousedown",this.eventMouseDown);document.observe("mouseup",this.eventMouseUp);document.observe("mousemove",this.eventMouseMove);this.initialized=true;},dispose:function(){var slider=this;Event.stopObserving(this.track,"mousedown",this.eventMouseDown);Event.stopObserving(document,"mouseup",this.eventMouseUp);Event.stopObserving(document,"mousemove",this.eventMouseMove);this.handles.each(function(h){Event.stopObserving(h,"mousedown",slider.eventMouseDown);});},setDisabled:function(){this.disabled=true;},setEnabled:function(){this.disabled=false;},getNearestValue:function(value){if(this.allowedValues){if(value>=this.allowedValues.max())return(this.allowedValues.max());if(value<=this.allowedValues.min())return(this.allowedValues.min());var offset=Math.abs(this.allowedValues[0]-value);var newValue=this.allowedValues[0];this.allowedValues.each(function(v){var currentOffset=Math.abs(v-value);if(currentOffset<=offset){newValue=v;offset=currentOffset;}});return newValue;}
if(value>this.range.end)return this.range.end;if(value<this.range.start)return this.range.start;return value;},setValue:function(sliderValue,handleIdx){if(!this.active){this.activeHandleIdx=handleIdx||0;this.activeHandle=this.handles[this.activeHandleIdx];this.updateStyles();}
handleIdx=handleIdx||this.activeHandleIdx||0;if(this.initialized&&this.restricted){if((handleIdx>0)&&(sliderValue<this.values[handleIdx-1]))
sliderValue=this.values[handleIdx-1];if((handleIdx<(this.handles.length-1))&&(sliderValue>this.values[handleIdx+1]))
sliderValue=this.values[handleIdx+1];}
sliderValue=this.getNearestValue(sliderValue);this.values[handleIdx]=sliderValue;this.value=this.values[0];this.handles[handleIdx].style[this.isVertical()?'top':'left']=this.translateToPx(sliderValue);this.drawSpans();if(!this.dragging||!this.event)this.updateFinished();},setValueBy:function(delta,handleIdx){this.setValue(this.values[handleIdx||this.activeHandleIdx||0]+delta,handleIdx||this.activeHandleIdx||0);},translateToPx:function(value){return Math.round(((this.trackLength-this.handleLength)/(this.range.end-this.range.start))*(value-this.range.start))+"px";},translateToValue:function(offset){return((offset/(this.trackLength-this.handleLength)*(this.range.end-this.range.start))+this.range.start);},getRange:function(range){var v=this.values.sortBy(Prototype.K);range=range||0;return $R(v[range],v[range+1]);},minimumOffset:function(){return(this.isVertical()?this.alignY:this.alignX);},maximumOffset:function(){return(this.isVertical()?(this.track.offsetHeight!=0?this.track.offsetHeight:this.track.style.height.replace(/px$/,""))-this.alignY:(this.track.offsetWidth!=0?this.track.offsetWidth:this.track.style.width.replace(/px$/,""))-this.alignX);},isVertical:function(){return(this.axis=='vertical');},drawSpans:function(){var slider=this;if(this.spans)
$R(0,this.spans.length-1).each(function(r){slider.setSpan(slider.spans[r],slider.getRange(r))});if(this.options.startSpan)
this.setSpan(this.options.startSpan,$R(0,this.values.length>1?this.getRange(0).min():this.value));if(this.options.endSpan)
this.setSpan(this.options.endSpan,$R(this.values.length>1?this.getRange(this.spans.length-1).max():this.value,this.maximum));},setSpan:function(span,range){if(this.isVertical()){span.style.top=this.translateToPx(range.start);span.style.height=this.translateToPx(range.end-range.start+this.range.start);}else{span.style.left=this.translateToPx(range.start);span.style.width=this.translateToPx(range.end-range.start+this.range.start);}},updateStyles:function(){this.handles.each(function(h){Element.removeClassName(h,'selected')});Element.addClassName(this.activeHandle,'selected');},startDrag:function(event){if(Event.isLeftClick(event)){if(!this.disabled){this.active=true;var handle=Event.element(event);var pointer=[Event.pointerX(event),Event.pointerY(event)];var track=handle;if(track==this.track){var offsets=this.track.cumulativeOffset();this.event=event;this.setValue(this.translateToValue((this.isVertical()?pointer[1]-offsets[1]:pointer[0]-offsets[0])-(this.handleLength/2)));var offsets=this.activeHandle.cumulativeOffset();this.offsetX=(pointer[0]-offsets[0]);this.offsetY=(pointer[1]-offsets[1]);}else{while((this.handles.indexOf(handle)==-1)&&handle.parentNode)
handle=handle.parentNode;if(this.handles.indexOf(handle)!=-1){this.activeHandle=handle;this.activeHandleIdx=this.handles.indexOf(this.activeHandle);this.updateStyles();var offsets=this.activeHandle.cumulativeOffset();this.offsetX=(pointer[0]-offsets[0]);this.offsetY=(pointer[1]-offsets[1]);}}}
Event.stop(event);}},update:function(event){if(this.active){if(!this.dragging)this.dragging=true;this.draw(event);if(Prototype.Browser.WebKit)window.scrollBy(0,0);Event.stop(event);}},draw:function(event){var pointer=[Event.pointerX(event),Event.pointerY(event)];var offsets=this.track.cumulativeOffset();pointer[0]-=this.offsetX+offsets[0];pointer[1]-=this.offsetY+offsets[1];this.event=event;this.setValue(this.translateToValue(this.isVertical()?pointer[1]:pointer[0]));if(this.initialized&&this.options.onSlide)
this.options.onSlide(this.values.length>1?this.values:this.value,this);},endDrag:function(event){if(this.active&&this.dragging){this.finishDrag(event,true);Event.stop(event);}
this.active=false;this.dragging=false;},finishDrag:function(event,success){this.active=false;this.dragging=false;this.updateFinished();},updateFinished:function(){if(this.initialized&&this.options.onChange)
this.options.onChange(this.values.length>1?this.values:this.value,this);this.event=null;}});var MapIconMaker={};MapIconMaker.createMarkerIcon=function(opts){var width=opts.width||32;var height=opts.height||32;var primaryColor=opts.primaryColor||"#ff0000";var strokeColor=opts.strokeColor||"#000000";var cornerColor=opts.cornerColor||"#ffffff";var baseUrl="http://chart.apis.google.com/chart?cht=mm";var iconUrl=baseUrl+"&chs="+width+"x"+height+"&chco="+cornerColor.replace("#","")+","+primaryColor.replace("#","")+","+strokeColor.replace("#","")+"&ext=.png";var icon=new GIcon(G_DEFAULT_ICON);icon.image=iconUrl;icon.iconSize=new GSize(width,height);icon.shadowSize=new GSize(Math.floor(width*1.6),height);icon.iconAnchor=new GPoint(width/2,height);icon.infoWindowAnchor=new GPoint(width/2,Math.floor(height/12));icon.printImage=iconUrl+"&chof=gif";icon.mozPrintImage=iconUrl+"&chf=bg,s,ECECD8"+"&chof=gif";var iconUrl=baseUrl+"&chs="+width+"x"+height+"&chco="+cornerColor.replace("#","")+","+primaryColor.replace("#","")+","+strokeColor.replace("#","");icon.transparent=iconUrl+"&chf=a,s,ffffff11&ext=.png";icon.imageMap=[width/2,height,(7/16)*width,(5/8)*height,(5/16)*width,(7/16)*height,(7/32)*width,(5/16)*height,(5/16)*width,(1/8)*height,(1/2)*width,0,(11/16)*width,(1/8)*height,(25/32)*width,(5/16)*height,(11/16)*width,(7/16)*height,(9/16)*width,(5/8)*height];for(var i=0;i<icon.imageMap.length;i++){icon.imageMap[i]=parseInt(icon.imageMap[i]);}
return icon;}
function MarkerClusterer(map,opt_markers,opt_opts){var clusters_=[];var map_=map;var maxZoom_=null;var me_=this;var gridSize_=60;var sizes=[53,56,66,78,90];var styles_=[];var leftMarkers_=[];var mcfn_=null;var zoomOnClick_=true;var calculator_=function(markers){var index=0;var count=markers.length;var dv=count;while(dv!==0){dv=parseInt(dv/10,10);index++;}
var stylesCount=this.getStyles().length;if(stylesCount<index){index=stylesCount;}
return{'text':count,'index':index};};var i=0;for(i=1;i<=5;++i){styles_.push({'url':'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/images/m'+i+'.png','height':sizes[i-1],'width':sizes[i-1]});}
if(typeof opt_opts==='object'&&opt_opts!==null){if(typeof opt_opts.gridSize==='number'&&opt_opts.gridSize>0){gridSize_=opt_opts.gridSize;}
if(typeof opt_opts.maxZoom==='number'){maxZoom_=opt_opts.maxZoom;}
if(typeof opt_opts.styles==='object'&&opt_opts.styles!==null&&opt_opts.styles.length!==0){styles_=opt_opts.styles;}
if(typeof opt_opts.calculator==='function'){calculator_=opt_opts.calculator;}
if(typeof opt_opts.zoomOnClick==='boolean'){zoomOnClick_=opt_opts.zoomOnClick;}}
this.setCalculator=function(calculator){calculator_=calculator;};this.getCalculator=function(){return GEvent.callback(this,calculator_);};this.isZoomOnClick=function(){return zoomOnClick_;};function addLeftMarkers_(){if(leftMarkers_.length===0){return;}
var leftMarkers=[];for(i=0;i<leftMarkers_.length;++i){if(isMarkerInViewport_(leftMarkers_[i])){me_.addMarker(leftMarkers_[i],true,null,null,true);}else{leftMarkers.push(leftMarkers_[i]);}}
leftMarkers_=leftMarkers;}
this.getStyles=function(){return styles_;};this.clearMarkers=function(){for(var i=0;i<clusters_.length;++i){if(typeof clusters_[i]!=="undefined"&&clusters_[i]!==null){clusters_[i].clearMarkers();}}
clusters_=[];leftMarkers_=[];};function isMarkerInViewport_(marker){return map_.getBounds().containsLatLng(marker.getLatLng());}
function reAddMarkers_(markers){var len=markers.length;var clusters=[];for(var i=len-1;i>=0;--i){me_.addMarker(markers[i].marker,true,markers[i].isAdded,clusters,true);}
addLeftMarkers_();}
this.addMarker=function(marker,opt_isNodraw,opt_isAdded,opt_clusters,opt_isNoCheck){if(opt_isNoCheck!==true){if(!isMarkerInViewport_(marker)){leftMarkers_.push(marker);return;}}
var isAdded=opt_isAdded;var clusters=opt_clusters;var pos=map_.fromLatLngToDivPixel(marker.getLatLng());if(typeof isAdded!=="boolean"){isAdded=false;}
if(typeof clusters!=="object"||clusters===null){clusters=clusters_;}
var length=clusters.length;var cluster=null;for(var i=length-1;i>=0;i--){cluster=clusters[i];var center=cluster.getCenter();if(center===null){continue;}
center=map_.fromLatLngToDivPixel(center);if(pos.x>=center.x-gridSize_&&pos.x<=center.x+gridSize_&&pos.y>=center.y-gridSize_&&pos.y<=center.y+gridSize_){cluster.addMarker({'isAdded':isAdded,'marker':marker});if(!opt_isNodraw){cluster.redraw_();}
return;}}
cluster=new Cluster(this,map);cluster.addMarker({'isAdded':isAdded,'marker':marker});if(!opt_isNodraw){cluster.redraw_();}
clusters.push(cluster);if(clusters!==clusters_){clusters_.push(cluster);}};this.removeMarker=function(marker){for(var i=0;i<clusters_.length;++i){if(clusters_[i]&&clusters_[i].removeMarker(marker)){clusters_[i].redraw_();return;}}
for(var i=0;i<leftMarkers_.length;++i){if(leftMarkers_[i]===marker){leftMarkers_.splice(i,1);return;}}};this.redraw_=function(){var clusters=this.getClustersInViewport_();for(var i=0;i<clusters.length;++i){clusters[i].redraw_(true);}};this.getClustersInViewport_=function(){var clusters=[];var curBounds=map_.getBounds();for(var i=0;i<clusters_.length;i++){if(clusters_[i].isInBounds(curBounds)){clusters.push(clusters_[i]);}}
return clusters;};this.getMaxZoom_=function(){return maxZoom_;};this.getMap_=function(){return map_;};this.getGridSize_=function(){return gridSize_;};this.getTotalMarkers=function(){var result=0;for(var i=0;i<clusters_.length;++i){result+=clusters_[i].getTotalMarkers();}
return result;};this.getTotalClusters=function(){return clusters_.length;};this.resetViewport=function(){var clusters=this.getClustersInViewport_();var tmpMarkers=[];var removed=0;for(var i=0;i<clusters.length;++i){var cluster=clusters[i];var oldZoom=cluster.getCurrentZoom();if(oldZoom===null){continue;}
var curZoom=map_.getZoom();if(curZoom!==oldZoom){var mks=cluster.getMarkers();for(var j=0;j<mks.length;++j){var newMarker={'isAdded':false,'marker':mks[j].marker};tmpMarkers.push(newMarker);}
cluster.clearMarkers();removed++;for(j=0;j<clusters_.length;++j){if(cluster===clusters_[j]){clusters_.splice(j,1);}}}}
reAddMarkers_(tmpMarkers);this.redraw_();};this.addMarkers=function(markers){for(var i=0;i<markers.length;++i){this.addMarker(markers[i],true);}
this.redraw_();};this.getParentCluster=function(marker){return marker.parentCluster_;};if(typeof opt_markers==="object"&&opt_markers!==null){this.addMarkers(opt_markers);}
mcfn_=GEvent.addListener(map_,"moveend",function(){me_.resetViewport();});}
function Cluster(markerClusterer){var center_=null;var markers_=[];var markerClusterer_=markerClusterer;var map_=markerClusterer.getMap_();var clusterMarker_=null;var zoom_=map_.getZoom();var this_=this;this.getMarkers=function(){return markers_;};this.getMarkerClusterer=function(){return markerClusterer_;};this.isInBounds=function(bounds){if(center_===null){return false;}
if(!bounds){bounds=map_.getBounds();}
var sw=map_.fromLatLngToDivPixel(bounds.getSouthWest());var ne=map_.fromLatLngToDivPixel(bounds.getNorthEast());var centerxy=map_.fromLatLngToDivPixel(center_);var inViewport=true;var gridSize=markerClusterer.getGridSize_();if(zoom_!==map_.getZoom()){var dl=map_.getZoom()-zoom_;gridSize=Math.pow(2,dl)*gridSize;}
if(ne.x!==sw.x&&(centerxy.x+gridSize<sw.x||centerxy.x-gridSize>ne.x)){inViewport=false;}
if(inViewport&&(centerxy.y+gridSize<ne.y||centerxy.y-gridSize>sw.y)){inViewport=false;}
return inViewport;};this.getCenter=function(){return center_;};this.addMarker=function(marker){if(center_===null){center_=marker.marker.getLatLng();}
marker.marker.parentCluster_=this_;markers_.push(marker);};this.removeMarker=function(marker){for(var i=0;i<markers_.length;++i){if(marker===markers_[i].marker){if(markers_[i].isAdded){map_.removeOverlay(markers_[i].marker);}
delete markers_[i].marker.parentCluster_;markers_.splice(i,1);return true;}}
return false;};this.getCurrentZoom=function(){return zoom_;};this.redraw_=function(isForce){if(!isForce&&!this.isInBounds()){return;}
zoom_=map_.getZoom();var i=0;var mz=markerClusterer.getMaxZoom_();if(mz===null){mz=map_.getCurrentMapType().getMaximumResolution();}
if(zoom_>mz||this.getTotalMarkers()<=1){for(i=0;i<markers_.length;++i){if(markers_[i].isAdded){if(markers_[i].marker.isHidden()){markers_[i].marker.show();}}else{map_.addOverlay(markers_[i].marker);markers_[i].isAdded=true;}}
if(clusterMarker_!==null){clusterMarker_.hide();}}else if(this.getTotalMarkers()>1){for(i=0;i<markers_.length;++i){if(markers_[i].isAdded&&(!markers_[i].marker.isHidden())){markers_[i].marker.hide();}}
var sums=markerClusterer_.getCalculator()(this.getRealMarkers());if(clusterMarker_===null){clusterMarker_=new ClusterMarker_(center_,sums,markerClusterer_.getStyles(),markerClusterer_.getGridSize_(),this_);map_.addOverlay(clusterMarker_);}else{if(clusterMarker_.isHidden()){clusterMarker_.show();}
clusterMarker_.setSums(sums);clusterMarker_.redraw(true);}}};this.clearMarkers=function(){if(clusterMarker_!==null){map_.removeOverlay(clusterMarker_);}
for(var i=0;i<markers_.length;++i){if(markers_[i].isAdded){map_.removeOverlay(markers_[i].marker);}
delete markers_[i].marker.parentCluster_;}
markers_=[];};this.getTotalMarkers=function(){return markers_.length;};this.getRealMarkers=function(){var result=[];for(var i=0;i<markers_.length;++i){result.push(markers_[i].marker);}
return result;};}
function ClusterMarker_(latlng,sums,styles,padding,cluster){var index=sums.index;this.useStyle(styles[index-1]);this.styleDirty_=false;this.latlng_=latlng;this.index_=index;this.styles_=styles;this.text_=sums.text;this.padding_=padding;this.sums_=sums;this.cluster_=cluster;}
ClusterMarker_.prototype=new GOverlay();ClusterMarker_.prototype.useStyle=function(style){this.url_=style.url;this.height_=style.height;this.width_=style.width;this.textColor_=style.opt_textColor;this.anchor_=style.opt_anchor;this.textSize_=style.opt_textSize;};ClusterMarker_.prototype.initialize=function(map){this.map_=map;var div=document.createElement("div");var latlng=this.latlng_;var pos=this.getPosFromLatLng(latlng);div.style.cssText=this.createCss(pos);div.innerHTML=this.text_;map.getPane(G_MAP_MARKER_SHADOW_PANE).appendChild(div);var padding=this.padding_;var cluster=this.cluster_;GEvent.addDomListener(div,"click",function(){GEvent.trigger(cluster.getMarkerClusterer(),"clusterclick",cluster);if(cluster.getMarkerClusterer().isZoomOnClick()){var pos=map.fromLatLngToDivPixel(latlng);var sw=new GPoint(pos.x-padding,pos.y+padding);sw=map.fromDivPixelToLatLng(sw);var ne=new GPoint(pos.x+padding,pos.y-padding);ne=map.fromDivPixelToLatLng(ne);var zoom=map.getBoundsZoomLevel(new GLatLngBounds(sw,ne),map.getSize());map.setCenter(latlng,zoom);}});this.div_=div;};ClusterMarker_.prototype.getPosFromLatLng=function(latlng){var pos=this.map_.fromLatLngToDivPixel(latlng);pos.x-=parseInt(this.width_/2,10);pos.y-=parseInt(this.height_/2,10);return pos;};ClusterMarker_.prototype.createCss=function(pos){var mstyle="";if(document.all){mstyle='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="'+this.url_+'");';}else{mstyle="background:url("+this.url_+");";}
if(typeof this.anchor_==="object"){if(typeof this.anchor_[0]==="number"&&this.anchor_[0]>0&&this.anchor_[0]<this.height_){mstyle+='height:'+(this.height_-this.anchor_[0])+'px;padding-top:'+this.anchor_[0]+'px;';}else{mstyle+='height:'+this.height_+'px;line-height:'+this.height_+'px;';}
if(typeof this.anchor_[1]==="number"&&this.anchor_[1]>0&&this.anchor_[1]<this.width_){mstyle+='width:'+(this.width_-this.anchor_[1])+'px;padding-left:'+this.anchor_[1]+'px;';}else{mstyle+='width:'+this.width_+'px;text-align:center;';}}else{mstyle+='height:'+this.height_+'px;line-height:'+this.height_+'px;';mstyle+='width:'+this.width_+'px;text-align:center;';}
var txtColor=this.textColor_?this.textColor_:'black';var txtSize=this.textSize_?this.textSize_:11;return mstyle+'cursor:pointer;top:'+pos.y+"px;left:"+
pos.x+"px;color:"+txtColor+";position:absolute;font-size:"+txtSize+"px;"+'font-family:Arial,sans-serif;font-weight:bold';};ClusterMarker_.prototype.remove=function(){this.div_.parentNode.removeChild(this.div_);};ClusterMarker_.prototype.copy=function(){return new ClusterMarker_(this.latlng_,this.sums_,this.text_,this.styles_,this.padding_,this.cluster_);};ClusterMarker_.prototype.redraw=function(force){if(!force){return;}
var pos=this.getPosFromLatLng(this.latlng_);if(this.styleDirty_){this.styleDirty_=false;this.useStyle(this.styles_[this.index_-1]);this.div_.style.cssText=this.createCss(pos);}else{this.div_.style.top=pos.y+"px";this.div_.style.left=pos.x+"px";}};ClusterMarker_.prototype.hide=function(){this.div_.style.display="none";};ClusterMarker_.prototype.show=function(){this.div_.style.display="";};ClusterMarker_.prototype.isHidden=function(){return this.div_.style.display==="none";};ClusterMarker_.prototype.setSums=function(sums){if(sums.index!==this.index_){this.styleDirty_=true;}
this.sums_=sums;this.text_=sums.text;this.index_=sums.index;this.div_.innerHTML=sums.text;};var _mSvgForced=true;var _mSvgEnabled=true;var arrowMarkerCounter;function BDCCArrow(point,rotation,color,opacity,tooltip){this.point_=point;this.rotation_=rotation;var r=rotation+270;this.dx_=20*Math.cos(r*Math.PI/180);this.dy_=20*Math.sin(r*Math.PI/180);this.color_=color||"#888888";this.opacity_=opacity||0.5;this.tooltip_=tooltip;if(arrowMarkerCounter==null)
arrowMarkerCounter=0;else
arrowMarkerCounter+=1;this.svgId_="BDCCArrow"+arrowMarkerCounter.toString();}
BDCCArrow.prototype=new GOverlay();BDCCArrow.prototype.getPoint=function(){return this.point_;}
BDCCArrow.prototype.getTooltip=function(){return this.tooltip_;}
BDCCArrow.prototype.clicked=function(){GEvent.trigger(this,"click");}
BDCCArrow.prototype.initialize=function(map){var div=document.createElement("DIV");map.getPane(G_MAP_MARKER_SHADOW_PANE).appendChild(div);this.map_=map;this.div_=div;if(navigator.userAgent.indexOf("MSIE")!=-1){var l=document.createElement("v:line");l.strokeweight="2px";l.strokecolor=this.color_;var s=document.createElement("v:stroke");s.opacity=this.opacity_;s.endcap="round";l.appendChild(s);var shadow=document.createElement("v:shadow");shadow.on=true;shadow.color="#888888";shadow.offset="1px, 1px";l.appendChild(shadow);this.div_.appendChild(l);this.vmlLine_=l;}
else{var svgNS="http://www.w3.org/2000/svg";var svgRoot=document.createElementNS(svgNS,"svg");svgRoot.setAttribute("width",50);svgRoot.setAttribute("height",50);svgRoot.setAttribute("stroke",this.color_);svgRoot.setAttribute("fill",this.color_);svgRoot.setAttribute("stroke-opacity",this.opacity_);svgRoot.setAttribute("fill-opacity",this.opacity_);this.div_.appendChild(svgRoot);var svgNode=document.createElementNS(svgNS,"line");svgNode.setAttribute("stroke","#888888");svgNode.setAttribute("stroke-width",2);svgNode.setAttribute("stroke-linecap","round");svgNode.setAttribute("x1",26+this.dx_);svgNode.setAttribute("y1",26+this.dy_);svgNode.setAttribute("x2",26);svgNode.setAttribute("y2",26);svgRoot.appendChild(svgNode);svgNode=document.createElementNS(svgNS,"line");svgNode.setAttribute("stroke-width",2);svgNode.setAttribute("stroke-linecap","round");svgNode.setAttribute("x1",25+this.dx_);svgNode.setAttribute("y1",25+this.dy_);svgNode.setAttribute("x2",25);svgNode.setAttribute("y2",25);svgRoot.appendChild(svgNode);this.svgRoot_=svgRoot;}}
BDCCArrow.prototype.hide=function(){navigator.userAgent.indexOf("MSIE")!=-1?this.vmlLine_.style.visibility="hidden":this.div_.hide();}
BDCCArrow.prototype.show=function(){navigator.userAgent.indexOf("MSIE")!=-1?this.vmlLine_.style.visibility="visible":this.div_.show();}
BDCCArrow.prototype.remove=function(){this.div_.parentNode.removeChild(this.div_);}
BDCCArrow.prototype.copy=function(){return new BDCCArrow(this.point_,this.rotation_,this.color_,this.opacity_,this.tooltip_);}
BDCCArrow.prototype.redraw=function(force){if(!force)
return;var p=this.map_.fromLatLngToDivPixel(this.point_);var x2=p.x+this.dx_;var y2=p.y+this.dy_;if(navigator.userAgent.indexOf("MSIE")!=-1){this.vmlLine_.from=x2+"px, "+y2+"px";this.vmlLine_.to=p.x+"px, "+p.y+"px";}
else{this.svgRoot_.setAttribute("style","position:absolute; top:"+(p.y-25)+"px; left:"+(p.x-25)+"px");}}
if(typeof(Control)=='undefined')
Control={};var $proc=function(proc){return typeof(proc)=='function'?proc:function(){return proc};};var $value=function(value){return typeof(value)=='function'?value():value;};Object.Event={extend:function(object){object._objectEventSetup=function(event_name){this._observers=this._observers||{};this._observers[event_name]=this._observers[event_name]||[];};object.observe=function(event_name,observer){if(typeof(event_name)=='string'&&typeof(observer)!='undefined'){this._objectEventSetup(event_name);if(!this._observers[event_name].include(observer))
this._observers[event_name].push(observer);}else
for(var e in event_name)
this.observe(e,event_name[e]);};object.stopObserving=function(event_name,observer){this._objectEventSetup(event_name);if(event_name&&observer)
this._observers[event_name]=this._observers[event_name].without(observer);else if(event_name)
this._observers[event_name]=[];else
this._observers={};};object.observeOnce=function(event_name,outer_observer){var inner_observer=function(){outer_observer.apply(this,arguments);this.stopObserving(event_name,inner_observer);}.bind(this);this._objectEventSetup(event_name);this._observers[event_name].push(inner_observer);};object.notify=function(event_name){this._objectEventSetup(event_name);var collected_return_values=[];var args=$A(arguments).slice(1);try{for(var i=0;i<this._observers[event_name].length;++i)
collected_return_values.push(this._observers[event_name][i].apply(this._observers[event_name][i],args)||null);}catch(e){if(e==$break)
return false;else
throw e;}
return collected_return_values;};if(object.prototype){object.prototype._objectEventSetup=object._objectEventSetup;object.prototype.observe=object.observe;object.prototype.stopObserving=object.stopObserving;object.prototype.observeOnce=object.observeOnce;object.prototype.notify=function(event_name){if(object.notify){var args=$A(arguments).slice(1);args.unshift(this);args.unshift(event_name);object.notify.apply(object,args);}
this._objectEventSetup(event_name);var args=$A(arguments).slice(1);var collected_return_values=[];try{if(this.options&&this.options[event_name]&&typeof(this.options[event_name])=='function')
collected_return_values.push(this.options[event_name].apply(this,args)||null);for(var i=0;i<this._observers[event_name].length;++i)
collected_return_values.push(this._observers[event_name][i].apply(this._observers[event_name][i],args)||null);}catch(e){if(e==$break)
return false;else
throw e;}
return collected_return_values;};}}};Element.addMethods({observeOnce:function(element,event_name,outer_callback){var inner_callback=function(){outer_callback.apply(this,arguments);Element.stopObserving(element,event_name,inner_callback);};Element.observe(element,event_name,inner_callback);}});(function(){function wheel(event){var delta,element,custom_event;if(event.wheelDelta){delta=event.wheelDelta/120;}else if(event.detail){delta=-event.detail/3;}
if(!delta){return;}
element=Event.extend(event).target;element=Element.extend(element.nodeType===Node.TEXT_NODE?element.parentNode:element);custom_event=element.fire('mouse:wheel',{delta:delta});if(custom_event.stopped){Event.stop(event);return false;}}
document.observe('mousewheel',wheel);document.observe('DOMMouseScroll',wheel);})();var IframeShim=Class.create({initialize:function(){this.element=new Element('iframe',{style:'position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);display:none',src:'javascript:void(0);',frameborder:0});$(document.body).insert(this.element);},hide:function(){this.element.hide();return this;},show:function(){this.element.show();return this;},positionUnder:function(element){var element=$(element);var offset=element.cumulativeOffset();var dimensions=element.getDimensions();this.element.setStyle({left:offset[0]+'px',top:offset[1]+'px',width:dimensions.width+'px',height:dimensions.height+'px',zIndex:element.getStyle('zIndex')-1}).show();return this;},setBounds:function(bounds){for(prop in bounds)
bounds[prop]+='px';this.element.setStyle(bounds);return this;},destroy:function(){if(this.element)
this.element.remove();return this;}});if(typeof(Prototype)=="undefined")
throw"Control.ScrollBar requires Prototype to be loaded.";if(typeof(Control.Slider)=="undefined")
throw"Control.ScrollBar requires Control.Slider to be loaded.";if(typeof(Object.Event)=="undefined")
throw"Control.ScrollBar requires Object.Event to be loaded.";Control.ScrollBar=Class.create({initialize:function(element,options){this.enabled=false;this.notificationTimeout=false;element.addClassName('scrollbar');this.container=new Element('div',{'class':'scrollbar_content'});element.childElements().each(function(e){this.container.appendChild(e)}.bind(this));element.insert(this.container);this.track=new Element('div',{'class':'scrollbar_track'});element.insert({top:this.track});this.handle=new Element('div',{'class':'scrollbar_handle'});this.track.insert(this.handle);this.boundMouseWheelEvent=this.onMouseWheel.bindAsEventListener(this);this.boundResizeObserver=this.onWindowResize.bind(this);this.options=Object.extend({active_class_name:'scrolling',apply_active_class_name_to:this.container,notification_timeout_length:125,handle_minimum_height:25,scroll_to_smoothing:0.01,scroll_to_steps:15,proportional:true,slider_options:{}},options||{});this.slider=new Control.Slider(this.handle,this.track,Object.extend({axis:'vertical',onSlide:this.onChange.bind(this),onChange:this.onChange.bind(this)},this.options.slider_options));this.recalculateLayout();Event.observe(window,'resize',this.boundResizeObserver);this.handle.observe('mousedown',function(){if(this.auto_sliding_executer)
this.auto_sliding_executer.stop();}.bind(this));},destroy:function(){Event.stopObserving(window,'resize',this.boundResizeObserver);},enable:function(){this.enabled=true;this.container.observe('mouse:wheel',this.boundMouseWheelEvent);this.slider.setEnabled();this.track.show();if(this.options.active_class_name)
$(this.options.apply_active_class_name_to).addClassName(this.options.active_class_name);this.notify('enabled');},disable:function(){this.enabled=false;this.container.stopObserving('mouse:wheel',this.boundMouseWheelEvent);this.slider.setDisabled();this.track.hide();if(this.options.active_class_name)
$(this.options.apply_active_class_name_to).removeClassName(this.options.active_class_name);this.notify('disabled');this.reset();},reset:function(){this.slider.setValue(0);},recalculateLayout:function(){if(this.container.scrollHeight<=this.container.offsetHeight)
this.disable();else{this.enable();this.slider.trackLength=this.slider.maximumOffset()-this.slider.minimumOffset();if(this.options.proportional){this.handle.style.height=Math.max(this.container.offsetHeight*(this.container.offsetHeight/this.container.scrollHeight),this.options.handle_minimum_height)+'px';this.slider.handleLength=this.handle.style.height.replace(/px/,'');}}},onWindowResize:function(){this.recalculateLayout();this.scrollBy(0);},onMouseWheel:function(event){if(this.auto_sliding_executer)
this.auto_sliding_executer.stop();this.slider.setValueBy(-(event.memo.delta/20));event.stop();return false;},onChange:function(value){this.container.scrollTop=Math.round(value/this.slider.maximum*(this.container.scrollHeight-this.container.offsetHeight));if(this.notification_timeout)
window.clearTimeout(this.notificationTimeout);this.notificationTimeout=window.setTimeout(function(){this.notify('change',value);}.bind(this),this.options.notification_timeout_length);},getCurrentMaximumDelta:function(){return this.slider.maximum*(this.container.scrollHeight-this.container.offsetHeight);},getDeltaToElement:function(element){return this.slider.maximum*((element.positionedOffset().top+(element.getHeight()/2))-(this.container.getHeight()/2));},scrollTo:function(y,animate){var current_maximum_delta=this.getCurrentMaximumDelta();if(y=='top')
y=0;else if(y=='bottom')
y=current_maximum_delta;else if(typeof(y)!="number")
y=this.getDeltaToElement($(y));if(this.enabled){y=Math.max(0,Math.min(y,current_maximum_delta));if(this.auto_sliding_executer)
this.auto_sliding_executer.stop();var target_value=y/current_maximum_delta;var original_slider_value=this.slider.value;var delta=(target_value-original_slider_value)*current_maximum_delta;if(animate){this.auto_sliding_executer=new PeriodicalExecuter(function(){if(Math.round(this.slider.value*100)/100<Math.round(target_value*100)/100||Math.round(this.slider.value*100)/100>Math.round(target_value*100)/100){this.scrollBy(delta/this.options.scroll_to_steps);}else{this.auto_sliding_executer.stop();this.auto_sliding_executer=null;if(typeof(animate)=="function")
animate();}}.bind(this),this.options.scroll_to_smoothing);}else
this.scrollBy(delta);}else if(typeof(animate)=="function")
animate();},scrollBy:function(y){if(!this.enabled)
return false;this.slider.setValueBy(y/this.getCurrentMaximumDelta());}});Object.Event.extend(Control.ScrollBar);var FOCUS_ZOOM_LEVEL=17;var mouse=null;var WallMap=Class.create({MARKERS_PATH:"/images/icons/map/markers/",LOCATION_HASH_FIELDS:["type","center","zoom","sidebar","infobox","hidden"],locationHashString:document.location.hash,locationHash:{},map:null,mapContainer:null,mapLoader:null,objects:[],mapStyles:null,legendItems:null,areas:null,legend:null,help:null,toolTip:null,infobox:null,markers:[],clusterer:null,imageIndex:0,callbackHandle:null,mapClickHandle:null,focusOverlay:null,initialize:function(map,mapStyles,legendItems,areas,helpText){this.map=map;this.mapContainer=$("map_container");this.mapContainer.fullWidth=this.mapContainer.getWidth();this.mapLoader=$("map_loader")||new Element("div");this.help={text:helpText};this.toolTip=new ToolTip();this.initializeAreas(areas);this.initializeMapStyles(mapStyles);this.initializeLegend(legendItems);this.initializeClusterer();var mapLoaded=function(){this.initializeMap();this.initializeLocationListener();}.bind(this);this.map.isLoaded()?mapLoaded():GEvent.addListener(this.map,"load",mapLoaded);},initializeMap:function(){this.setMapType();GEvent.addListener(this.map,"maptypechanged",this.mapTypeChanged.bind(this));GEvent.addListener(this.map,"moveend",this.moveend.bind(this));GEvent.addListener(this.map,"zoomend",this.zoomend.bind(this));this.setMapClickListener();$("map").observe("mousemove",function(event){mouse={x:event.clientX-$("map").viewportOffset().left,y:event.clientY-$("map").viewportOffset().top};}.bind(this));$("map").observe("mouseleave",this.hideToolTip.bind(this));},initializeMapStyles:function(mapStyles){this.mapStyles=$H(mapStyles);this.mapStyles.values().each(function(mapStyle){mapStyle.currentLevel=this.getMapStyleLevel(mapStyle);}.bind(this));},initializeLegend:function(legendItems){this.legendItems=$H(legendItems);this.legendItems.values().each(function(legendItem){legendItem.mapStyle=this.mapStyles.get(legendItem.map_style_id);}.bind(this));this.legendItems.type="legend";},initializeAreas:function(areas){this.areas=areas||{};this.areas.type="areas";},initializeClusterer:function(){this.clusterer=new MarkerClusterer(this.map,[],{gridSize:50,maxZoom:14,styles:[{width:53,height:52,url:"/images/icons/map/markers/cluster_1.png",opt_textColor:"#fff"},{width:56,height:55,url:"/images/icons/map/markers/cluster_2.png",opt_textColor:"#fff"},{width:66,height:65,url:"/images/icons/map/markers/cluster_3.png",opt_textColor:"#fff"}]});},initializeLocationListener:function(){this.restoreAppState();setInterval(this.locationListener.bind(this),100);},locationListener:function(){if(document.location.hash!=this.locationHashString){this.locationHashString=document.location.hash;this.restoreAppState();}},restoreAppState:function(){var hash=this.locationHashString.substr(1).toQueryParams();var changed=$H(hash).any(function(pair){return this.LOCATION_HASH_FIELDS.include(pair[0])&&pair[1]!=this.locationHash[pair[0]];}.bind(this));this.locationHash=hash;if(changed||!this.locationHash.center){this.withoutUpdate(function(){this.restoreSidebar();this.restoreMapState();this.restoreInfobox();this.restoreLegendItemVisibility();}.bind(this));this.update(true);this.updateLocationHash();}},restoreSidebar:function(){if(this.locationHash.sidebar){var pair=this.locationHash.sidebar.split(":");var id=pair.length>1?parseInt(pair.last()):null;this.showSidebar(pair.first(),id,true,true);}
else{this.hideSidebar(null,true);}},restoreMapState:function(){var centerChanged=this.locationHash.center&&this.locationHash.center!==this.map.getCenter().toString();var zoomChanged=this.locationHash.zoom&&parseInt(this.locationHash.zoom)!==this.map.getZoom();var mapTypeChanged=this.locationHash.type&&this.locationHash.type!==this.getMapTypeName();if(!centerChanged&&!zoomChanged&&!mapTypeChanged)return;if(centerChanged){var center=this.locationHash.center.split(",").toGLatLng();if(zoomChanged){this.map.setCenter(center,parseInt(this.locationHash.zoom));}
else{this.map.setCenter(center);}}
else if(zoomChanged){this.map.setZoom(parseInt(this.locationHash.zoom));}
if(mapTypeChanged){this.setMapType(this.locationHash.type);}},restoreInfobox:function(){if(this.locationHash.infobox){var pair=this.locationHash.infobox.split(":");this.showObject(pair.first(),parseInt(pair.last()),true,true);}
else{this.hideInfobox(true);}},restoreLegendItemVisibility:function(){var ids=this.locationHash.hidden?this.locationHash.hidden.split(",").collect(function(id){return parseInt(id)}):[];this.legendItems.each(function(li){if(ids.include(li.first())!=Boolean(li.last().hidden)){this.toggleLegendItem(li.first());}}.bind(this));},moveend:function(){this.updateLocationHash();this.update();},zoomend:function(oldLevel,newLevel){if(oldLevel!=newLevel){this.resetViewport();}},mapTypeChanged:function(){this.setMapTypeCookie();this.updateLocationHash();},updateLocationHash:function(){if(this.skipUpdate)return;var hash=this.getCleanLocationHash();hash.center=this.map.getCenter().toString();hash.zoom=this.map.getZoom();if(this.infobox&&this.infobox.object.id){hash.infobox=this.infobox.object.type+":"+this.infobox.object.id;}
if(this.sidebar){hash.sidebar=[this.sidebar.type,this.sidebar.objectId()].compact().join(":");}
var hidden=this.legendItems.values().select(function(li){return li.hidden});if(hidden.length>0){hash.hidden=hidden.pluck("id").join(",");}
hash.type=this.getMapTypeName();this.locationHash=hash;this.locationHashString="#"+$H(this.locationHash).toUnescapedQueryString();document.location.hash=this.locationHashString;},update:function(resetViewport){if(this.skipUpdate)return;this.mapLoader.setOpacity(0.9).show();this.toolTip.hide(true);this.refresh(resetViewport);if(this.request){this.request.transport.abort();}
this.request=new Ajax.Request("/map/within_bounds",{asynchronous:true,parameters:$H(this.getUpdateParams()).toQueryString(),onSuccess:function(transport){var response=transport.responseText.evalJSON();this.addObjects(response.images,"image");this.addObjects(response.items,"item");this.addObjects(response.areas,"area");this.addMarkers();this.request=null;this.mapLoader.fade({duration:0.3});}.bind(this)});},withoutUpdate:function(func){this.skipUpdate=true;func();this.skipUpdate=false;},refresh:function(resetViewport){this.removeOutOfBoundsObjects();this.updateObjectsWithMinZoom();this.updateObjectsWithChangedMapStyles();if(resetViewport){this.resetViewport();}},updateObjectsWithMinZoom:function(){var zoom=this.map.getZoom();this.getObjectsWithMinZoom().each(function(object){if(object.legendItems.all(function(li){return li.mapStyle.minZoom>zoom})){this.removeObject(object);}
else if((object.geodata_for_map.minZoom<=zoom&&!object.minZoomReached)||(object.geodata_for_map.minZoom>zoom&&object.minZoomReached)||object.overlays.any(function(overlay){return((overlay instanceof GPolygon)&&overlay.minLineZoom<=zoom)||((overlay instanceof GPolyline)&&overlay.minLineZoom>zoom);})){this.removeOverlays(object);this.addGeometries(object);}}.bind(this));this.addMarkers();},updateObjectsWithChangedMapStyles:function(){var changed=this.mapStyles.values().inject([],function(result,mapStyle){var newLevel=this.getMapStyleLevel(mapStyle);if(mapStyle.currentLevel!=newLevel){mapStyle.currentLevel=newLevel;result.push(mapStyle);}
return result;}.bind(this));this.getObjectsByMapStyles(changed).each(function(object){object.overlays.select(function(overlay){return!(overlay instanceof GMarker);}).each(function(overlay){var config=object.legendItems.last().mapStyle.currentLevel[overlay instanceof GPolyline?"line":"polygon"];overlay.setStrokeStyle({weight:config.strokeWeight,opacity:config.strokeOpacity});if(overlay instanceof GPolygon){overlay.setFillStyle({opacity:config.fillOpacity});}});});},resetViewport:function(){if(this.clusterer){this.clusterer.resetViewport();}},addObjects:function(objects,type,isDetailed){objects.each(function(object){this.addObject(object,type,isDetailed);}.bind(this));},addObject:function(object,type,isDetailed){object.type=type;object.legendItems=[];object.legend_item_ids.each(function(id){object.legendItems.push(this.legendItems.get(id));}.bind(this));object.isDetailed=isDetailed?true:false;object.overlays=[];this.addGeometries(object);this.objects.push(object);},removeObject:function(object){this.removeOverlays(object);this.objects.splice(this.objects.indexOf(object),1);},removeOutOfBoundsObjects:function(){this.getOutOfBoundsObjects().each(function(object){this.removeObject(object);}.bind(this));},getObject:function(type,id){return this.objects.find(function(o){return o.type===type&&o.id===id;});},fetchObject:function(type,id,noDetails){var object=this.getObject(type,id);if(!object||(!noDetails&&!object.isDetailed)){new Ajax.Request("/"+type+"s/"+id,{method:"get",asynchronous:false,onSuccess:function(transport){var response=transport.responseText.evalJSON();if(!object){object=response;this.addObject(object,type,true);this.addMarkers();}
else{Object.extend(object,response);object.isDetailed=true;}}.bind(this)});}
return object;},getObjectsByType:function(type){return this.objects.select(function(object){return object.type===type;});},getObjectsByLegendItem:function(legendItem){return this.objects.select(function(object){return object.legend_item_ids.include(legendItem.id);});},getObjectsByMapStyles:function(mapStyles){var ids=mapStyles.pluck("id");return this.objects.select(function(object){return object.legendItems.pluck("map_style_id").any(function(id){return ids.include(id);});});},getObjectsWithMinZoom:function(){return this.objects.select(function(object){return object.geodata_for_map.minZoom||object.legendItems.any(function(li){return li.mapStyle.minZoom})||object.overlays.any(function(overlay){return overlay.minLineZoom});});},getOutOfBoundsObjects:function(){var bounds=this.map.getBounds();return this.objects.select(function(object){return object.overlays.select(function(overlay){return((overlay instanceof GMarker)||(overlay instanceof GPolyline))||(overlay instanceof GPolygon);}).all(function(overlay){if(overlay instanceof GMarker){return!bounds.containsLatLng(overlay.getLatLng());}
else{return!bounds.intersects(overlay.getBounds());}});});},getHelpObject:function(){return this.help},getLegendObject:function(){return this.legendItems},getAreasObject:function(){return this.areas},getLegendItemObject:function(id){return this.legendItems.get(id)},getAreaObject:function(id){return this.fetchObject("area",id)},addGeometries:function(object){if(object.geodata_for_map.minZoom>this.map.getZoom()&&!object.legendItems.any(function(li){return!li.mapStyle.marker})){object.minZoomReached=false;this.addGeometry(object,object.geodata_for_map.center);}
else{object.minZoomReached=true;object.geodata_for_map.geodata.each(function(geometry){this.addGeometry(object,geometry);}.bind(this));}},addGeometry:function(object,geometry){var type=null,options={};var geometryForMap=geometry;if(Object.isArray(geometry)&&Object.isNumber(geometry.first())){geometryForMap=new GLatLng(geometry[0],geometry[1]);}
if(geometryForMap instanceof GLatLng){type="marker";}
else{options.center=geometry.center;geometryForMap=geometry.encoded;if(Object.isArray(geometryForMap)){type=geometry.minLineZoom<=this.map.getZoom()?"line":"polygon";geometryForMap=geometryForMap.first();options.minLineZoom=geometry.minLineZoom;}
else{type="line";}}
var overlay=this["create"+type.capitalize()](geometryForMap,object.legendItems,options);Object.extend(overlay,options);this.addOverlay(object,overlay);if(overlay instanceof GMarker&&object.legendItems.any(function(li){return li.mapStyle.marker.angle})&&Object.isNumber(object.angle)){var arrow=new BDCCArrow(overlay.getPoint(),object.angle,"#FFFFFF",1);this.addOverlay(object,arrow);}},addOverlay:function(object,overlay,noListeners){var hidden=object.legendItems.all(function(li){return li.hidden});overlay.object=object;object.overlays.push(overlay);if(overlay instanceof GMarker&&!hidden&&!object.legendItems.any(function(li){return li.mapStyle.noCluster})){this.markers.push(overlay);}
else{this.map.addOverlay(overlay);}
if(hidden){overlay.hide();}
if(object.legendItems.any(function(li){return li.mapStyle.marker})&&!object.legendItems.any(function(li){return!li.mapStyle.marker})&&((overlay instanceof GPolyline)||(overlay instanceof GPolygon))){this.addGeometry(object,overlay.center);}
if(!noListeners){GEvent.addListener(overlay,"mouseover",this.showToolTip.bind(this,object));GEvent.addListener(overlay,"mouseout",this.hideToolTip.bind(this));}},removeOverlays:function(object){object.overlays.each(function(overlay){this.removeOverlay(object,overlay,true);}.bind(this));object.overlays=[];},removeOverlay:function(object,overlay,dontRemoveFromObject){GEvent.clearInstanceListeners(overlay);this.map.removeOverlay(overlay);if(overlay instanceof GMarker&&!object.legendItems.any(function(li){return li.mapStyle.noCluster})){this.clusterer.removeMarker(overlay);}
if(!dontRemoveFromObject){object.overlays.splice(object.overlays.indexOf(overlay),1);}},addMarkers:function(){if(this.markers.length>0){this.clusterer.addMarkers(this.markers);this.markers=[];}},createMarker:function(point,legendItems){var config=legendItems.last().mapStyle.marker;var markerId=legendItems.pluck("id").join("_");var icon=new GIcon();icon.image=this.MARKERS_PATH+"marker_legend_item_id_"+markerId+".png";icon.shadow=config.shadow;icon.iconSize=new GSize(config.iconSize.width,config.iconSize.height);icon.shadowSize=new GSize(config.shadowSize.width,config.shadowSize.height);icon.iconAnchor=new GPoint(config.iconAnchor.x,config.iconAnchor.y);var marker=new GMarker(point,{icon:icon});return marker;},createPolygon:function(encoded,legendItems){var legendItem=legendItems.last();var config=legendItem.mapStyle.currentLevel.polygon;var overlay=new GPolygon.fromEncoded({polylines:[this.encodedGPolylineOptions(encoded,legendItem,config)],color:"#"+legendItem.color,opacity:config.fillOpacity,fill:true,outline:true});return overlay;},createLine:function(encoded,legendItems){var legendItem=legendItems.last();var overlay=new GPolyline.fromEncoded(this.encodedGPolylineOptions(encoded,legendItem,legendItem.mapStyle.currentLevel.line));return overlay;},encodedGPolylineOptions:function(encoded,legendItem,config){return{color:"#"+legendItem.color,weight:config.strokeWeight,opacity:config.strokeOpacity,points:encoded.points,levels:encoded.levels,numLevels:encoded.numLevels,zoomFactor:encoded.zoomFactor};},toggleLegendItem:function(id){var legendItem=this.legendItems.get(id);legendItem.hidden=legendItem.hidden?false:true;if(this.sidebar instanceof LegendSidebar){this.sidebar.setChecked(id,!legendItem.hidden);}
this.getObjectsByLegendItem(legendItem).each(function(object){var numVisibleLegendItems=object.legendItems.inject(0,function(sum,li){return li.hidden?sum:sum+1;});var noCluster=object.legendItems.any(function(li){return li.mapStyle.noCluster});object.overlays.each(function(overlay){if(numVisibleLegendItems===0){overlay.hide();if(overlay instanceof GMarker&&!noCluster){this.clusterer.removeMarker(overlay);}}
else if(!legendItem.hidden&&numVisibleLegendItems===1){overlay.show();if(overlay instanceof GMarker&&!noCluster){this.markers.push(overlay);}}}.bind(this));}.bind(this));this.addMarkers();this.updateLocationHash();},showToolTip:function(object,startSuppressing){this.toolTip.show(object,startSuppressing);},hideToolTip:function(stopSuppressing){this.toolTip.hide(stopSuppressing);},setMapClickListener:function(handle){if(this.mapClickHandle){GEvent.removeListener(this.mapClickHandle);}
this.mapClickHandle=handle?GEvent.addListener(this.map,"click",handle):GEvent.addListener(this.map,"click",this.handleMapClick.bind(this));},handleMapClick:function(overlay,latlng,overlayLatlng){if(overlay&&overlay.object){var object=overlay.object;var noInfobox=object.legendItems.any(function(li){return li.mapStyle.noInfobox});var clusterClicked=this.clusterMarkerClicked(latlng||overlayLatlng);if(noInfobox||(!(overlay instanceof GMarker)&&clusterClicked))return;if(object.type==="area"){this.showSidebar(object.type,object.id,true);}
else{latlng=overlay instanceof GMarker?overlay.getLatLng():latlng||overlayLatlng;this.showInfobox(object,overlay,latlng,true);}}
else{this.hideInfobox();}},clusterMarkerClicked:function(latlng){var clicked=false;var point=this.map.fromLatLngToDivPixel(latlng);$("map").select(".cluster-marker").each(function(marker){var offset=marker.positionedOffset();if(point.x>offset.left&&point.x<offset.left+marker.getWidth()&&point.y>offset.top&&point.y<offset.top+marker.getHeight()){clicked=true;throw $break;}});return clicked;},showInfobox:function(object,overlay,latlng,inFocus,skipAnimation){var infoboxClass=window[object.type.capitalize().dasherize().camelize()+"Infobox"];if((this.infobox instanceof infoboxClass)&&this.infobox.object.id===object.id)return;if(this.infobox){this.hideInfobox(true);}
this.infobox=new infoboxClass(this,object,overlay,latlng,inFocus);this.infobox.show(skipAnimation,this.updateLocationHash.bind(this));},hideInfobox:function(skipAnimation){if(this.infobox){this.infobox.hide(skipAnimation);this.infobox=null;this.updateLocationHash();}},toggleSidebar:function(type,id){if(this.sidebar instanceof window[type.capitalize().dasherize().camelize()+"Sidebar"]){this.hideSidebar();}
else{this.showSidebar(type,id);}},showSidebar:function(type,id,inFocus,skipAnimation){var sidebarClass=window[type.capitalize().dasherize().camelize()+"Sidebar"];if((this.sidebar instanceof sidebarClass)&&this.sidebar.objectId()===id)return;var object=this["get"+type.capitalize().dasherize().camelize()+"Object"](id);var sidebar=new sidebarClass(this,object,inFocus);var showCallback=function(){this.sidebar=sidebar;this.sidebar.show(skipAnimation);this.updateLocationHash();}.bind(this);if(this.sidebar){this.hideSidebar(showCallback,skipAnimation);}
else{showCallback();}},hideSidebar:function(afterHide,skipAnimation){if(this.sidebar){var sidebar=this.sidebar;this.sidebar=null;sidebar.hide(afterHide,skipAnimation);if(!afterHide){this.updateLocationHash();}}},toggleHelp:function(){this.toggleSidebar("help");},toggleLegend:function(){this.toggleSidebar("legend");},toggleAreas:function(){this.toggleSidebar("areas");},showArea:function(id,inFocus,skipAnimation){this.showSidebar("area",id,inFocus,skipAnimation);},showLegendItem:function(id){this.showSidebar("legend_item",id);},showObject:function(type,id,inFocus,skipAnimation){var object=this.fetchObject(type,id);if(object&&object.overlays){var marker=object.overlays.find(function(overlay){return overlay instanceof GMarker;});this.showInfobox(object,marker,marker.getLatLng(),inFocus,skipAnimation);}},setMapType:function(name){if(!name){name=this.getMapTypeCookie();}
if(name){this.map.setMapType(window["G_"+name.toUpperCase()+"_MAP"]);}
$("map_controls").select("a.maptype").invoke("removeClassName","active");$("maptype_"+this.getMapTypeName()).addClassName("active");},focusImage:function(id){this.hideInfobox();this.removeFocusOverlay();var image=this.fetchObject("image",id,true);if(image){this.zoomOnObject('image',id,true);var latlng=image.overlays.find(function(overlay){return overlay instanceof GMarker;}).getLatLng();this.focusOverlay=new ImageOverlay(latlng,this.MARKERS_PATH+"circle.png",new GSize(30,30));this.map.addOverlay(this.focusOverlay);}},removeFocusOverlay:function(){if(this.focusOverlay){this.map.removeOverlay(this.focusOverlay);}},zoomOnObject:function(type,id,dontShow){var object=this.fetchObject(type,id);if(object&&object.geodata_for_map){this.map.zoomOnGeodata(object.geodata_for_map,true);if(!dontShow){this.showObject(type,id);}}},getCleanLocationHash:function(){var hash={};$H(this.locationHash).each(function(pair){if(!this.LOCATION_HASH_FIELDS.include(pair[0])){hash[pair[0]]=pair[1];}}.bind(this));return hash;},getZoomLevel:function(){for(var i=this.zoomLevels.length-1;i>=0;i--){if(this.zoomLevels[i].minZoom<=this.map.getZoom()){return this.zoomLevels[i];}}},updateZoomLevel:function(){this.zoomLevel=this.getZoomLevel();},getMapStyleLevel:function(mapStyle){if(!Object.isArray(mapStyle.levels)){return mapStyle;}
var levels=mapStyle.levels;for(var i=levels.length-1;i>=0;i--){if((levels[i].minZoom||0)<=this.map.getZoom()&&levels[i]){return levels[i];}}},getUpdateParams:function(){var bounds=this.map.getBounds();var params={"authenticity_token":window._token,"zoom":this.map.getZoom(),"bbox":[[bounds.getSouthWest().lng(),bounds.getSouthWest().lat()],[bounds.getNorthEast().lng(),bounds.getNorthEast().lat()]].toJSON()};["item","image","area"].each(function(type){params[type+"_ids[]"]=this.getObjectsByType(type).pluck("id");}.bind(this));return params;},getMapTypeCookie:function(){return document.cookie.split(";").reject(function(chunk){return chunk.strip().empty();}).inject({},function(result,chunk){var pair=chunk.strip().split("=");result[pair[0].strip()]=pair[1].strip();return result;})["map_type"];},setMapTypeCookie:function(){document.cookie="map_type="+this.getMapTypeName()+"; path=/";},getMapTypeName:function(){switch(this.map.getCurrentMapType()){case G_NORMAL_MAP:return"normal";case G_SATELLITE_MAP:return"satellite";case G_HYBRID_MAP:return"hybrid";}}});var Captionable={caption:function(){return{thumbnail:this.captionForThumbnail(),details:this.captionForDetails()};},captionForThumbnail:function(){var caption="";if(this.name)caption+=this.name;if(this.date_taken)caption+=(caption?" ("+this.date_taken+")":this.date_taken);return caption?"<div class='image-caption'>"+caption+"</div>":"";},captionForDetails:function(){var caption=[];if(this.full_name)caption.push(this.full_name);if(this.date_taken)caption.push(I18n.t("map.image.date_taken")+": "+this.date_taken);if(this.source_name)caption.push(I18n.t("map.image.source")+": "+this.source_name);return caption.join(", ");}};var ToolTip=Class.create({containerDiv:new Element("div",{id:"tooltip"}).hide(),updatePositionHandler:null,suppressing:false,suppressedObject:null,offsetY:5,initialize:function(){$("map").insert(this.containerDiv);this.updatePositionHandler=this.updatePosition.bind(this);},show:function(object,startSuppressing){if(this.suppressing&&!startSuppressing){this.suppressedObject=object;return;}
var content=object.name||object.legendItems.first().name;this.containerDiv.setStyle({right:''}).update("<div id='tooltip_content'>"+content+"</div>").show();this.updatePosition();$("map").observe("mousemove",this.updatePositionHandler);if(startSuppressing){this.suppressing=true;}},hide:function(stopSuppressing){if(!stopSuppressing){this.suppressedObject=null;}
this.containerDiv.hide();$("map").stopObserving("mousemove",this.updatePositionHandler);if(stopSuppressing){this.suppressing=false;if(this.suppressedObject){this.show(this.suppressedObject);}}},updatePosition:function(){if(!mouse)return;this.containerDiv.setStyle({bottom:$("map").getHeight()-mouse.y+this.offsetY+"px",left:mouse.x-Math.round(this.containerDiv.getWidth()/2)+"px",right:$("map").getWidth()-mouse.x-Math.round(this.containerDiv.getWidth()/2)+"px"});}});var AjaxLoader=Class.create({loadContent:function(){if(!this.object.isDetailed){new Ajax.Request("/"+this.object.type+"s/"+this.object.id,{method:"get",asynchronous:false,onSuccess:function(transport){var response=transport.responseText.evalJSON();Object.extend(this.object,response);this.object.isDetailed=true;}.bind(this)});}}});var ImageOverlay=function(latlng,src,size){this.latlng_=latlng;this.img_=new Element("img",{src:src,width:size.width+"px",height:size.height+"px"});};ImageOverlay.prototype=new GOverlay();ImageOverlay.prototype.initialize=function(map){this.map_=map;map.getPane(G_MAP_OVERLAY_LAYER_PANE).appendChild(this.img_);};ImageOverlay.prototype.remove=function(){this.img_.remove();};ImageOverlay.prototype.redraw=function(force){if(!force)return;var point=this.map_.fromLatLngToDivPixel(this.latlng_);this.img_.setStyle({position:"absolute",left:point.x-Math.round(this.img_.getWidth()/2)+"px",top:point.y-Math.round(this.img_.getHeight()/2)+"px",zIndex:10000000});};ClusterMarker_.prototype.superInitialize=ClusterMarker_.prototype.initialize;ClusterMarker_.prototype.initialize=function(map){this.superInitialize(map);$(this.div_).addClassName("cluster-marker");GEvent.addDomListener(this.div_,"mouseover",function(){wallMap.showToolTip({name:this.innerHTML+" "+I18n.t("map.items_in_this_area")},true);});GEvent.addDomListener(this.div_,"mouseout",function(){wallMap.hideToolTip(true);});};ClusterMarker_.prototype.superRemove=ClusterMarker_.prototype.remove;ClusterMarker_.prototype.remove=function(){GEvent.clearInstanceListeners(this.div_);this.superRemove();};GMap2.prototype.zoomOnGeodata=function(geodata,setCenter,noPan){var zoom=0,center=null;if(geodata.bounds){var bounds=geodata.bounds.toGLatLngBounds();zoom=this.getBoundsZoomLevel(bounds);zoom=zoom>FOCUS_ZOOM_LEVEL?FOCUS_ZOOM_LEVEL:zoom;center=bounds.getCenter();}
else{zoom=FOCUS_ZOOM_LEVEL;center=geodata.geodata.first().toGLatLng();}
if(setCenter){if(zoom!=this.getZoom()||noPan){this.setCenter(center,zoom);}
else{this.panTo(center);}}
else if(zoom!=this.getZoom()){this.setZoom(zoom);}};GLatLng.prototype.toString=function(){return parseFloat(this.lat().toFixed(8))+","+parseFloat(this.lng().toFixed(8));}
Array.prototype.toGLatLng=function(){return new GLatLng(this[0],this[1]);};Array.prototype.toGLatLngBounds=function(){return new GLatLngBounds(this[0].toGLatLng(),this[1].toGLatLng());};var Infobox=Class.create();Infobox.prototype=new GOverlay();Infobox=Class.create(Infobox,{BORDERS:{top:29,right:5,bottom:25,left:50},OPACITY:0.9,closeLink:"<a href='#' onclick='wallMap.hideInfobox(); return false;' class='button close'>"+I18n.t("map.actions.close")+"</a>",contentContainerTemplate:"<div id='infobox_content'>#{content}</div>",areaLinkTemplate:"<p class='area'>"+"<strong>"+I18n.pluralize(1,"map.focus_point")+":</strong> <a href='#' onclick='wallMap.showArea(#{area.id}); return false;'>#{area.bare_name}</a>"+"</p>",contentHash:null,offset:0,wallMap:null,map:null,object:null,overlay:null,latlng:null,scrollbar:null,slideshow:null,initialize:function(wallMap,object,overlay,latlng,inFocus){if(arguments.length>=4){this.wallMap=wallMap;this.map=wallMap.map;this.object=object;this.overlay=overlay;this.latlng=latlng;this.inFocus=inFocus;var cssClass=this.object.type+(overlay instanceof GMarker?" marker":"");this.containerDiv=new Element("div",{id:"infobox","class":cssClass}).hide();this.initializeContentHash();var wrapperDiv=new Element("div",{id:"infobox_wrapper"}).update(this.getContent());this.containerDiv.update(wrapperDiv);this.map.addOverlay(this);}
else{$("inner_map_wrapper").appendChild(this.containerDiv);}},initializeContentHash:function(){this.contentHash={object:this.object,closeLink:this.closeLink};Object.extend(this.contentHash,this.getContentHashExtensions());},getContentHashExtensions:function(){return{};},fitMap:function(afterFinish){if(!this.inFocus){this.wallMap.withoutUpdate(this.map.zoomOnGeodata.bind(this.map,this.object.geodata_for_map,true,true));}
var point=this.map.fromLatLngToContainerPixel(this.latlng);var newPoint=this.getInfoboxAnchorPoint(point);if(newPoint.x!=point.x||newPoint.y!=point.y){var newLatLng=this.map.fromContainerPixelToLatLng(newPoint);var offset=new GLatLng(newLatLng.lat()-this.map.getCenter().lat(),newLatLng.lng()-this.map.getCenter().lng());if(afterFinish){var listener=GEvent.addListener(this.map,"moveend",function(){GEvent.removeListener(listener);afterFinish();});}
this.map.panTo(new GLatLng(this.latlng.lat()-offset.lat(),this.latlng.lng()-offset.lng()));}
else if(afterFinish){afterFinish();}},redraw:function(){var point=this.map.fromLatLngToContainerPixel(this.latlng);this.containerDiv.setStyle({bottom:$("map").getHeight()-point.y+this.offset+"px",left:point.x-Math.round(this.containerDiv.getWidth()/2)+this.offset+"px"});},show:function(skipAnimation,afterFinish){this.containerDiv.setOpacity(skipAnimation?this.OPACITY:0.00001).show();this.beforeVisible();if(!skipAnimation){this.containerDiv.appear({duration:0.5,to:this.OPACITY});}
this.fitMap(afterFinish);},beforeVisible:function(){},hide:function(skipAnimation){if(skipAnimation){this.remove();}
else{this.containerDiv.fade({duration:0.5,afterFinish:this.remove.bind(this)});}},remove:function(){if(this.scrollbar){this.scrollbar=null}
if(this.slideshow){this.slideshow=null}
this.containerDiv.remove();},getWidth:function(){return this.containerDiv.getWidth();},getHeight:function(){return this.containerDiv.getHeight();},getContent:function(){var content=this.contentTemplate.interpolate(this.contentHash);return new Element("div",{id:"infobox_content"}).update(content);},getInfoboxAnchorPoint:function(point){var bounds={xMin:Math.round(this.getWidth()/2)+this.BORDERS.left,xMax:this.map.getSize().width-this.BORDERS.right-Math.round(this.getWidth()/2),yMin:this.getHeight()+this.BORDERS.top,yMax:this.map.getSize().height-this.BORDERS.bottom};var newPoint=Object.clone(point);if(point.x<bounds.xMin){newPoint.x=bounds.xMin;}
if(point.x>bounds.xMax){newPoint.x=bounds.xMax;}
if(point.y<bounds.yMin){newPoint.y=bounds.yMin;}
if(point.y>bounds.yMax){newPoint.y=bounds.yMax;}
return newPoint;}});var TextInfobox=Class.create(Infobox,{contentTemplate:"<div class='buttons'>"+"#{closeLink}"+"#{updateLink}"+"</div>"+"<h3>#{object.title}</h3>#{object.content}",getContentHashExtensions:function(){var object=this.wallMap.currentObject;if(!$w("item image area").include(object.type))return{};var field="<input type='hidden' name='latlng' value='"+this.latlng+"'/>";return{updateLink:'<a href="#" onclick="geometryEditor.form.insert(\''+field.gsub("'","&quot;")+'\');'+'geometryEditor.form.submit(); return false;"'+'class="button action">'+
I18n.t("map.actions.update_place")+'</a>'}}});var AjaxInfobox=Class.create(Infobox,{getContent:function($super){this.loadContent();return $super();}});AjaxInfobox.prototype.loadContent=AjaxLoader.prototype.loadContent;var ItemInfobox=Class.create(AjaxInfobox,{DESCRIPTION_HEIGHT:65,contentTemplate:"<div class='buttons'>"+"#{closeLink}"+"<a href='#' onclick='wallMap.zoomOnObject(\"item\", #{object.id}); return false;' class='button zoom'>"+I18n.t("map.actions.zoom")+"</a>"+"</div>"+"<div class='actions'>"+"<a href='/admin/items/#{object.id}'><img src='/images/icons/show.png' class='icon'/></a>"+"<a href='/admin/items/#{object.id}/edit'><img src='/images/icons/edit.png' class='icon'/></a>"+"</div>"+"<h3>#{object.name}</h3>"+"<p class='place'>#{object.place}</p>",beforeVisible:function(){if(this.object.description_html){var description=this.containerDiv.down('.description');if(description.getHeight()>this.DESCRIPTION_HEIGHT){description.setStyle({height:this.DESCRIPTION_HEIGHT+"px"});this.scrollbar=new Control.ScrollBar(description);description.scrollbar=this.scrollbar;}}},loadContent:function($super){$super();this.object.place=this.object.place_names.join(", ");this.object.attached_areas=this.object.attached_areas.reject(function(area){return!area.published});},getContent:function($super){var content=$super();content.insert({bottom:this.getLegendItemsContent()});if(this.object.attached_areas.first()){content.insert({bottom:this.areaLinkTemplate.interpolate({area:this.object.attached_areas.first()})});}
if(this.object.description_html){content.insert({bottom:"<div class='description'>"+this.object.description_html+"</div>"});}
if(this.object.attached_images.length>0){this.initializeSlideshow();content.insert({bottom:this.slideshow.getContent()});}
return content;},initializeSlideshow:function(){this.slideshow=new ImageSlideshow(this.object.attached_images.reject(function(image){return!image.published}),{gallery:"item",thumbnail:"preview",maxImageWidth:300});},getLegendItemsContent:function(){var legendItems=this.object.legendItems.inject("",function(result,li){if(result.length>0)result+=", ";if(!li.dynamic){result+="<img src='/images/blank.gif' class='color' style='background-color: #"+li.color+";'/> ";}
result+="<a href='#' onclick='wallMap.showLegendItem("+li.id+"); return false;'>"+li.name+"</a>";return result;});return"<p class='legend-items'><strong>"+I18n.t("map.legend.legend_item")+": </strong>"+legendItems+"</p>";}});var ImageInfobox=Class.create(AjaxInfobox,{imageWidth:300,contentTemplate:"<div class='buttons'>"+"#{closeLink}"+"<a href='#' onclick='wallMap.zoomOnObject(\"image\", #{object.id}); return false;' class='button zoom'>"+I18n.t("map.actions.zoom")+"</a>"+"</div>"+"<div class='actions'>"+"<a href='/admin/images/#{object.id}'><img src='/images/icons/show.png' class='icon'/></a>"+"<a href='/admin/images/#{object.id}/edit'><img src='/images/icons/edit.png' class='icon'/></a>"+"</div>"+"#{object.place}"+"<p class='legend-item'>"+"<strong>"+I18n.t("map.image.legend_item")+":</strong> <img src='/images/blank.gif' class='color' style='background-color: ##{object.legendItems[0].color};'/>"+"<a href='#' onclick='wallMap.showLegendItem(#{object.legendItems[0].id}); return false;'>#{object.legendItems[0].name}</a>"+"</p>"+"<div class='images-container block'>"+"<div class='imagebox'>"+"<a href='#{object.image_file.public_filename}' class='lightview' title='#{object.caption.details}'>"+"<img src='#{object.image_file.preview.public_filename}' width='#{object.image_file.scaled.width}' height='#{object.image_file.scaled.height}'/>"+"#{object.caption.thumbnail}"+"</a>"+"</div>"+"</div>",loadContent:function($super){$super();if(this.object.place_names){this.object.place="<p class='place'>"+this.object.place_names.join(", ")+"</p>";}
this.object.attached_areas=this.object.attached_areas.reject(function(area){return!area.published});this.object.caption=Object.extend(this.object,Captionable).caption();var preview=this.object.image_file.preview;var height=Math.round(preview.height*(this.imageWidth/preview.width));this.object.image_file.scaled={width:this.imageWidth,height:height};},getContent:function($super){var content=$super();if(this.object.attached_areas.first()){content.down(".legend-item").insert({after:this.areaLinkTemplate.interpolate({area:this.object.attached_areas.first()})});}
return content;}});var Sidebar=Class.create({closeLink:"<a href='#' onclick='wallMap.hideSidebar(); return false;' class='button close' title='Schliessen'>"+I18n.t("map.actions.close")+"</a>",type:"",buttonId:"",wallMap:null,map:null,mapContainer:null,oldMapCenter:null,object:null,inFocus:false,skipAnimation:false,containerDiv:null,hiding:false,afterHideCallback:null,scrollbar:null,slideshow:null,initialize:function(wallMap,object,inFocus){this.wallMap=wallMap;this.map=wallMap.map;this.object=object;this.inFocus=inFocus;this.mapContainer=wallMap.mapContainer;this.containerDiv=new Element("div",{id:"sidebar","class":this.type}).update(this.getContent()).hide();this.containerDiv.sidebar=this;this.mapContainer.insert({after:this.containerDiv});this.containerDiv.setStyle({left:this.mapContainer.getWidth()+"px",width:this.width+"px",height:this.mapContainer.getHeight()+"px"});},initializeScrollbar:function(){var div=this.containerDiv.down(".scrollbar");this.scrollbar=new Control.ScrollBar(div);div.scrollbar=this.scrollbar;},objectId:function(){return this.object&&this.object.id?this.object.id:null;},beforeShow:function(){},show:function(skipAnimation){this.containerDiv.show();this.beforeShow();this.resize(this.mapContainer.fullWidth-this.width,skipAnimation);},hide:function(afterHideCallback,skipAnimation){if(afterHideCallback){this.afterHideCallback=afterHideCallback;}
this.hiding=true;var mapWidth=this.mapContainer.getWidth()+(afterHideCallback?0:this.width);this.resize(mapWidth,skipAnimation);this.afterHide();},afterHide:function(){},visible:function(){return this.containerDiv.visible();},toggle:function(afterHideCallback){this.visible()?this.hide(afterHideCallback):this.show();},resize:function(to,skipAnimation){if($(this.buttonId)){$(this.buttonId).toggleClassName("active").blur();}
if(to!=this.mapContainer.getWidth()){this.oldMapCenter=this.map.getCenter();if(skipAnimation){this.mapContainer.setStyle({width:to+"px"});this.afterMapResize();}
else{new Effect.Morph(this.mapContainer,{style:{width:to+"px"},duration:0.3,queue:"end",afterFinish:this.afterMapResize.bind(this)});}}
this.containerDiv.setStyle({left:to+"px"});if(skipAnimation){this.containerDiv[this.hiding?"hide":"show"]();this.afterResize();}
else{this.containerDiv[this.hiding?"show":"hide"]();new Effect[this.hiding?"BlindUp":"BlindDown"](this.containerDiv,{duration:0.3,queue:"end",afterFinish:function(){this.afterResize();}.bind(this)});}},afterMapResize:function(){this.map.checkResize();this.map.setCenter(this.oldMapCenter);},afterResize:function(){if(this.hiding){this.remove();if(this.afterHideCallback){this.afterHideCallback();this.afterHideCallback=null;}}},remove:function(){if(this.scrollbar){this.scrollbar=null}
if(this.slideshow){this.slideshow=null}
this.containerDiv.hide();this.containerDiv.remove();},getWidth:function(){return this.containerDiv.getWidth();},getHeight:function(){return this.containerDiv.getHeight();},getContentContainer:function(){return new Element("div",{id:"sidebar_content"});},getContent:function(){var content=this.contentTemplate.interpolate({object:this.object,closeLink:this.closeLink});return this.getContentContainer().update(content);}});var HelpSidebar=Class.create(Sidebar,{type:"help",buttonId:"button_help",width:350,contentTemplate:"<div class='head'><div class='buttons'>#{closeLink}</div></div>"+"<div class='details-container'>"+"<div class='scrollbar description'>#{object.text}</div>"+"</div>",beforeShow:function(){this.initializeScrollbar();}});var LegendSidebar=Class.create(Sidebar,{type:"legend",buttonId:"button_legend",width:311,contentTemplate:"<div class='head'>"+"<div class='buttons'>#{closeLink}</div>"+"</div>"+"<div class='details-container'>"+"<div class='buttons'>"+"<a href='#' onclick='this.up(\"#sidebar\").sidebar.showAll(); return false;' class='button show-all'>"+I18n.t("map.legend.actions.show_all")+"</a>"+"<a href='#' onclick='this.up(\"#sidebar\").sidebar.hideAll(); return false;' class='button hide-all'>"+I18n.t("map.legend.actions.hide_all")+"</a>"+"</div>"+"<div class='scrollbar'><ul>#{legendItems}</ul></div>"+"</div>",legendItemTemplate:"<li id='legend_item_#{legendItem.id}' class='#{class}'>"+"<div class='marker' style='background-image: url(#{legendItem.mapStyle.marker.shadow});'>#{marker}</div>"+"<input type='checkbox' #{checked} onclick='wallMap.toggleLegendItem(#{legendItem.id});'/>"+"<div class='text'>"+"<strong>#{legendItem.name}</strong><br/>"+"<a href='#' onclick='wallMap.showLegendItem(#{legendItem.id}); return false;'>"+I18n.t("map.actions.more")+"</a>"+"</div>"+"</li>",beforeShow:function(){this.containerDiv.down(".scrollbar").setStyle({height:(this.getHeight()-this.containerDiv.down(".head").getHeight()-66)+"px"});this.initializeScrollbar();},getContent:function(){var legendItems=this.object.inject("",function(result,pair,index){var legendItem=pair.value;return result+=this.legendItemTemplate.interpolate({legendItem:legendItem,checked:this.wallMap.legendItems.get(pair.key).hidden?"":"checked='checked'",marker:legendItem.mapStyle.marker?"<img src='/images/icons/map/markers/marker_legend_item_id_"+legendItem.id+".png'/>":"<div class='color' style='background: #"+legendItem.color+";'> </div>"})}.bind(this));var content=this.contentTemplate.interpolate({legendItems:legendItems,closeLink:this.closeLink});return this.getContentContainer().update(content);},showAll:function(){this.toggleAll(true);},hideAll:function(){this.toggleAll(false);},toggleAll:function(visible){this.wallMap.legendItems.values().each(function(legendItem){if((legendItem.hidden&&visible)||!legendItem.hidden&&!visible){this.wallMap.toggleLegendItem(legendItem.id);this.containerDiv.down("li#legend_item_"+legendItem.id+" input").checked=visible;}}.bind(this));},setChecked:function(id,checked){this.containerDiv.down("#legend_item_"+id+" input").checked=checked;}});var LegendItemSidebar=Class.create(Sidebar,{type:"legend_item",buttonId:"button_legend",width:311,contentTemplate:"<div class='head'>"+"<div class='buttons'>"+"#{closeLink}"+"<a href='#' onclick='wallMap.toggleLegend(); return false;' class='button list'>"+I18n.t("map.legend.actions.list")+"</a>"+"</div>"+"<h3><img src='/images/blank.gif' class='color' style='background-color: ##{object.color};'/>#{object.name}</h3>"+"</div>"+"<div class='details-container'>"+"<div class='scrollbar description'>#{object.description_html}</div>"+"</div>",beforeShow:function(){this.containerDiv.down(".description").setStyle({height:(this.getHeight()-this.containerDiv.down(".head").getHeight()-40)+"px"});this.initializeScrollbar();}});var AreasSidebar=Class.create(Sidebar,{type:"areas",buttonId:"button_areas",width:350,contentTemplate:"<div class='head'>"+"<div class='buttons'>#{closeLink}</div>"+"</div>"+"<div class='details-container'>"+"<ul class='scrollbar'>#{areas}</ul>"+"</div>",areaTemplate:"<li>"+"<a href='#' onclick='wallMap.showArea(#{area.id}); return false;'>"+"<div class='map' style='background: transparent url(http://maps.google.com/maps/api/staticmap?center=52.491,13.292&markers=size:small|color:0x008FC5|#{area.center[0]},#{area.center[1]}&zoom=7&size=50x70&maptype=terrain&sensor=false&key=#{mapKey});'></div>"+"</a>"+"<div class='text'>"+"<strong>#{area.bare_name}</strong><br/>"+"<a href='#' onclick='wallMap.showArea(#{area.id}); return false;'>"+I18n.t("map.actions.more")+"</a>"+"</div>"+"</li>",beforeShow:function(){this.containerDiv.down("ul").setStyle({height:(this.getHeight()-this.containerDiv.down(".head").getHeight()-40)+"px"});this.initializeScrollbar();},getContent:function(){var areas=this.object.inject("",function(result,area){return result+=this.areaTemplate.interpolate({area:area,mapKey:window._mapKey})}.bind(this));var content=this.contentTemplate.interpolate({areas:areas,closeLink:this.closeLink})
return this.getContentContainer().update(content);}});var AjaxSidebar=Class.create(Sidebar,{getContent:function($super){this.loadContent();return $super();}});AjaxSidebar.prototype.loadContent=AjaxLoader.prototype.loadContent;var AreaSidebar=Class.create(AjaxSidebar,{type:"area",buttonId:"button_areas",width:350,bounds:null,contentTemplate:"<div class='head'>"+"<div class='actions'>"+"<a href='/admin/areas/#{object.id}'><img src='/images/icons/show.png' class='icon'/></a>"+"<a href='/admin/areas/#{object.id}/edit'><img src='/images/icons/edit.png' class='icon'/></a>"+"</div>"+"<div class='buttons'>"+"#{closeLink}"+"<a href='#' onclick='wallMap.toggleAreas(); return false;' class='button list'>"+I18n.t("map.focus_point.actions.list")+"</a>"+"</div>"+"<h3>#{object.name}</h3>"+"</div>"+"<div class='details-container'>"+"<div class='scrollbar description'>#{object.description_html}</div>"+"</div>",beforeShow:function(){this.containerDiv.down(".description").setStyle({height:(this.getHeight()-this.containerDiv.down(".head").getHeight()-this.containerDiv.down(".slideshow").getHeight()-50)+"px"});this.initializeScrollbar();},afterHide:function(){this.wallMap.removeFocusOverlay();},afterResize:function($super){$super();if(this.visible()){if(!this.inFocus){this.map.zoomOnGeodata(this.object.geodata_for_map,true);}}},getContent:function($super){var content=$super();this.slideshow=new ImageSlideshow(this.object.attached_images.reject(function(image){return!image.published;}),{gallery:"area",thumbnail:"preview",maxImageWidth:this.width-57,callback:function(index){this.wallMap.focusImage(this.object.attached_images[index].id);}.bind(this)});content.insert({bottom:this.slideshow.getContent()});return content;}});var ImageSlideshow=Class.create({DEFAULT_OPTIONS:{gallery:"default",thumbnail:"large",maxImageWidth:128,maxImageHeight:250,minPortraitImageHeight:220},lowestImageHeight:Infinity,container:"",options:{},length:0,index:0,contentTemplate:"<div class='images-container'>"+"<div class='images'>#{imagesContent}</div>"+"</div>",controlsTemplate:"<div class='controls'>"+"<a href='#' title='"+I18n.t("map.slideshow.actions.previous")+"' onclick='this.up(\".slideshow\").slideshow.prev(); return false;'><img src='/images/icons/prev.png'/></a>"+"<strong class='current'>#{current}</strong> "+I18n.t("map.of")+" <strong>#{total}</strong>"+"<a href='#' title='"+I18n.t("map.slideshow.actions.next")+"' onclick='this.up(\".slideshow\").slideshow.next(); return false;'><img src='/images/icons/next.png'/></a>"+"</div>",imageTemplate:"<div class='imagebox-container' style='width: #{options.imageboxWidth}px;'>"+"<div class='imagebox image-#{index}' style='width: #{image.image_file.slideshow.width}px;'>"+"<a href='#{image.image_file.public_filename}' class='lightview' rel='gallery[#{options.gallery}]' title='#{image.caption.details}'>"+"<img src='#{image.image_file.slideshow.public_filename}' width='#{image.image_file.slideshow.width}' height='#{image.image_file.slideshow.height}'/>"+"#{image.caption.thumbnail}"+"</a>"+"</div>"+"</div>",initialize:function(images,options){this.initializeOptions(options);this.length=images.length;this.container=new Element("div",{"class":"slideshow block"});this.container.slideshow=this;this.adjustImageDimensions(images);var imagesContent=images.inject("",function(result,image,index){image.caption=Object.extend(image,Captionable).caption();return result+this.imageTemplate.interpolate({options:this.options,image:image,index:index});}.bind(this));this.container.update(this.contentTemplate.interpolate({imagesContent:imagesContent}));if(this.length>1){this.container.insert({top:this.controlsTemplate.interpolate({current:1,total:this.length})});}},initializeOptions:function(options){this.options=Object.clone(this.DEFAULT_OPTIONS);Object.extend(this.options,options||{});this.options.imageboxWidth=this.options.maxImageWidth+12;},getContent:function(){return this.container;},getImages:function(){return this.container.down(".images");},adjustImageDimensions:function(images){this.adjustImageWidth(images);this.adjustImageHeight(images);},adjustImageWidth:function(images){images.each(function(image){var img=Object.clone(image.image_file[this.options.thumbnail]);img.height=Math.round((this.options.maxImageWidth/img.width)*img.height);img.width=this.options.maxImageWidth;if(img.height<this.lowestImageHeight){this.lowestImageHeight=img.height;}
image.image_file.slideshow=img;}.bind(this));},adjustImageHeight:function(images){images.each(function(image){var img=image.image_file.slideshow;var newHeight=this.lowestImageHeight;if((img.height>img.width)&&(newHeight<this.options.minPortraitImageHeight)){newHeight=this.options.minPortraitImageHeight;}
else if(newHeight>this.options.maxImageHeight){newHeight=this.options.maxImageHeight;}
var newWidth=Math.round((newHeight/img.height)*img.width);if(newWidth<=this.options.maxImageWidth){img.width=Math.round((newHeight/img.height)*img.width);img.height=newHeight;}}.bind(this));},prev:function(){if(this.index>0){this.slide(-1);}},next:function(){if(this.index<this.length-1){this.slide(1);}},slide:function(direction){var index=this.index+direction;this.index=index;this.container.down(".current").update(this.index+1);new Effect.Move(this.getImages(),{x:-(this.index*(this.options.imageboxWidth+5)),y:0,mode:"absolute",duration:0.5,queue:"end",afterFinish:function(){if(this.options.callback){this.options.callback(index);}}.bind(this)});}});