
function PanoMapTypeControl(opt_opts)
{this.options=opt_opts||{};}
PanoMapTypeControl.prototype=new GControl();PanoMapTypeControl.prototype.initialize=function(map)
{var container=document.createElement("div");var me=this;var first_border=document.createElement("div");first_border.className="panoramio_amtc_option";var panoDiv=me.createButton_("Panoramio");GEvent.addDomListener(panoDiv,"click",function()
{if(me.panoLayer)
{if(me.panoLayer.getEnabled())
{me.panoLayer.disable();}
else
{me.panoLayer.enable();}}
else
{me.panoLayer=new PanoramioLayer(map);me.panoLayer.enable();}
me.toggleButton_(panoDiv.firstChild,me.panoLayer.getEnabled());});me.toggleButton_(panoDiv.firstChild,false);container.appendChild(first_border);first_border.appendChild(panoDiv);map.getContainer().appendChild(container);return container;}
PanoMapTypeControl.prototype.createButton_=function(text)
{var buttonDiv=document.createElement("div");buttonDiv.className="panoramio_estate_button";var textDiv=document.createElement("div");textDiv.appendChild(document.createTextNode(text));buttonDiv.appendChild(textDiv);return buttonDiv;}
PanoMapTypeControl.prototype.toggleButton_=function(div,boolCheck)
{if(boolCheck)
{div.className="panoramio_estate_active";}
else
{div.className="panoramio_estate";}}
PanoMapTypeControl.prototype.getDefaultPosition=function()
{return new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(220,7));}
function PanoramioLayerCallback(json,panoLayer)
{for(var i=0;i<json.photos.length;i++)
{var photo=json.photos[i];if(!panoLayer.ids[photo.photo_id])
{var marker=this.createMarker(photo,panoLayer.markerIcon);panoLayer.mgr.addMarker(marker,0);panoLayer.ids[photo.photo_id]="exists";}}}
PanoramioLayerCallback.prototype.formImgUrl=function(photoId,imgType)
{return'http://www.panoramio.com/photos/'+imgType+'/'+photoId+'.jpg';}
PanoramioLayerCallback.prototype.createMarker=function(photo,baseIcon)
{var markerIcon=new GIcon(baseIcon);markerIcon.image=this.formImgUrl(photo.photo_id,"mini_square");var marker=new GMarker(new GLatLng(photo.latitude,photo.longitude),{icon:markerIcon,title:photo.photo_title});if(photo.photo_title.length>33)
{photo.photo_title=photo.photo_title.substring(0,33)+"&#8230;";}
var html="<div id='panoramio_flyout_info_window'>"+"<p><a href='http://www.panoramio.com/' target='_blank'>"+"<img src='http://www.panoramio.com/img/logo-small.gif' class='panoramio_flyout_img' alt='Panoramio logo' /><\/a></p>"+"<a target='_blank' href='"+photo.photo_url+"'>"+"<img width='"+photo.width+"' height='"+photo.height+"' src='"+photo.photo_file_url+"'/><\/a>"+"<div id='panoramio_flyout_text'>"+"<p><a target='_blank' href='"+photo.photo_url+"'><strong>"+photo.photo_title+"<\/strong><\/a></p>"+"<p>Posted by <a target='_blank' href='"+photo.owner_url+"'>"+
photo.owner_name+"<\/a></p><\/div>"+"<\/div>";marker.html=html;GEvent.addListener(marker,"click",function()
{map.openInfoWindow(marker.getLatLng(),marker.html,{noCloseOnClick:true});});return marker;}
function PanoramioLayer(map,opt_opts)
{var me=this;me.ids={};me.mgr=new MarkerManager(map,{maxZoom:19});var icon=new GIcon();icon.image="http://www.panoramio.com/img/panoramio-marker.png";icon.shadow="";icon.iconSize=new GSize(24,24);icon.shadowSize=new GSize(22,22);icon.iconAnchor=new GPoint(9,9);icon.infoWindowAnchor=new GPoint(9,0);me.markerIcon=icon;me.enabled=false;GEvent.addListener(map,"moveend",function()
{if(me.enabled)
{var bounds=map.getBounds();var southWest=bounds.getSouthWest();var northEast=bounds.getNorthEast();me.load(me,{maxy:northEast.lat(),miny:southWest.lat(),maxx:northEast.lng(),minx:southWest.lng()});}});}
PanoramioLayer.prototype.enable=function()
{this.enabled=true;GEvent.trigger(map,"moveend");}
PanoramioLayer.prototype.disable=function()
{this.enabled=false;this.mgr.clearMarkers();this.ids={};}
PanoramioLayer.prototype.getEnabled=function()
{return this.enabled;}
PanoramioLayer.prototype.load=function(panoLayer,userOptions)
{var options={order:"popularity",set:"public",from:"0",to:"10",minx:"-180",miny:"-90",maxx:"180",maxy:"90",size:"small"};for(optionName in userOptions)
{if(userOptions.hasOwnProperty(optionName))
{options[optionName]=userOptions[optionName];}}
var url="http://www.panoramio.com/map/get_panoramas.php?";var uniqueID="";for(optionName in options)
{if(options.hasOwnProperty(optionName))
{var optionVal=""+options[optionName]+"";url+=optionName+"="+optionVal+"&";uniqueID+=optionVal.replace(/[^\w]+/g,"");}}
var callbackName="PanoramioLayerCallback.loader"+uniqueID;eval(callbackName+" = function(json) { var pa = new PanoramioLayerCallback(json, panoLayer);}");var script=document.createElement('script');script.setAttribute('src',url+'callback='+callbackName);script.setAttribute('id','jsonScript');script.setAttribute('type','text/javascript');document.documentElement.firstChild.appendChild(script);}