// ClusterMarker.js
function ClusterMarker($map,$options){this._map=$map;this._mapMarkers=[];this._iconBounds=[];this._clusterMarkers=[];this._eventListeners=[];if(typeof($options)==="undefined"){$options={}}this.borderPadding=($options.borderPadding)?$options.borderPadding:256;this.clusteringEnabled=($options.clusteringEnabled===false)?false:true;if($options.clusterMarkerClick){this.clusterMarkerClick=$options.clusterMarkerClick}if($options.clusterMarkerIcon){this.clusterMarkerIcon=$options.clusterMarkerIcon}else{this.clusterMarkerIcon=new GIcon();this.clusterMarkerIcon.image="http://maps.google.com/mapfiles/arrow.png";this.clusterMarkerIcon.iconSize=new GSize(39,34);this.clusterMarkerIcon.iconAnchor=new GPoint(9,31);this.clusterMarkerIcon.infoWindowAnchor=new GPoint(9,31);this.clusterMarkerIcon.shadow="http://www.google.com/intl/en_us/mapfiles/arrowshadow.png";this.clusterMarkerIcon.shadowSize=new GSize(39,34)}this.clusterMarkerTitle=($options.clusterMarkerTitle)?$options.clusterMarkerTitle:"Click to zoom in and see %count markers";if($options.fitMapMaxZoom){this.fitMapMaxZoom=$options.fitMapMaxZoom}this.intersectPadding=($options.intersectPadding)?$options.intersectPadding:0;if($options.markers){this.addMarkers($options.markers)}GEvent.bind(this._map,"moveend",this,this._moveEnd);GEvent.bind(this._map,"zoomend",this,this._zoomEnd);GEvent.bind(this._map,"maptypechanged",this,this._mapTypeChanged)}ClusterMarker.prototype.addMarkers=function($markers){var i;if(!$markers[0]){var $numArray=[];for(i in $markers){$numArray.push($markers[i])}$markers=$numArray}for(i=$markers.length-1;i>=0;i--){$markers[i]._isVisible=false;$markers[i]._isActive=false;$markers[i]._makeVisible=false}this._mapMarkers=this._mapMarkers.concat($markers)};ClusterMarker.prototype._clusterMarker=function($clusterGroupIndexes){function $newClusterMarker($location,$icon,$title){return new GMarker($location,{icon:$icon,title:$title})}var $clusterGroupBounds=new GLatLngBounds(),i,$clusterMarker,$clusteredMarkers=[],$marker,$this=this,$mapMarkers=this._mapMarkers;for(i=$clusterGroupIndexes.length-1;i>=0;i--){$marker=$mapMarkers[$clusterGroupIndexes[i]];$marker.index=$clusterGroupIndexes[i];$clusterGroupBounds.extend($marker.getLatLng());$clusteredMarkers.push($marker)}$clusterMarker=$newClusterMarker($clusterGroupBounds.getCenter(),this.clusterMarkerIcon,this.clusterMarkerTitle.replace(/%count/gi,$clusterGroupIndexes.length));$clusterMarker.clusterGroupBounds=$clusterGroupBounds;this._eventListeners.push(GEvent.addListener($clusterMarker,"click",function(){$this.clusterMarkerClick({clusterMarker:$clusterMarker,clusteredMarkers:$clusteredMarkers})}));$clusterMarker._childIndexes=$clusterGroupIndexes;for(i=$clusterGroupIndexes.length-1;i>=0;i--){$mapMarkers[$clusterGroupIndexes[i]]._parentCluster=$clusterMarker}return $clusterMarker};ClusterMarker.prototype.clusterMarkerClick=function($args){this._map.setCenter($args.clusterMarker.getLatLng(),this._map.getBoundsZoomLevel($args.clusterMarker.clusterGroupBounds))};ClusterMarker.prototype._filterActiveMapMarkers=function(){var $borderPadding=this.borderPadding,$mapZoomLevel=this._map.getZoom(),$mapProjection=this._map.getCurrentMapType().getProjection(),$mapPointSw,$activeAreaPointSw,$activeAreaLatLngSw,$mapPointNe,$activeAreaPointNe,$activeAreaLatLngNe,$activeAreaBounds=this._map.getBounds(),i,$marker,$uncachedIconBoundsIndexes=[],$oldState,$mapMarkers=this._mapMarkers,$iconBounds=this._iconBounds;if($borderPadding){$mapPointSw=$mapProjection.fromLatLngToPixel($activeAreaBounds.getSouthWest(),$mapZoomLevel);$activeAreaPointSw=new GPoint($mapPointSw.x-$borderPadding,$mapPointSw.y+$borderPadding);$activeAreaLatLngSw=$mapProjection.fromPixelToLatLng($activeAreaPointSw,$mapZoomLevel);$mapPointNe=$mapProjection.fromLatLngToPixel($activeAreaBounds.getNorthEast(),$mapZoomLevel);$activeAreaPointNe=new GPoint($mapPointNe.x+$borderPadding,$mapPointNe.y-$borderPadding);$activeAreaLatLngNe=$mapProjection.fromPixelToLatLng($activeAreaPointNe,$mapZoomLevel);$activeAreaBounds.extend($activeAreaLatLngSw);$activeAreaBounds.extend($activeAreaLatLngNe)}this._activeMarkersChanged=false;if(typeof($iconBounds[$mapZoomLevel])==="undefined"){this._iconBounds[$mapZoomLevel]=[];this._activeMarkersChanged=true;for(i=$mapMarkers.length-1;i>=0;i--){$marker=$mapMarkers[i];$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;$marker._makeVisible=$marker._isActive;if($marker._isActive){$uncachedIconBoundsIndexes.push(i)}}}else{for(i=$mapMarkers.length-1;i>=0;i--){$marker=$mapMarkers[i];$oldState=$marker._isActive;$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;$marker._makeVisible=$marker._isActive;if(!this._activeMarkersChanged&&$oldState!==$marker._isActive){this._activeMarkersChanged=true}if($marker._isActive&&typeof($iconBounds[$mapZoomLevel][i])==="undefined"){$uncachedIconBoundsIndexes.push(i)}}}return $uncachedIconBoundsIndexes};ClusterMarker.prototype._filterIntersectingMapMarkers=function(){var $clusterGroup,i,j,$mapZoomLevel=this._map.getZoom(),$mapMarkers=this._mapMarkers,$iconBounds=this._iconBounds;for(i=$mapMarkers.length-1;i>0;i--){if($mapMarkers[i]._makeVisible){$clusterGroup=[];for(j=i-1;j>=0;j--){if($mapMarkers[j]._makeVisible&&$iconBounds[$mapZoomLevel][i].intersects($iconBounds[$mapZoomLevel][j])){$clusterGroup.push(j)}}if($clusterGroup.length!==0){$clusterGroup.push(i);for(j=$clusterGroup.length-1;j>=0;j--){$mapMarkers[$clusterGroup[j]]._makeVisible=false}this._clusterMarkers.push(this._clusterMarker($clusterGroup))}}}};ClusterMarker.prototype.fitMapToMarkers=function(){var $mapMarkers=this._mapMarkers,$markersBounds=new GLatLngBounds(),i;for(i=$mapMarkers.length-1;i>=0;i--){$markersBounds.extend($mapMarkers[i].getLatLng())}var $fitMapToMarkersZoom=this._map.getBoundsZoomLevel($markersBounds);if(this.fitMapMaxZoom&&$fitMapToMarkersZoom>this.fitMapMaxZoom){$fitMapToMarkersZoom=this.fitMapMaxZoom}this._map.setCenter($markersBounds.getCenter(),$fitMapToMarkersZoom);this.refresh()};ClusterMarker.prototype._mapTypeChanged=function(){this.refresh(true)};ClusterMarker.prototype._moveEnd=function(){if(!this._cancelMoveEnd){this.refresh()}else{this._cancelMoveEnd=false}};ClusterMarker.prototype._preCacheIconBounds=function($indexes,$mapZoomLevel){var $mapProjection=this._map.getCurrentMapType().getProjection(),i,$marker,$iconSize,$iconAnchorPoint,$iconAnchorPointOffset,$iconBoundsPointSw,$iconBoundsPointNe,$iconBoundsLatLngSw,$iconBoundsLatLngNe,$intersectPadding=this.intersectPadding,$mapMarkers=this._mapMarkers;for(i=$indexes.length-1;i>=0;i--){$marker=$mapMarkers[$indexes[i]];$iconSize=$marker.getIcon().iconSize;$iconAnchorPoint=$mapProjection.fromLatLngToPixel($marker.getLatLng(),$mapZoomLevel);$iconAnchorPointOffset=$marker.getIcon().iconAnchor;$iconBoundsPointSw=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x-$intersectPadding,$iconAnchorPoint.y-$iconAnchorPointOffset.y+$iconSize.height+$intersectPadding);$iconBoundsPointNe=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x+$iconSize.width+$intersectPadding,$iconAnchorPoint.y-$iconAnchorPointOffset.y-$intersectPadding);$iconBoundsLatLngSw=$mapProjection.fromPixelToLatLng($iconBoundsPointSw,$mapZoomLevel);$iconBoundsLatLngNe=$mapProjection.fromPixelToLatLng($iconBoundsPointNe,$mapZoomLevel);this._iconBounds[$mapZoomLevel][$indexes[i]]=new GLatLngBounds($iconBoundsLatLngSw,$iconBoundsLatLngNe)}};ClusterMarker.prototype.refresh=function($forceFullRefresh){var i,$marker,$zoomLevel=this._map.getZoom(),$uncachedIconBoundsIndexes=this._filterActiveMapMarkers();if(this._activeMarkersChanged||$forceFullRefresh){this._removeClusterMarkers();if(this.clusteringEnabled&&$zoomLevel<this._map.getCurrentMapType().getMaximumResolution()){if($uncachedIconBoundsIndexes.length>0){this._preCacheIconBounds($uncachedIconBoundsIndexes,$zoomLevel)}this._filterIntersectingMapMarkers()}for(i=this._clusterMarkers.length-1;i>=0;i--){this._map.addOverlay(this._clusterMarkers[i])}for(i=this._mapMarkers.length-1;i>=0;i--){$marker=this._mapMarkers[i];if(!$marker._isVisible&&$marker._makeVisible){this._map.addOverlay($marker);$marker._isVisible=true}if($marker._isVisible&&!$marker._makeVisible){this._map.removeOverlay($marker);$marker._isVisible=false}}}};ClusterMarker.prototype._removeClusterMarkers=function(){var i,j,$map=this._map,$eventListeners=this._eventListeners,$clusterMarkers=this._clusterMarkers,$childIndexes,$mapMarkers=this._mapMarkers;for(i=$clusterMarkers.length-1;i>=0;i--){$childIndexes=$clusterMarkers[i]._childIndexes;for(j=$childIndexes.length-1;j>=0;j--){delete $mapMarkers[$childIndexes[j]]._parentCluster}$map.removeOverlay($clusterMarkers[i])}for(i=$eventListeners.length-1;i>=0;i--){GEvent.removeListener($eventListeners[i])}this._clusterMarkers=[];this._eventListeners=[]};ClusterMarker.prototype.removeMarkers=function(){var i,$mapMarkers=this._mapMarkers,$map=this._map;for(i=$mapMarkers.length-1;i>=0;i--){if($mapMarkers[i]._isVisible){$map.removeOverlay($mapMarkers[i])}delete $mapMarkers[i]._isVisible;delete $mapMarkers[i]._isActive;delete $mapMarkers[i]._makeVisible}this._removeClusterMarkers();this._mapMarkers=[];this._iconBounds=[]};ClusterMarker.prototype.triggerClick=function($index){var $marker=this._mapMarkers[$index];if($marker._isVisible){GEvent.trigger($marker,"click")}else{if($marker._isActive){var $clusteredMarkersIndexes=$marker._parentCluster._childIndexes,$intersectDetected=true,$uncachedIconBoundsIndexes,i,$mapZoomLevel=this._map.getZoom(),$clusteredMarkerIndex,$iconBounds=this._iconBounds,$mapMaxZoomLevel=this._map.getCurrentMapType().getMaximumResolution();while($intersectDetected&&$mapZoomLevel<$mapMaxZoomLevel){$intersectDetected=false;$mapZoomLevel++;if(typeof($iconBounds[$mapZoomLevel])==="undefined"){$iconBounds[$mapZoomLevel]=[];this._preCacheIconBounds($clusteredMarkersIndexes,$mapZoomLevel)}else{$uncachedIconBoundsIndexes=[];for(i=$clusteredMarkersIndexes.length-1;i>=0;i--){if(typeof($iconBounds[$mapZoomLevel][$clusteredMarkersIndexes[i]])==="undefined"){$uncachedIconBoundsIndexes.push($clusteredMarkersIndexes[i])}}if($uncachedIconBoundsIndexes.length>=1){this._preCacheIconBounds($uncachedIconBoundsIndexes,$mapZoomLevel)}}for(i=$clusteredMarkersIndexes.length-1;i>=0;i--){$clusteredMarkerIndex=$clusteredMarkersIndexes[i];if($clusteredMarkerIndex!==$index&&$iconBounds[$mapZoomLevel][$clusteredMarkerIndex].intersects($iconBounds[$mapZoomLevel][$index])){$intersectDetected=true;break}}}this._map.setCenter($marker.getLatLng(),$mapZoomLevel);this.triggerClick($index)}else{this._map.setCenter($marker.getLatLng());this.triggerClick($index)}}};ClusterMarker.prototype._zoomEnd=function(){this._cancelMoveEnd=true;this.refresh(true)};
// map.js
var DOM=YAHOO.util.Dom;var EVENT=YAHOO.util.Event;var MAP;var MARKERS=[];var CLUSTER;var initialize=function(){loadDayTabs();loadGoogleMap();createGameMarkers();showAllGames();showInitialGame()};EVENT.onDOMReady(initialize);var loadGoogleMap=function(){if(GBrowserIsCompatible()){MAP=new GMap2(DOM.get("pickup_map"));MAP.addControl(new GLargeMapControl());MAP.addControl(new GMapTypeControl());if(YAHOO.util.Cookie.get("zoom")!=null){goHome()}else{MAP.setCenter(new GLatLng(29.53522956,-6.328125),2);saveHome()}EVENT.on("savehome","click",saveHome);EVENT.on("gohome","click",goHome)}else{DOM.get("pickup_map").innerHTML='Your browser cannot display the map on this page.  Please <a href="http://www.getfirefox.com">upgrade</a>.'}};var saveHome=function(){var c=new Date("January 12, 2050");var b=MAP.getZoom();YAHOO.util.Cookie.set("zoom",b,{expires:c});var a=MAP.getCenter();YAHOO.util.Cookie.set("latitude",a.lat(),{expires:c});YAHOO.util.Cookie.set("longitude",a.lng(),{expires:c})};var goHome=function(){if(YAHOO.util.Cookie.get("zoom")!=null){var c=parseFloat(YAHOO.util.Cookie.get("latitude"));var b=parseFloat(YAHOO.util.Cookie.get("longitude"));var a=parseInt(YAHOO.util.Cookie.get("zoom"),10);MAP.setCenter(new GLatLng(c,b),a)}};var createGameMarkers=function(){for(var b=0;b<GAMES.length;b++){var a=new GLatLng(GAMES[b][0],GAMES[b][1]);MARKERS[b]=createMarker(a,GAMES[b][3])}CLUSTER=new ClusterMarker(MAP);CLUSTER.intersectPadding=5};function createMarker(a,c){var b=new GMarker(a);GEvent.addListener(b,"click",function(){openInfoWindow(b,c)});return b}var openInfoWindow=function(marker,id){var waiting='<img src="images/icons/loading.gif" alt="" /> loading...';marker.openInfoWindowHtml(waiting);var ajax_failure=function(){var message="<b>AJAX Failure!</b><br />There was a problem sending your request to the server.<br />Please refresh the page and try again.";marker.openInfoWindowHtml(message)};var callback={success:function(o){if(o.responseText!==undefined){marker.closeInfoWindow();var tabs=[];eval(o.responseText);marker.openInfoWindowTabsHtml(tabs)}else{ajax_failure()}},failure:ajax_failure};var url="game/info/"+id;YAHOO.util.Connect.asyncRequest("GET",url,callback,"")};function showAllGames(){CLUSTER.removeMarkers();CLUSTER.addMarkers(MARKERS);CLUSTER.refresh(true)}function switchDayTab(b){var a=DOM.getElementsByClassName("day-tab","div","day-tabs");DOM.removeClass(a,"active-day-tab");DOM.addClass(a,"inactive-day-tab");DOM.replaceClass(b,"inactive-day-tab","active-day-tab")}function showGames(a){CLUSTER.removeMarkers();var c=0;var d=[];for(var b=0;b<MARKERS.length;b++){if(GAMES[b][2].match(a+".")!=null){d.push(MARKERS[b]);c++}}CLUSTER.addMarkers(d);CLUSTER.refresh(true)}function showInitialGame(){if(DOM.inDocument("initial_game")){var f=parseInt(DOM.get("initial_game").innerHTML,10);var c=15;var a=-1;for(var b=0;b<GAMES.length;b++){if(GAMES[b][3]==f){a=b;break}}if(a!=-1){MAP.setCenter(new GLatLng(GAMES[a][0],GAMES[a][1]),c);openInfoWindow(MARKERS[a],GAMES[a][3])}}if(DOM.inDocument("city")){var e=parseFloat(DOM.get("latitude").innerHTML);var d=parseFloat(DOM.get("longitude").innerHTML);var c=parseInt(DOM.get("zoom").innerHTML,10);MAP.setCenter(new GLatLng(e,d),c)}}function loadDayTabs(){EVENT.on("days_all","click",function(){switchDayTab("days_all");showAllGames()});EVENT.on("days_mon","click",function(){switchDayTab("days_mon");showGames(1)});EVENT.on("days_tues","click",function(){switchDayTab("days_tues");showGames(2)});EVENT.on("days_wed","click",function(){switchDayTab("days_wed");showGames(3)});EVENT.on("days_thurs","click",function(){switchDayTab("days_thurs");showGames(4)});EVENT.on("days_fri","click",function(){switchDayTab("days_fri");showGames(5)});EVENT.on("days_sat","click",function(){switchDayTab("days_sat");showGames(6)});EVENT.on("days_sun","click",function(){switchDayTab("days_sun");showGames(0)})};