
$.extend(Function.prototype,{bind:function(){function $A(iterable){if(!iterable)return[];if(iterable.toArray)return iterable.toArray();var length=iterable.length,results=new Array(length);while(length--)results[length]=iterable[length];return results;}
if(arguments.length<2&&arguments[0]===undefined)return this;var __method=this,args=$A(arguments),object=args.shift();return function(){return __method.apply(object,args.concat($A(arguments)));}}});lp=window.lp={maps:{}};lp.maps.load=function(callback)
{if(window.google&&!google.maps)
{google.load("maps","2",{"callback":function(){lp.maps.init(callback);}.bind(this)});}
else if(!lp.maps.INIT_DONE)
{lp.maps.init(callback);}
else
{callback();}};lp.maps.init=function(callback)
{lp.maps.Map2.create();lp.maps.Marker.create();lp.maps.MapTypeControl.create();lp.maps.ZoomControl.create();lp.maps.POITypeControl.create();lp.maps.ThrobberControl.create();lp.maps.IWindow.create();lp.maps.Config.supported_maptypes={map:{name:'Map',type:G_NORMAL_MAP},sat:{name:'Satellite',type:G_SATELLITE_MAP},hyb:{name:'Hybrid',type:G_HYBRID_MAP},ter:{name:'Terrain',type:G_PHYSICAL_MAP}};callback();};lp.maps.Map2=function(opts)
{this.initialize(opts);};lp.maps.Map2.create=function()
{$.extend(lp.maps.Map2.prototype,GMap2.prototype);lp.maps.Map2.DESTINATION_TYPE='3';lp.maps.Map2.POI_EAT_TYPE='10';lp.maps.Map2.POI_NIGHT_TYPE='53';lp.maps.Map2.POI_SEE_TYPE='54';lp.maps.Map2.POI_SHOP_TYPE='55';lp.maps.Map2.POI_HAYSTACK_TYPE='56';lp.maps.Map2.POI_GENERAL_TYPE='59';$.extend(lp.maps.Map2.prototype,{initialize:function(__opts){this.__resolveInputOptions(__opts||{});$(lp.maps.Config.container).addClass("lpmapsDiv");var cssSheet=document.createElement('link');cssSheet.setAttribute('rel','stylesheet');cssSheet.setAttribute('type','text/css');cssSheet.setAttribute('href',lp.maps.Config.cdnUrl+'assets/css/maps.css');document.getElementsByTagName("head")[0].appendChild(cssSheet);this.__inheritFrom=GMap2;this.__inheritFrom(lp.maps.Config.container);lp.maps.Config.map=this;var __oldEvt=window.onunload;window.onunload=function(){if(__oldEvt)__oldEvt();GUnload();};this.addControl(new lp.maps.MapTypeControl());this.addControl(new lp.maps.ZoomControl());this.addControl(new lp.maps.ThrobberControl());if(lp.maps.Config.showscale)this.addControl(new GScaleControl());GEvent.addListener(this,"addoverlay",function(overlay){overlay.map=this;});GEvent.addListener(this,"removeoverlay",function(overlay){if(overlay.hideIWindow)overlay.hideIWindow();overlay.map=undefined;});GEvent.addListener(this,"clearoverlays",function(){if(lp.maps.Cache.iwindow)lp.maps.Cache.iwindow.hide();});GEvent.addListener(this,"data_load_error",function(type,XMLHttpRequest,textStatus,errorThrown){var missingDataOverlay=$('<div/>').addClass('lpmapsErrorContainer');missingDataOverlay.append("<div id='lpmapsMessageContainer'><div id='lpmapsErrorContent'><p>"+lp.maps.Config.messages.error.data_load_error+"</p></div></div>");$(lp.maps.Config.container).append(missingDataOverlay);missingDataOverlay.show();});if(lp.maps.Config.lpTiles)this.tilemanager=new lp.maps.TileManager(this);switch(lp.maps.Config.mode){case'poi':var controller=new lp.maps.POIController(this);controller.run();break;case'destination':var controller=new lp.maps.DestinationController(this);controller.run();break;case'favourites':var controller=new lp.maps.FavouritesController(this);controller.run();break;case'tripplanner':var controller=new lp.maps.TripPlannerController(this);controller.run();break;default:return false;}
this.controller=controller;},__resolveInputOptions:function(__opts){for(var property in __opts)lp.maps.Config[property]=__opts[property];},zoomIn:function(){GEvent.trigger("zoominstart");GMap2.prototype.zoomIn.call(this);},zoomOut:function(){GEvent.trigger("zoomoutstart");GMap2.prototype.zoomOut.call(this);}});};lp.maps.Config={map:'',mode:'poi',request:'json',dataserver:'/destinations/',cdnUrl:'/static-ui/style/',poizoom:14,cluster_zoom:95,maptype:'map',maptypes:['map','sat','hyb','ter'],poitypes:['SIGHTS'],showscale:true,featured_items:{},noBubbles:{},noBubble:false,displayFeature:false,lpTiles:true,tileBoxesUrl:'http://localhost/static-ui/maps/tileBoxes.json',tileUrl:'http://web01.maps.dev.lpdi.net:3000/tiles',icons:{small:{'SIGHTS':'pin-sml_sights.png','SHOPPING':'pin-sml_shops.png','EATING':'pin-sml_restaurants.png','ENTERTAINMENT':'pin-sml_entertainment.png','OTHER':'pin-sml_general.png','Destination':'pin-sml_destination.png'},large:{'SIGHTS':'pin-lrg_sights.png','SHOPPING':'pin-lrg_shops.png','EATING':'pin-lrg_restaurants.png','ENTERTAINMENT':'pin-lrg_entertainment.png','OTHER':'pin-lrg_general.png','Destination':'pin-lrg_destination.png'},options:{SIGHTS:{small:{w:12,h:22,shadow:'pin-sml_shadow.png',shadow_w:23,shadow_h:22,overlay_anchor:4},large:{w:26,h:50,shadow:'pin-lrg_shadow.png',shadow_w:51,shadow_h:50,overlay_anchor:10}},SHOPPING:{small:{w:12,h:22,shadow:'pin-sml_shadow.png',shadow_w:23,shadow_h:22,overlay_anchor:4},large:{w:26,h:50,shadow:'pin-lrg_shadow.png',shadow_w:51,shadow_h:50,overlay_anchor:10}},EATING:{small:{w:12,h:22,shadow:'pin-sml_shadow.png',shadow_w:23,shadow_h:22,overlay_anchor:4},large:{w:26,h:50,shadow:'pin-lrg_shadow.png',shadow_w:51,shadow_h:50,overlay_anchor:10}},ENTERTAINMENT:{small:{w:12,h:22,shadow:'pin-sml_shadow.png',shadow_w:23,shadow_h:22,overlay_anchor:4},large:{w:26,h:50,shadow:'pin-lrg_shadow.png',shadow_w:51,shadow_h:50,overlay_anchor:10}},OTHER:{small:{w:12,h:22,shadow:'pin-sml_shadow.png',shadow_w:23,shadow_h:22,overlay_anchor:4},large:{w:26,h:50,shadow:'pin-lrg_shadow.png',shadow_w:51,shadow_h:50,overlay_anchor:10}},Destination:{small:{w:26,h:26,shadow:'pin-sml_destination-shadow.png',shadow_w:35,shadow_h:26,overlay_anchor:4},large:{w:40,h:48,shadow:'pin-lrg_destination-shadow.png',shadow_w:65,shadow_h:48,overlay_anchor:10}}}},supported_poi_types:{SIGHTS:"Sights",SHOPPING:"Shopping",EATING:"Restaurants",ENTERTAINMENT:"Entertainment"},messages:{error:{data_load_error:"Sorry, we were unable to service your request."}}};lp.maps.Cache={};lp.maps.LoadManager=function(map){this.initialize(map);};$.extend(lp.maps.LoadManager.prototype,{initialize:function(map)
{this.map=map;this.loaded_bounds={};this.loaded_poi_bounds={};this.loaded_destinations={};this.loaded_poi_destinations={};this.mercator=new GMercatorProjection(23);var loadManager=this;$.each(lp.maps.Config.supported_poi_types,function(i)
{loadManager.loaded_poi_destinations[i]={};});},minSize:function(zoom)
{switch(zoom){case 1:return 256*256;break;case 2:return 256*128;break;default:return 128*128;}},load:function(bounds,zoom)
{if(this.isCacheHit(bounds,zoom))
{GEvent.trigger(this,"load",this.visibleDestinations(bounds,zoom));}
else
{var bounds_to_load=this.boundsToLoad(bounds);this.do_load(bounds_to_load,zoom,this.destinationsToExclude(bounds_to_load,zoom));this.expandBoundsCache(zoom,bounds_to_load);}},manualItemLoad:function(url,callback)
{$.ajax({url:url,dataType:'json',success:function(data)
{this.massageLoadedItem(data);lp.maps.Map2.LOADED=true;callback(data);}.bind(this),error:function(xmlHttpRequest,textStatus,errorThrown)
{GEvent.trigger(this.map,"data_load_error","LoadManager",xmlHttpRequest,textStatus,errorThrown);}.bind(this)});},isDestinationVisible:function(destination,zoom)
{var sw=this.mercator.fromLatLngToPixel(destination.latLngBounds.getSouthWest(),zoom);var ne=this.mercator.fromLatLngToPixel(destination.latLngBounds.getNorthEast(),zoom);var width=Math.round(Math.abs(sw.x-ne.x));var height=Math.round(Math.abs(sw.y-ne.y));return(width*height>=this.minSize(zoom));},visibleDestinations:function(bounds,zoom)
{var loadManager=this;var dests=[];$.each(this.loaded_destinations,function(id,destination)
{if(destination.latLngBounds.intersects(bounds))dests.push(destination);});dests=$.grep(dests,function(n,i){return(loadManager.isDestinationVisible(n,zoom));});$.each(dests,function()
{var destination=this;destination.properties.pois_by_type={};$.each(lp.maps.Config.supported_poi_types,function(type){if(loadManager.loaded_poi_destinations[type][destination.properties.id])
{destination.properties.pois_by_type[type]=loadManager.loaded_poi_destinations[type][destination.properties.id];}});});return dests;},destinationsToExclude:function(bounds,zoom)
{var loadManager=this;return $.grep(this.visibleDestinations(bounds,zoom),function(destination)
{var okay=true;$.each(lp.maps.Config.poitypes,function()
{if(loadManager.loaded_poi_destinations[this][destination.properties.id]==undefined)okay=false;});return okay;});},expandBoundsCache:function(zoom,bounds)
{var loadManager=this;if(!loadManager.loaded_bounds[zoom])loadManager.loaded_bounds[zoom]=[];loadManager.loaded_bounds[zoom].push(bounds);$.each(lp.maps.Config.poitypes,function()
{var poi_category_type=this;if(!loadManager.loaded_poi_bounds[zoom])loadManager.loaded_poi_bounds[zoom]={};if(!loadManager.loaded_poi_bounds[zoom][poi_category_type])loadManager.loaded_poi_bounds[zoom][poi_category_type]=[];loadManager.loaded_poi_bounds[zoom][poi_category_type].push(bounds);});},expandDestinationCache:function(destinations)
{var loadManager=this;$.each(destinations,function()
{var destination=this;var dest_id=destination.properties.id;loadManager.loaded_destinations[dest_id]=destination;if(destination.properties.num_pois>0)
{$.each(lp.maps.Config.poitypes,function()
{if(!loadManager.loaded_poi_destinations[this][dest_id])
loadManager.loaded_poi_destinations[this][dest_id]=destination.properties.pois_by_type[this];});}
else
{$.each(lp.maps.Config.supported_poi_types,function(i)
{loadManager.loaded_poi_destinations[i][dest_id]=[];});}});},isCacheHit:function(bounds,zoom)
{var loadManager=this;if(loadManager.loaded_bounds[zoom]&&$.grep(loadManager.loaded_bounds[zoom],function(a){return a.containsBounds(bounds);}).length>0)
{var loaded=true;$.each(lp.maps.Config.poitypes,function()
{if(!(loadManager.loaded_poi_bounds[zoom]&&loadManager.loaded_poi_bounds[zoom][this]&&$.grep(loadManager.loaded_poi_bounds[zoom][this],function(a){return a.containsBounds(bounds);}).length>0))
{loaded=false;}});if(loaded)return true;var loaded_destinations=this.visibleDestinations(bounds,zoom);var poi_destinations=$.grep(loaded_destinations,function(destination)
{return(destination.properties.num_pois>0);});return(poi_destinations.length==0);}
else
{return false;}},do_load:function(bounds,zoom,excludes)
{var url=lp.maps.Config.dataserver
+"surroundingDestinations"
+"/"+this.getPoiTypes()
+"/"+bounds.getNorthEast().lat()
+","+bounds.getNorthEast().lng()
+","+bounds.getSouthWest().lat()
+","+bounds.getSouthWest().lng()
+"/"+this.minSize(zoom)
+"/"+zoom
+"/"+$.map(excludes,function(n){return n.properties.id;}).join(',')
+".json";GEvent.trigger(this.map,"ajax.surroundingDestinations.start");$.ajax({url:url,dataType:'json',success:function(data){this.on_data_load(data,excludes);GEvent.trigger(this.map,"ajax.surroundingDestinations.success");}.bind(this),error:function(xmlHttpRequest,textStatus,errorThrown)
{GEvent.trigger(this.map,"ajax.surroundingDestinations.error");GEvent.trigger(this.map,"data_load_error","LoadManager",xmlHttpRequest,textStatus,errorThrown);}.bind(this)});},on_data_load:function(data,excludes)
{var loadManager=this;data.destinations=$.map(data.destinations,function(destination)
{return loadManager.massageLoadedItem(destination);});data.destinations=$.grep(data.destinations,function(destination){return destination.point});this.expandDestinationCache(data.destinations);data.destinations=data.destinations.concat(excludes);if(this.map.getZoom()==2)
{var new_dests=[];$.each(data.destinations,function(){if(this.properties.type=='continent'||this.properties.type=='root')new_dests.push(this);});data.destinations=new_dests;}
GEvent.trigger(loadManager,"load",data.destinations);},massageLoadedItem:function(item)
{var loadManager=this;if(typeof item.geometry=="undefined")
{item.point=new GLatLng(0,0);}
else if(item.geometry.type=='bbox')
{if(item.geometry.coordinates[0]=="0"&&item.geometry.coordinates[1]=="0"&&item.geometry.coordinates[2]=="0"&&item.geometry.coordinates[3]=="0")
{GEvent.trigger(loadManager.map,"missing_data",item);return null;}
else
{item.latLngBounds=new GLatLngBounds(new GLatLng(item.geometry.coordinates[2],item.geometry.coordinates[3]),new GLatLng(item.geometry.coordinates[0],item.geometry.coordinates[1]));item.point=item.latLngBounds.getCenter();item.properties.num_pois=loadManager.countDestinationPois(item);}}
else if(item.geometry.type=='Point')
{if(!item.geometry.coordinates||(item.geometry.coordinates[0]=="0"&&item.geometry.coordinates[1]=="0"))
{GEvent.trigger(loadManager.map,"missing_data",item);return null;}
else
{item.point=new GLatLng(item.geometry.coordinates[1],item.geometry.coordinates[0]);}}
if(item.properties.pois)
{item.properties.pois=$.grep(item.properties.pois,function(poi)
{if(poi.geometry.coordinates[0]=="0"&&poi.geometry.coordinates[1]=="0")
GEvent.trigger(loadManager.map,"missing_data",poi);return(!(poi.geometry.coordinates[0]=="0"&&poi.geometry.coordinates[1]=="0"));});$.each(item.properties.pois,function()
{this.point=new GLatLng(this.geometry.coordinates[1],this.geometry.coordinates[0]);this.destination=item;});item.properties.pois_by_type={};$.each(lp.maps.Config.supported_poi_types,function(type)
{item.properties.pois_by_type[type]=[];});$.each(item.properties.pois,function()
{item.properties.pois_by_type[this.properties.type].push(this);});item.properties.pois=null;}
else
{item.properties.pois_by_type=null;}
if(item.properties.destinations)
{item.properties.destinations=$.grep(item.properties.destinations,function(destination){if(destination.geometry.coordinates[0]=="0"&&destination.geometry.coordinates[1]=="0"&&destination.geometry.coordinates[2]=="0"&&destination.geometry.coordinates[3]=="0")
{GEvent.trigger(loadManager.map,"missing_data",destination);}
return(!(destination.geometry.coordinates[0]=="0"&&destination.geometry.coordinates[1]=="0"&&destination.geometry.coordinates[2]=="0"&&destination.geometry.coordinates[3]=="0"));});$.each(item.properties.destinations,function(){var bounds=new GLatLngBounds(new GLatLng(this.geometry.coordinates[2],this.geometry.coordinates[3]),new GLatLng(this.geometry.coordinates[0],this.geometry.coordinates[1]));this.latLngBounds=bounds;this.point=bounds.getCenter();this.properties.num_pois=loadManager.countDestinationPois(this);});}
return item;},countDestinationPois:function(destination)
{var num_pois=0;if(destination.properties.poi_categories)
{$.each(destination.properties.poi_categories,function(){num_pois+=this.total;});}
return num_pois;},boundsToLoad:function(bounds)
{var pre_pan=0.25;var north=bounds.getNorthEast().lat();var east=bounds.getNorthEast().lng();var south=bounds.getSouthWest().lat();var west=bounds.getSouthWest().lng();var pan_north=north+((north-south)*pre_pan);var pan_east=east+((east-west)*pre_pan);var pan_south=south-((north-south)*pre_pan);var pan_west=west-((east-west)*pre_pan);pan_north=(pan_north>90)?90:pan_north;pan_east=(pan_east>180)?180:pan_east;pan_south=(pan_south<-90)?-90:pan_south;pan_west=(pan_west<-180)?-179.999999:pan_west;return new GLatLngBounds(new GLatLng(pan_south,pan_west),new GLatLng(pan_north,pan_east));},getPoiTypes:function()
{return(lp.maps.Config.poitypes.length==0)?'SupressPoiCategories':lp.maps.Config.poitypes.join(',');}});lp.maps.MarkerManager=function(map){this.initialize(map);};$.extend(lp.maps.MarkerManager.prototype,{initialize:function(map)
{var markerManager=this;this.map=map;this.destinations=[];this.destination_pois={};this.availableMarkers={};this.hiddenDestinationMarkers={};this.current_markers={POI:{},Destination:{}};this.current_featured_markers={POI:{},Destination:{}};markerManager.previous_poi_types={};$.each(lp.maps.Config.poitypes,function(){markerManager.previous_poi_types[this]=true;});this.setupIWindowEvents();},setDestinations:function(destinations)
{var markerManager=this;var dest_hash={};$.each(destinations,function(){dest_hash[this.properties.id]=this});var old_dest_hash={};$.each(this.destinations,function(){old_dest_hash[this.properties.id]=this;});$.each(this.destinations,function()
{if(!dest_hash[this.properties.id])
{markerManager.removeDestination(this);}});$.each(destinations,function()
{if(!old_dest_hash[this.properties.id])
{markerManager.addDestination(this);}
else
{markerManager.reloadDestination(this);}});this.hideUnnecessaryDestinationMarkers();markerManager.previous_poi_types={};$.each(lp.maps.Config.poitypes,function(){markerManager.previous_poi_types[this]=true;});},addDestination:function(destination,onlynew)
{var markerManager=this;if(destination.properties.pois_by_type)
{if(!markerManager.destination_pois[destination.properties.id])
{markerManager.destination_pois[destination.properties.id]={};$.each(lp.maps.Config.supported_poi_types,function(i)
{markerManager.destination_pois[destination.properties.id][i]={};});}
$.each(lp.maps.Config.poitypes,function()
{var poi_type=this;$.each(destination.properties.pois_by_type[poi_type],function()
{markerManager.destination_pois[destination.properties.id][poi_type][this.properties.id]=this;markerManager.addItemMarker(this);});});}
if(destination.properties.destinations)
{$.each(destination.properties.destinations,function()
{markerManager.addItemMarker(this);});}
this.destinations.push(destination);},removeDestination:function(destination)
{var markerManager=this;$.each(markerManager.destination_pois[destination.properties.id],function(poi_type)
{$.each(markerManager.destination_pois[destination.properties.id][poi_type],function(id,item)
{markerManager.removeItemMarker(item);});});delete markerManager.destination_pois[destination.properties.id];if(destination.properties.destinations)
{$.each(destination.properties.destinations,function()
{markerManager.removeItemMarker(this);});}
var new_destinations=[];$.each(this.destinations,function(){if(this.properties.id!=destination.properties.id)new_destinations.push(this);});this.destinations=new_destinations;},reloadDestination:function(destination)
{var markerManager=this;var current_poi_types={};$.each(lp.maps.Config.poitypes,function(){current_poi_types[this]=true;});var old_and_new_poi_types={};$.each(current_poi_types,function(type){old_and_new_poi_types[type]=true;});$.each(markerManager.previous_poi_types,function(type){old_and_new_poi_types[type]=true;});$.each(old_and_new_poi_types,function(type)
{if(current_poi_types[type]&&!markerManager.previous_poi_types[type])
{$.each(destination.properties.pois_by_type[type],function()
{markerManager.destination_pois[destination.properties.id][type][this.properties.id]=this;markerManager.addItemMarker(this);});}
else if(!current_poi_types[type]&&markerManager.previous_poi_types[type])
{$.each(markerManager.destination_pois[destination.properties.id][type],function(id,item)
{markerManager.removeItemMarker(item);});markerManager.destination_pois[destination.properties.id][type]={};}
else if(current_poi_types[type]&&markerManager.previous_poi_types[type])
{}});},addItemMarker:function(item)
{if(!this.current_markers[item.type][item.properties.id])
{var marker=this.nextMarker(item);marker.show();if(this.openedMarker&&item.properties.id==this.openedMarker.properties.id)marker.showIWindow();this.current_markers[item.type][item.properties.id]=marker;}},addFeaturedItemMarker:function(item)
{if(!this.current_featured_markers[item.type][item.properties.id])
{var marker=this.nextMarker(item);marker.show();if(this.openedMarker&&item.properties.id==this.openedMarker.properties.id)marker.showIWindow();this.current_featured_markers[item.type][item.properties.id]=marker;}},removeItemMarker:function(item)
{if(this.current_markers[item.type][item.properties.id])
{var marker=this.current_markers[item.type][item.properties.id];if(this.openedMarker&&item.properties.id==this.openedMarker.properties.id)marker.hideIWindow();marker.hide();this.availableMarkers[marker.markerType][marker.size].push(marker);if(this.hiddenDestinationMarkers)delete this.hiddenDestinationMarkers[item.properties.id];this.current_markers[item.type][item.properties.id]=null;}},removeFeaturedItemMarker:function(item)
{if(this.current_featured_markers[item.type][item.properties.id])
{var marker=this.current_featured_markers[item.type][item.properties.id];if(this.openedMarker&&item.properties.id==this.openedMarker.properties.id)marker.hideIWindow();marker.hide();this.availableMarkers[marker.markerType][marker.size].push(marker);if(this.hiddenDestinationMarkers)delete this.hiddenDestinationMarkers[item.properties.id];this.current_featured_markers[item.type][item.properties.id]=null;}},nextMarker:function(item)
{var markerType=(item.type=='POI')?this.validate_icon(item.properties.type):item.type;var markerSize=((lp.maps.Config.featured_items[item.properties.id]&&!lp.maps.Config.displayFeature)||item.featured)?'large':'small';var display_noBubble=(lp.maps.Config.noBubbles[item.properties.id]);if(!this.availableMarkers[markerType])this.availableMarkers[markerType]={};if(!this.availableMarkers[markerType][markerSize])this.availableMarkers[markerType][markerSize]=[];if(this.availableMarkers[markerType][markerSize].length==0)
{var marker=new lp.maps.Marker(item.point,{type:markerType,size:markerSize,data:item,noBubble:display_noBubble});marker.markerType=markerType;marker.size=markerSize;this.map.addOverlay(marker);marker.hide();}
else
{var marker=this.availableMarkers[markerType][markerSize].pop();marker.setLatLng(item.point);marker.setData(item);}
return marker;},hideUnnecessaryDestinationMarkers:function()
{var markerManager=this;var dest_hash={};$.each(this.destinations,function(){dest_hash[this.properties.id]=this});$.each(this.hiddenDestinationMarkers,function()
{if(!dest_hash[this.data.properties.id])
{this.show();delete markerManager.hiddenDestinationMarkers[this.data.properties.id];}
else
{}});$.each(this.destinations,function(){if(this.properties.destinations)
{$.each(this.properties.destinations,function()
{if(dest_hash[this.properties.id]&&(dest_hash[this.properties.id].properties.num_pois>0||dest_hash[this.properties.id].properties.destinations.length>0))
{var marker=markerManager.current_markers.Destination[this.properties.id];marker.hide();markerManager.hiddenDestinationMarkers[this.properties.id]=marker;}});}});},validate_icon:function(type_icon)
{return(lp.maps.Config.supported_poi_types[type_icon])?type_icon:'OTHER';},setupIWindowEvents:function()
{GEvent.addListener(this.map,"infowindowopen",function(data)
{this.openedMarker=data;}.bind(this));GEvent.addListener(this.map,"infowindowclosed",function(data)
{this.openedMarker=null;}.bind(this));}});lp.maps.AbstractController=function(){this.initialize();};$.extend(lp.maps.AbstractController.prototype,{initialize:function()
{},run:function()
{},triggerLoaded:function(data)
{lp.maps.Map2.LOADED=true;GEvent.trigger(this.map,"dataloaded",data);}});lp.maps.AbstractPanDestController=function(map){this.initialize(map);};$.extend(lp.maps.AbstractPanDestController.prototype,lp.maps.AbstractController.prototype);$.extend(lp.maps.AbstractPanDestController.prototype,{initialize:function(map)
{this.map=map;this.loadManager=new lp.maps.LoadManager(this.map);this.markerManager=new lp.maps.MarkerManager(this.map);this.dynamicEnabled=null;GEvent.addListener(this.loadManager,"load",this.onDataLoad.bind(this));GEvent.addListener(map,"dataload",this.run.bind(this));GEvent.addListener(map,"show_item",function(item){this.zoomToItem(item);}.bind(this));GEvent.addListener(map,"marker_click",this.markerClick.bind(this));GEvent.addListener(map,"showitem",this.handle_show_item.bind(this));},setDynamic:function(bool)
{if(bool&&!this.dynamicEnabled)
{this.dynamicEnabled=GEvent.addListener(this.map,"moveend",this.run.bind(this));this.run();}
else if(!bool&&this.dynamicEnabled)
{GEvent.removeListener(this.dynamicEnabled);this.dynamicEnabled=null;this.run();}},run:function()
{if(this.dynamicEnabled)
{this.dynamicLoad();}
else
{this.staticLoad();}},staticLoad:function()
{},dynamicLoad:function()
{this.loadManager.load(this.map.getBounds(),this.map.getZoom());},onDataLoad:function(destinations)
{this.markerManager.setDestinations(destinations);if(lp.maps.Cache.poitypecontrol)
{var loaded=false;$.each(destinations,function(){if(this.properties.id==lp.maps.Cache.poitypecontrol.data.properties.id)loaded=true;});if(!loaded)this.setPOITypeControl(false);}},zoomToItem:function(marker)
{var marker_data=marker.data;if(marker_data.type=='POI')
{this.map.setCenter(marker_data.point,lp.maps.Config.poizoom);lp.maps.Cache.iwindow.show(marker);}
else
{var pos_info=this.getDestinationZoom(marker_data);this.map.setCenter(pos_info[0],pos_info[1]);if(!this.dynamicEnabled)
{this.setDynamic((marker_data.properties.type!='world'&&marker_data.properties.type!='continent'));}
if(!this.dynamicEnabled)
{lp.maps.Config.initdata={id:marker_data.properties.id};}
this.setPOITypeControl((marker_data.properties.num_pois>0),marker_data);if(!this.dynamicEnabled)this.run();}},markerClick:function(item)
{if(item.type=='POI')
{this.setPOITypeControl(true,item.destination);}},handle_show_item:function(item)
{},setPOITypeControl:function(bool,destination)
{if(bool)
{if(!lp.maps.Cache.poitypecontrol)
{lp.maps.Cache.poitypecontrol=new lp.maps.POITypeControl();this.map.addControl(lp.maps.Cache.poitypecontrol);}
GEvent.trigger(lp.maps.Cache.poitypecontrol,"refresh",destination);}
else
{if(lp.maps.Cache.poitypecontrol)
{this.map.removeControl(lp.maps.Cache.poitypecontrol);if(lp.maps.Config.poitypes.length==0)
{lp.maps.Config.poitypes.push("SIGHTS");}
lp.maps.Cache.poitypecontrol=null;}
if(lp.maps.Config.poitypes.length==0)lp.maps.Config.poitypes=["SIGHTS"];}},getDestinationZoom:function(destination)
{if(destination.properties.destinations&&destination.properties.destinations.length>=4)
{var bounds=new GLatLngBounds();$.each(destination.properties.destinations,function()
{if(destination.latLngBounds.containsLatLng(this.point))bounds.extend(this.point);});if(bounds.isEmpty())
{return[destination.latLngBounds.getCenter(),this.map.getBoundsZoomLevel(destination.latLngBounds)];}
return[bounds.getCenter(),this.map.getBoundsZoomLevel(bounds)];}
else
{var zoomLevel=this.map.getBoundsZoomLevel(destination.latLngBounds);while(!this.loadManager.isDestinationVisible(destination,zoomLevel)){zoomLevel=zoomLevel+1;};if(destination.properties.title=='Canada'||destination.properties.title=='Russia')zoomLevel++;return[destination.latLngBounds.getCenter(),zoomLevel];}}});lp.maps.AbstractDestinationAppController=function(map){this.initialize(map);};$.extend(lp.maps.AbstractDestinationAppController.prototype,lp.maps.AbstractPanDestController.prototype);$.extend(lp.maps.AbstractDestinationAppController.prototype,{url_for:function(type,initdata)
{if(type=='destination')
{return lp.maps.Config.dataserver+type+'/'+initdata.id
+'/GetDestinationChildren/GetPoiCategories/'+lp.maps.Config.poitypes.join(',')+'.json';}
else if(type=='poi')
{return lp.maps.Config.dataserver+type+'/'+initdata.id+'.json';}},setCenter:function(items,feature)
{var controller=this;var found_feature=false;var outerbox={n:'',e:'',s:'',w:''};var north,east,west,south;$.each(items,function()
{if(this.type.toLowerCase()=="destination"){north=this.geometry.coordinates[0];east=this.geometry.coordinates[1];south=this.geometry.coordinates[2];west=this.geometry.coordinates[3];if(east<west){var tmpbounds=new GLatLngBounds(new GLatLng(south,west),new GLatLng(north,east));east=179.99;if(tmpbounds.getCenter().lng()<west){west=tmpbounds.getCenter().lng();}}}else if(this.type.toLowerCase()=="poi"){north=this.point.lat();east=this.point.lng();south=this.point.lat();west=this.point.lng();}
outerbox.n=(north>outerbox.n||outerbox.n=='')?north:outerbox.n;outerbox.e=(east>outerbox.e||outerbox.e=='')?east:outerbox.e;outerbox.s=(south<outerbox.s||outerbox.s=='')?south:outerbox.s;outerbox.w=(west<outerbox.w||outerbox.w=='')?west:outerbox.w;if(feature&&(typeof feature.properties=="object"))
{if(feature.properties.id==this.properties.id)
{if(feature.type=="poi")
{controller.map.setCenter(this.point,lp.maps.Config.poizoom);}
else if(feature.type=="destination")
{var destinationbounds=new GLatLngBounds(new GLatLng(this.geometry.coordinates[2],this.geometry.coordinates[3]),new GLatLng(this.geometry.coordinates[0],this.geometry.coordinates[1]));controller.map.setCenter(destinationbounds.getCenter(),controller.map.getBoundsZoomLevel(destinationbounds));}
found_feature=true;}}});if(found_feature)
{return;}
var bounds=new GLatLngBounds(new GLatLng(outerbox.s,outerbox.w),new GLatLng(outerbox.n,outerbox.e));if(bounds.getSouthWest().toString()==bounds.getNorthEast().toString())
{return;}
this.map.setCenter(bounds.getCenter(),this.map.getBoundsZoomLevel(bounds));try
{var too_close=lp.maps.Config.cluster_zoom;var bounds_height=bounds.getNorthEast().lat()-bounds.getSouthWest().lat();var maps_height=this.map.getBounds().getNorthEast().lat()-this.map.getBounds().getSouthWest().lat();var percent=(bounds_height/maps_height)*100;if(percent>too_close){this.map.zoomOut();}}
catch(err)
{}}});lp.maps.POIController=function(map){this.initialize(map);};$.extend(lp.maps.POIController.prototype,lp.maps.AbstractDestinationAppController.prototype);$.extend(lp.maps.POIController.prototype,{initialize:function(map)
{lp.maps.AbstractDestinationAppController.prototype.initialize.call(this,map);lp.maps.Config.initdata.id=lp.maps.Config.initdata.destination;lp.maps.Config.poitypes=[lp.maps.Config.initdata.poitype];lp.maps.Config.featured_items={};lp.maps.Config.featured_items[lp.maps.Config.initdata.poi]=lp.maps.Config.initdata.poi;},staticLoad:function()
{this.loadManager.manualItemLoad(this.url_for('destination',lp.maps.Config.initdata),function(data)
{if(!data.properties.pois_by_type)return;var featured=null;$.each(lp.maps.Config.poitypes,function()
{$.each(data.properties.pois_by_type[this],function()
{if(this.properties.id==lp.maps.Config.initdata.poi)featured=this;});});if(typeof(lp.maps.Cache.poitypecontrol)=="undefined")
{if(!featured)
{var list=[];$.each(lp.maps.Config.poitypes,function()
{list=list.concat(data.properties.pois_by_type[this]);});this.setCenter(list);}
else
{this.map.setCenter(featured.point,lp.maps.Config.poizoom,lp.maps.Config.supported_maptypes[lp.maps.Config.maptype].type);this.markerManager.openedMarker=featured;}}
this.setDynamic(true);this.setPOITypeControl(true,data);}.bind(this));}});lp.maps.DestinationController=function(map){this.initialize(map);};$.extend(lp.maps.DestinationController.prototype,lp.maps.AbstractDestinationAppController.prototype);$.extend(lp.maps.DestinationController.prototype,{staticLoad:function()
{this.loadManager.manualItemLoad(this.url_for('destination',lp.maps.Config.initdata),function(data)
{if(!this.map.isLoaded())
{this.map.setCenter(new GLatLng(0,0));var pos_info=lp.maps.Config.destinationzoom?[data.point,lp.maps.Config.destinationzoom]:this.getDestinationZoom(data);this.map.setCenter(pos_info[0],pos_info[1],lp.maps.Config.supported_maptypes[lp.maps.Config.maptype].type);}
this.setDynamic(true);this.setPOITypeControl((data.properties.num_pois>0),data);}.bind(this));}});lp.maps.AbstractPlanningController=function(map){this.initialize(map);};$.extend(lp.maps.AbstractPlanningController.prototype,lp.maps.AbstractDestinationAppController.prototype);$.extend(lp.maps.AbstractPlanningController.prototype,{staticLoad:function()
{},handle_show_item:function(data)
{lp.maps.Config.initdata=data;this.staticLoad();},removeFeaturedItems:function()
{var controller=this;$.each(lp.maps.Config.featured_items,function()
{controller.markerManager.removeFeaturedItemMarker(this);});lp.maps.Config.featured_items={};lp.maps.Config.noBubbles={};},addFeaturedItems:function(items)
{var controller=this;$.each(items,function(){lp.maps.Config.featured_items[this.properties.id]=this;lp.maps.Config.noBubbles[this.properties.id]=this;this.featured=true;controller.markerManager.addFeaturedItemMarker(this);});}});lp.maps.FavouritesController=function(map){this.initialize(map);};$.extend(lp.maps.FavouritesController.prototype,lp.maps.AbstractPlanningController.prototype);$.extend(lp.maps.FavouritesController.prototype,{staticLoad:function()
{this.loadManager.manualItemLoad(this.url_for(lp.maps.Config.initdata.type,lp.maps.Config.initdata),function(data)
{if(!this.map.isLoaded())
{this.map.setCenter(new GLatLng(0,0),1,lp.maps.Config.supported_maptypes[lp.maps.Config.maptype].type);}
else
{this.removeFeaturedItems();}
if(typeof data.point=='undefined')
{return;}
this.addFeaturedItems([data]);var pos_info=(data.type=="Destination")?this.getDestinationZoom(data):[data.point,lp.maps.Config.poizoom];this.map.setCenter(pos_info[0],pos_info[1],lp.maps.Config.supported_maptypes[lp.maps.Config.maptype].type);}.bind(this));},url_for:function(type,initdata)
{if(type=='destination')
{return lp.maps.Config.dataserver+type+'/'+initdata.properties.id
+'/SupressDestinationChildren/SupressPoiCategories/.json';}
else
{return lp.maps.Config.dataserver+type+'/'+initdata.properties.id+'.json';}},markerClick:function(item)
{}});lp.maps.TripPlannerController=function(map){this.initialize(map);};$.extend(lp.maps.TripPlannerController.prototype,lp.maps.AbstractPlanningController.prototype);$.extend(lp.maps.TripPlannerController.prototype,{staticLoad:function(feature)
{this.loadManager.manualItemLoad(this.url_for(),function(data)
{if(typeof(feature)=="undefined")
{feature={center:true};}
this.removeFeaturedItems();var featured_items=[];if(data.properties.pois_by_type)
{$.each(lp.maps.Config.supported_poi_types,function(type)
{featured_items=featured_items.concat(data.properties.pois_by_type[type]);});featured_items=featured_items.concat(data.properties.destinations);}
else
{featured_items=data.properties.destinations;}
if(featured_items.length==0&&feature.center)
{this.map.setCenter(new GLatLng(0,0),1,lp.maps.Config.supported_maptypes[lp.maps.Config.maptype].type);}
else
{if(feature.center)
{if(featured_items.length==1)
{feature={type:(featured_items[0].type.toLowerCase()=='poi')?'poi':'destination',properties:{id:featured_items[0].properties.id},center:true};}
this.setCenter(featured_items,feature);}}
this.addFeaturedItems(featured_items);this.setDynamic(true);}.bind(this));},url_for:function()
{var url=lp.maps.Config.dataserver+"destinationsAndPois.json?";url+="destIds="+lp.maps.Config.initdata.destinations;url+="&poiIds="+lp.maps.Config.initdata.pois;return url;},handle_show_item:function(feature)
{this.staticLoad(feature);},markerClick:function(item)
{if(item.type=='POI'&&!item.featured)
{this.setPOITypeControl(true,item.destination);}}});lp.maps.Marker=function(point,opts){this.run_init(point,opts);};lp.maps.Marker.create=function()
{$.extend(lp.maps.Marker.prototype,GMarker.prototype);$.extend(lp.maps.Marker.prototype,{run_init:function(point,opts)
{this.opts=opts;this.setData(opts.data);this.setupIcon();this.inheritFrom=GMarker;this.inheritFrom(point,$.extend(opts,{zIndexProcess:this.zIndexFunction.bind(this)}));GEvent.addListener(this,"mouseover",this.showTooltip.bind(this));GEvent.addListener(this,"mouseout",this.hideTooltip.bind(this));if(!this.opts.noBubble&&!lp.maps.Config.noBubble)
{GEvent.addListener(this,"click",this.showIWindow.bind(this));}
GEvent.addListener(this,"click",function()
{GEvent.trigger(this.map,"marker_click",this.data);}.bind(this));},setData:function(data)
{this.data=data;},setupIcon:function()
{var icon=new GIcon();this.icon_options=lp.maps.Config.icons.options[this.opts.type][this.opts.size];icon.image=lp.maps.Config.cdnUrl+'assets/images/markers/'+lp.maps.Config.icons[this.opts.size][this.opts.type];icon.iconSize=new GSize(this.icon_options.w,this.icon_options.h);icon.shadow=lp.maps.Config.cdnUrl+'assets/images/markers/'+this.icon_options.shadow;icon.shadowSize=new GSize(this.icon_options.shadow_w,this.icon_options.shadow_h);icon.iconAnchor=new GPoint(this.icon_options.w/2,this.icon_options.h);icon.infoWindowAnchor=new GPoint(0,0);this.opts.icon=icon;},showIWindow:function()
{if(!lp.maps.Cache.iwindow)
{lp.maps.Cache.iwindow=new lp.maps.IWindow(this.map);this.map.addOverlay(lp.maps.Cache.iwindow);}
lp.maps.Cache.iwindow.show(this);this.hideTooltip();},hideIWindow:function()
{lp.maps.Cache.iwindow.hide();},showTooltip:function()
{if(!lp.maps.Cache.tooltip)
{lp.maps.Cache.tooltip=document.createElement('div');$(lp.maps.Cache.tooltip).addClass('tooltip');this.map.getPane(G_MAP_FLOAT_PANE).appendChild(lp.maps.Cache.tooltip);}
lp.maps.Cache.tooltip.innerHTML="<nobr>"+this.data.properties.title+"</nobr>";var offset=this.map.fromLatLngToDivPixel(this.getPoint());var anchor=this.getIcon().iconAnchor;var isize=this.getIcon().iconSize;var newpos=new GSize(offset.x-anchor.x+isize.width+2,offset.y-isize.height+(this.icon_options.overlay_anchor/2));var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,newpos);pos.apply(lp.maps.Cache.tooltip);$(lp.maps.Cache.tooltip).show();},hideTooltip:function()
{if(lp.maps.Cache.tooltip){$(lp.maps.Cache.tooltip).hide();}},html:function()
{var properties=this.data.properties;var displayZoom=this._displayZoomHere();var doesntHaveFeaturedItems=!lp.maps.Config.featured_items[properties.id];return'<span class="title">'+properties.title+'</span>'
+'<p class="poidescription">'
+(properties.address?'<strong>Address:</strong> '+properties.address+'<br />':'')
+(properties.description?'<span class="description">'+properties.description+'</span>':'')
+'</p>'
+'<table class="linkstable"><tr><td>'
+((doesntHaveFeaturedItems)?'<a class="linkChevron" href="'+properties.link+'">Read more</a>':'')
+'</td><td>'
+((displayZoom)?'<a class="linkChevron action" rel="zoom" href="#">Zoom here</a>':'')
+'</td></tr></table>';},_displayZoomHere:function()
{if(this.data.type=="Destination"&&this.data.properties.type=="sub_country"){var destinationbounds=this.data.latLngBounds;return!(this.map.getBoundsZoomLevel(destinationbounds)<=this.map.getZoom());}else if((this.data.type==='POI')&&(this.map.getZoom()>=lp.maps.Config.poizoom)){return false;}
return true;},zIndexFunction:function(marker,b)
{return GOverlay.getZIndex(marker.getPoint().lat());}});};lp.maps.MapTypeControl=function(){this.run_init();};lp.maps.MapTypeControl.create=function()
{$.extend(lp.maps.MapTypeControl.prototype,GControl.prototype);$.extend(lp.maps.MapTypeControl.prototype,{run_init:function()
{this.inheritFrom=GControl;this.inheritFrom();},initialize:function(map)
{this.map=map;var html='<ul class="maptype" id="maptype_unordered_list">';$.each(lp.maps.Config.maptypes,function(i,item){var liclass=(i==(lp.maps.Config.maptypes.length-1))?' class="last"':'';html+='<li'+liclass+'><a class="maptype_link" rel="'+item+'" href="#">'
+lp.maps.Config.supported_maptypes[item].name+'</a></li>';});html+='</ul>';var container=document.createElement('div');$(container).addClass('outer_maptype_container').append(html);map.getContainer().appendChild(container);var maptypecontrol=this;$('#maptype_unordered_list .maptype_link').click(function()
{map.setMapType(lp.maps.Config.supported_maptypes[$(this).attr('rel')].type);maptypecontrol.updateForMapType();return false;});GEvent.addListener(map,'maptypechanged',this.updateForMapType.bind(this));return container;},getDefaultPosition:function(){return new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,10));},printable:function(){return true;},selectable:function(){return false;},updateForMapType:function(){$('#maptype_unordered_list .maptype_link').removeClass('selected');var maptypecontrol=this;$('#maptype_unordered_list .maptype_link').each(function(i,item)
{if(lp.maps.Config.supported_maptypes[$(item).attr('rel')].type==maptypecontrol.map.getCurrentMapType())
$(item).addClass('selected');});}});};lp.maps.ZoomControl=function(){this.run_init();};lp.maps.ZoomControl.create=function()
{$.extend(lp.maps.ZoomControl.prototype,GControl.prototype);$.extend(lp.maps.ZoomControl.prototype,{run_init:function()
{this.inheritFrom=GControl;this.inheritFrom();},initialize:function(map)
{var html='<img class="map_zoombtn" id="map_zoomin" src="'+lp.maps.Config.cdnUrl+'assets/images/controls/zoom-in.gif" alt="" /><br />'
+'<img class="map_zoombtn" id="map_zoomout" src="'+lp.maps.Config.cdnUrl+'assets/images/controls/zoom-out.gif" alt="" />';var container=document.createElement('div');$(container).addClass('outer_zoom_container').append(html);$(container).width(17);$(container).height(36);map.getContainer().appendChild(container);$('#map_zoomin').click(function()
{map.zoomIn();return false;});$('#map_zoomout').click(function()
{map.zoomOut();return false;});return container;},getDefaultPosition:function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(10,10));},printable:function(){return true;},selectable:function(){return false;}});};lp.maps.POITypeControl=function(){this.run_init();};lp.maps.POITypeControl.create=function()
{$.extend(lp.maps.POITypeControl.prototype,GControl.prototype);$.extend(lp.maps.POITypeControl.prototype,{run_init:function()
{this.inheritFrom=GControl;this.inheritFrom();},initialize:function(map)
{var html='<ul class="poitype">';$.each(lp.maps.Config.supported_poi_types,function(i,item)
{html+='<li title="Show '+item+'"><input type="checkbox" class="poi_type_checkbox" id="poi_checkbox_'+i+'"/> '+item
+' (<span id="poi_type_num_'+i+'">0</span>)</li>';});html+='</ul>';var container=document.createElement('div');$(container).addClass('outer_poitype_container').append(html);map.getContainer().appendChild(container);$.each(lp.maps.Config.poitypes,function(i,item)
{$('#poi_checkbox_'+item).trigger("click");});$.each(lp.maps.Config.supported_poi_types,function(i,item)
{$('#poi_checkbox_'+i).click(function()
{lp.maps.Config.poitypes=[];$.each(lp.maps.Config.supported_poi_types,function(j,item2)
{if($('#poi_checkbox_'+j).get(0).checked){lp.maps.Config.poitypes.push(j);}});GEvent.trigger(map,"dataload");});});GEvent.addListener(this,"refresh",function(data){if(data)
{if(typeof data.properties.poi_categories!="undefined")
{$.each(data.properties.poi_categories,function()
{$("#"+'poi_type_num_'+this.type).html(this.total);});}}
this.data=data;});return container;},getDefaultPosition:function(){return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT,new GSize(10,15));},printable:function(){return true;},selectable:function(){return false;}});};lp.maps.ThrobberControl=function(){this.run_init();};lp.maps.ThrobberControl.create=function()
{$.extend(lp.maps.ThrobberControl.prototype,GControl.prototype);$.extend(lp.maps.ThrobberControl.prototype,{run_init:function()
{this.inheritFrom=GControl;this.inheritFrom();},initialize:function(map)
{this.map=map;this.displayEventStack=[];var throbberDiv=document.createElement('div');throbberDiv.id="map_throbber";map.getContainer().appendChild(throbberDiv);this.throbber=throbberDiv;GEvent.addListener(this.map,"zoominstart",function()
{this.processZoomEvent();}.bind(this));GEvent.addListener(this.map,"zoomoutstart",function()
{this.processZoomEvent();}.bind(this));GEvent.addListener(this.map,"tilesloaded",function()
{this.hideSlow();}.bind(this));GEvent.addListener(this.map,"ajax.surroundingDestinations.start",function()
{this.show();}.bind(this));GEvent.addListener(this.map,"ajax.surroundingDestinations.success",function()
{this.hideSlow();}.bind(this));GEvent.addListener(this.map,"ajax.surroundingDestinations.error",function()
{this.hideSlow();}.bind(this));return throbberDiv;},getDefaultPosition:function()
{var parent=$(this.throbber.parentNode);var left=(parent.width()-$(this.throbber).width())/2;var top=(parent.height()-$(this.throbber).height())/2;return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(left,top));},printable:function()
{return false;},selectable:function()
{return false;},processMoveEvent:function()
{this.show();var listener=GEvent.addListener(this.map,"moveend",function(){this.hideFast();GEvent.removeListener(listener);}.bind(this));},processZoomEvent:function()
{this.show();var listener=GEvent.addListener(this.map,"zoomend",function(){this.hideFast();GEvent.removeListener(listener);}.bind(this));},show:function()
{this.displayEventStack.push("");$(this.throbber).show();},hideSlow:function()
{this.hide(300);},hideFast:function()
{this.hide();},hide:function(timeout)
{this.displayEventStack.pop();if(this.displayEventStack.length>0){return;}
if(timeout){setTimeout(function(){$(this.throbber).fadeOut("slow");}.bind(this),timeout);}else{$(this.throbber).hide();}}});};lp.maps.IWindow=function(){this.run_init();};lp.maps.IWindow.create=function()
{$.extend(lp.maps.IWindow.prototype,GOverlay.prototype);$.extend(lp.maps.IWindow.prototype,{run_init:function()
{this.inheritFrom=GOverlay;this.inheritFrom();},initialize:function(map)
{this.map=map;this.div=document.createElement('div');$(this.div).html('<div class="iwindow_content" id="lp_iwindow">'
+'<img class="close_btn" src="'+lp.maps.Config.cdnUrl+'assets/images/bubble/info-close.gif" alt="" />'
+'<img class="callout bottom" src="'+lp.maps.Config.cdnUrl+'assets/images/bubble/info-callout-bottom.gif" alt="" />'
+'<img class="callout top" src="'+lp.maps.Config.cdnUrl+'assets/images/bubble/info-callout-top.gif" alt="" />'
+'<img class="callout left" src="'+lp.maps.Config.cdnUrl+'assets/images/bubble/info-callout-left.gif" alt="" />'
+'<img class="callout right" src="'+lp.maps.Config.cdnUrl+'assets/images/bubble/info-callout-right.gif" alt="" />'
+'<div id="lp_iwindow_content"></div></div>');$(this.div).addClass('iwindow');this.map.getPane(G_MAP_FLOAT_PANE).appendChild(this.div);this.callout_offset=20;this.callout_align=37;$('#lp_iwindow img.close_btn').click(this.hide.bind(this));this.point=this.map.getCenter();this.offset=this.map.getCenter();},show:function(marker)
{this.offset=this.offsetForMarker(marker);this.point=marker.getPoint();this.icon_options=marker.icon_options;this.data=marker.data;$(this.div).css('zIndex',GOverlay.getZIndex(this.point.lat()));$('#lp_iwindow_content').html(marker.html());$('#lp_iwindow img.bottom').css('left',Math.floor(($(this.div).width()-this.callout_align)/2));$('#lp_iwindow img.top').css('left',Math.floor(($(this.div).width()-this.callout_align)/2));$('#lp_iwindow img.left').css('top',Math.floor(($(this.div).height()-this.callout_align)/2));$('#lp_iwindow img.right').css('top',Math.floor(($(this.div).height()-this.callout_align)/2));this.redraw(true);$(this.div).show();this.handleIWindowEvents(marker);GEvent.trigger(this.map,'infowindowopen',marker.data);},hide:function()
{$(this.div).hide();GEvent.trigger(this.map,'infowindowclosed',this.data);this.data=null;},redraw:function(force,same_pos)
{if(force)
{var c=this.map.fromLatLngToContainerPixel(this.point);var off=$(this.map.getContainer()).offset();var p=this.map.fromLatLngToDivPixel(this.point);var dim={width:$(this.div).width()+2+this.callout_offset,height:$(this.div).height()+2+this.callout_offset};var mdim={width:$(this.map.getContainer()).width(),height:$(this.map.getContainer()).height()};if(!same_pos)
{this.fits_right=((c.x+this.offset.x+dim.width)<=mdim.width)&&((c.y-this.offset.y+$(this.div).height()/2+3)<=mdim.height)&&((c.y-this.offset.y-$(this.div).height()/2+3)>=0);this.fits_left=((c.x-this.offset.x-dim.width)>=0)&&((c.y-this.offset.y+$(this.div).height()/2+3)<=mdim.height)&&((c.y-this.offset.y-$(this.div).height()/2+3)>=0);this.fits_up=((c.y-this.offset.y-dim.height)>=0)&&((c.x-($(this.div).width()+2)/2)>=0)&&((c.x+($(this.div).width()+2)/2)<=mdim.width);this.fits_down=((c.y-this.offset.y+dim.height)<=mdim.height)&&((c.x-($(this.div).width()+2)/2)>=0)&&((c.x+($(this.div).width()+2)/2)<=mdim.width);}
$('#lp_iwindow img.callout').hide();if(this.fits_up)
{var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(p.x-($(this.div).width()/2)-1,p.y-$(this.div).height()-this.offset.y-this.callout_offset-2-2));$('#lp_iwindow img.bottom').show();pos.apply(this.div);}
else if(this.fits_right)
{var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(p.x+this.offset.x+this.callout_offset+2,p.y-this.offset.y-($(this.div).height()/2)+this.icon_options.overlay_anchor));$('#lp_iwindow img.left').show();pos.apply(this.div);}
else if(this.fits_left)
{var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(p.x-this.offset.x-$(this.div).width()-this.callout_offset-2,p.y-this.offset.y-($(this.div).height()/2)+this.icon_options.overlay_anchor));$('#lp_iwindow img.right').show();pos.apply(this.div);}
else if(1||this.fits_down)
{var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(p.x-($(this.div).width()/2)-1,p.y+this.callout_offset));$('#lp_iwindow img.top').show();pos.apply(this.div);}}},remove:function()
{},copy:function()
{return{};},offsetForMarker:function(marker)
{var vx=marker.getIcon().iconAnchor.x-marker.getIcon().infoWindowAnchor.x;var vy=marker.getIcon().iconAnchor.y-marker.getIcon().infoWindowAnchor.y;return new GPoint(vx,vy);},handleIWindowEvents:function(marker)
{var map=this.map;var iwindow=this;$("#lp_iwindow .action").click(function(){if($(this).attr("rel")=='zoom')
{iwindow.hide();GEvent.trigger(map,'show_item',marker)}})}});};lp.maps.TileManager=function(map){this.initialize(map);};$.extend(lp.maps.TileManager.prototype,{initialize:function(map)
{this.map=map;this.tile_bboxes=[];window['_lptile']=function(data){this.setupTileBoxes(data);}.bind(this);$.ajax({type:'GET',url:lp.maps.Config.tileBoxesUrl+'?callback=_lptile',dataType:'script',cache:true,error:function(xmlHttpRequest,textStatus,errorThrown)
{}.bind(this)});this.lplayer=new GTileLayerOverlay(new GTileLayer(new GCopyrightCollection("Lonely Planet"),12,17,{tileUrlTemplate:lp.maps.Config.tileUrl+'/{Z}/{X}/{Y}.png',isPng:true,opacity:1.0}));this.isHidden=false;GEvent.addListener(map,"load",function(){this.checkTileDisplay();GEvent.addListener(map,"moveend",this.checkTileDisplay.bind(this));GEvent.addListener(map,"maptypechanged",this.checkTileDisplay.bind(this));}.bind(this));},setupTileBoxes:function(data)
{var tile_bboxes=[];$.each(data.tiles,function(ind,val){tile_bboxes.push(new GLatLngBounds(new GLatLng(val[1],val[3]),new GLatLng(val[0],val[2])));});this.tile_bboxes=tile_bboxes;this.hide();this.checkTileDisplay();},checkTileDisplay:function()
{if(this.lplayer&&this.map.isLoaded())
{if(this.map.getCurrentMapType()!=G_NORMAL_MAP)
{this.hide();return;}
if(this.map.getZoom()<12||this.map.getZoom>17)
{this.hide();return;}
for(var i=0;i<this.tile_bboxes.length;i++)
{if(this.map.getBounds().intersects(this.tile_bboxes[i]))
{this.show();return;}}
this.hide();}},show:function()
{if(this.isHidden)
{this.map.addOverlay(this.lplayer);this.isHidden=false;}},hide:function()
{if(!this.isHidden)
{this.map.removeOverlay(this.lplayer);this.isHidden=true;}}});