
function AtlasCountryMap(projectURL,mapCanvas,polygon)
{this.projectURL=projectURL;this.mapCanvas=mapCanvas;this.polygon=polygon;this.allPoints=[];var _this=this;this.showWait();this.GoogleApiExtends();APIManager.addFunction(function(){new Ajax.Request(_this.projectURL+'ajax.get.php',{method:'get',parameters:{event:'LoadPolygonAndChilds',id:_this.polygon},onSuccess:function(transport){try{_this.polygons=transport.responseText.evalJSON();}catch(e){}
_this.initMap();if(_this.polygons)
{_this.showSurfSpot();_this.showPolygons();}}});});UnLoad.addFunction(function(){GUnload();});}
AtlasCountryMap.prototype.showWait=function()
{$(this.mapCanvas).update('<div style="text-align: center; margin-top: 50px;"><b>Please Wait. Loading...</b></div> ');}
AtlasCountryMap.prototype.initMap=function()
{this.map=new GMap2($(this.mapCanvas));this.map.addControl(new GSmallMapControl());this.map.addControl(new GMapTypeControl());this.map.enableScrollWheelZoom();this.map.setCenter(new GLatLng(0,0),1);this.markerCluster=new ClusterMarker(this.map);this.createIcons();}
AtlasCountryMap.prototype.createIcons=function()
{this.icons=[];this.icons.left_reefbreak=new GIcon(G_DEFAULT_ICON,this.projectURL+'images/icons/left_reefbreak.png');this.icons.left_reefbreak.iconSize=new GSize(25,37);this.icons.left_reefbreak.shadow=this.projectURL+'images/icons/shadow.png';this.icons.right_reefbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/right_reefbreak.png');this.icons.rightandleft_reefbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/rightandleft_reefbreak.png');this.icons.left_beachbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/left_beachbreak.png');this.icons.right_beachbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/right_beachbreak.png');this.icons.rightandleft_beachbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/rightandleft_beachbreak.png');this.icons.left_pointbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/left_pointbreak.png');this.icons.right_pointbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/right_pointbreak.png');this.icons.rightandleft_pointbreak=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/rightandleft_pointbreak.png');this.icons.left_rivermouth=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/left_rivermouth.png');this.icons.right_rivermouth=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/right_rivermouth.png');this.icons.rightandleft_rivermouth=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/rightandleft_rivermouth.png');this.icons.left_groyne_or_breakwater=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/left_groyne_or_breakwater.png');this.icons.right_groyne_or_breakwater=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/right_groyne_or_breakwater.png');this.icons.rightandleft_groyne_or_breakwater=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/rightandleft_groyne_or_breakwater.png');this.icons.shop=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/shop.png');this.icons.camp=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/camp.png');this.icons.lessons=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/lessons.png');this.icons.accom=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/accom.png');this.icons.surftrip=new GIcon(this.icons.left_reefbreak,this.projectURL+'images/icons/surftrip.png');}
AtlasCountryMap.prototype.convertPointToLatLng=function(points)
{var LatLngPoints=[];for(var i=0;i<points.length;i++)
{LatLngPoints.push(new GLatLng(points[i].lat,points[i].lng));}
return LatLngPoints;}
AtlasCountryMap.prototype.showPolygons=function()
{for(var i=0;i<this.polygons.childs.length;i++)
{this.showPolygon(this.polygons.childs[i]);}
try{var mainPoints=this.polygons.points.evalJSON();}catch(e){}
if(mainPoints)
{var mainPolyline=new GPolyline(this.convertPointToLatLng(mainPoints),this.polygons.color,3,0.4);this.map.addOverlay(mainPolyline);}
var polyline=(this.allPoints.length>0?new GPolyline(this.convertPointToLatLng(this.allPoints)):mainPolyline);if(polyline)
{this.map.setCenter(polyline.getBounds().getCenter(),this.map.getBoundsZoomLevel(polyline.getBounds()));this.allPoints=[];}}
AtlasCountryMap.prototype.showPolygon=function(pHash)
{try{var points=pHash.points.evalJSON();}catch(e){}
if(points)
{this.allPoints=this.allPoints.concat(points);var polygon=new GPolygon(this.convertPointToLatLng(points),pHash.color,1,1,pHash.color,0.2);polygon.setHash({id:pHash.id,name:pHash.name,spotcount:pHash.spotcount,surfinginfo:pHash.surfinginfo,url:pHash.url});this.map.addOverlay(polygon);_this=this;GEvent.addListener(polygon,"click",function(point){pHash=this.getHash();redirect(_this.projectURL+'atlas/'+pHash.url+'.html');});}}
AtlasCountryMap.prototype.showSurfSpot=function()
{var list=this.polygons.surfspots;var markers=[];if(list!=null)
{for(var i=0;i<list.getSize();i++)
{var icon=this.icons.left_reefbreak;if(list[i].wavedirection=='Left'&&list[i].wavetype=='Reef break')icon=this.icons.left_reefbreak;if(list[i].wavedirection=='Right'&&list[i].wavetype=='Reef break')icon=this.icons.right_reefbreak;if(list[i].wavedirection=='Right & left'&&list[i].wavetype=='Reef break')icon=this.icons.rightandleft_reefbreak;if(list[i].wavedirection=='Left'&&list[i].wavetype=='Beach break')icon=this.icons.left_beachbreak;if(list[i].wavedirection=='Right'&&list[i].wavetype=='Beach break')icon=this.icons.right_beachbreak;if(list[i].wavedirection=='Right & left'&&list[i].wavetype=='Beach break')icon=this.icons.rightandleft_beachbreak;if(list[i].wavedirection=='Left'&&list[i].wavetype=='Point break')icon=this.icons.left_pointbreak;if(list[i].wavedirection=='Right'&&list[i].wavetype=='Point break')icon=this.icons.right_pointbreak;if(list[i].wavedirection=='Right & left'&&list[i].wavetype=='Point break')icon=this.icons.rightandleft_pointbreak;if(list[i].wavedirection=='Left'&&list[i].wavetype=='Rivermouth')icon=this.icons.left_rivermouth;if(list[i].wavedirection=='Right'&&list[i].wavetype=='Rivermouth')icon=this.icons.right_rivermouth;if(list[i].wavedirection=='Right & left'&&list[i].wavetype=='Rivermouth')icon=this.icons.rightandleft_rivermouth;if(list[i].wavedirection=='Left'&&list[i].wavetype=='Breakwater / groyne')icon=this.icons.left_groyne_or_breakwater;if(list[i].wavedirection=='Right'&&list[i].wavetype=='Breakwater / groyne')icon=this.icons.right_groyne_or_breakwater;if(list[i].wavedirection=='Right & left'&&list[i].wavetype=='Breakwater / groyne')icon=this.icons.rightandleft_groyne_or_breakwater;if(list[i].wavetype=='Shop')icon=this.icons.shop;if(list[i].wavetype=='Camp')icon=this.icons.camp;if(list[i].wavetype=='Lessons')icon=this.icons.lessons;if(list[i].wavetype=='Accommodation')icon=this.icons.accom;if(list[i].wavetype=='SurfTrip')icon=this.icons.surftrip;var marker=new GMarker(new GLatLng(list[i].lat,list[i].lng),icon);marker.surfingSpotId=list[i].id*1;markers.push(marker);var _this=this;GEvent.addListener(marker,"click",function(){new Ajax.Request(_this.projectURL+'ajax.get.php',{method:'get',parameters:{event:'LoadSurfSpot',id:this.surfingSpotId},onSuccess:function(transport){try{var spotData=transport.responseText.evalJSON();}catch(e){}
if(spotData)
{_this.onLoadSurfSpotWindow(spotData);}}});});this.markerCluster.removeMarkers();this.markerCluster.addMarkers(markers);this.markerCluster.fitMapToMarkers();}}}
AtlasCountryMap.prototype.onLoadSurfSpotWindow=function(sHash)
{if(sHash)
{if(sHash.type=='success')
{var data=sHash.hash;}
if(data)
{var html='<div>'+'<div style="text-align; left;"><b>Spot name:</b><a class="minilink" style="font-weight: bold; font-size: 12px;" href="'+this.projectURL+'atlas/'+data.url+'.html"> '+data.name+'</a></div>';html+='<table cellpadding="0" cellspacing="5" border="0" style="width: auto;"><tr>';html+=(data.ImgG!=null?'<td class="imageGLItem"  valign="middle" align="center"><img src="'+data.ImgG[0].imagePR+'" alt="'+data.ImgG[0].title+'"></td>':'');html+=(data.VideoG[0]?'<td class="imageGLItem" valign="middle" align="center"><img src="'+this.projectURL+'data/datastorage/video/'+data.VideoG[0].thumb+'" alt="'+data.VideoG[0].title+'">'+'</td>':'');html+='</tr></table>';html+='</div>';this.map.openInfoWindowHtml(new GLatLng(data.lat,data.lng),html);}}}
AtlasCountryMap.prototype.GoogleApiExtends=function()
{GPolygon.prototype.setHash=function(hash)
{this.sfHash=hash;}
GPolygon.prototype.getHash=function()
{return this.sfHash;}}