var map;var mapRegion=new GLatLngBounds(new GLatLng(43.581,-79.717),new GLatLng(43.834,-79.102));var searchMarker=null;var searchMarkerAddress=null;var zoomLevel=null;var stationMarker=null;var stationParam=null;var geocoder=new GClientGeocoder();var CM_stations=new Array(0);var locationIcon=new GIcon();locationIcon.image="http://maps.google.com/mapfiles/arrow.png";locationIcon.shadow="http://maps.google.com/mapfiles/arrowshadow.png";locationIcon.iconSize=new GSize(39,34);locationIcon.shadowSize=new GSize(39,34);locationIcon.iconAnchor=new GPoint(11,34);locationIcon.infoWindowAnchor=new GPoint(13,2);function getParams(){var _1=[];var _2=window.location.search.substring(1);if(_2){var _3=_2.split("&");for(var i=0;i<_3.length;i++){var _5=_3[i].split("=");_5[0]=decodeURIComponent(_5[0].replace(/\+/g," "));_5[1]=decodeURIComponent(_5[1].replace(/\+/g," "));_1[_5[0]]=_5[1];}}return _1;}function CM_createStationMarker(_6,_7,_8,_9){var _a=new GMarker(new GPoint(_7.lng,_7.lat),_9);GEvent.addListener(_a,"click",function(){_a.openInfoWindowHtml(_8);});GEvent.addListener(_a,"infowindowopen",function(){stationMarker=_6;});GEvent.addListener(_a,"infowindowclose",function(){stationMarker=null;});return _a;}function getStationHtml(_b,_c){var _d="<div class=\"station "+_b.type+"\"><h3>"+_b.name+"</h3><p>"+_b.address+"</p>";if(_b.platforms&&_b.platforms.length>0){_d+="<div class=\"platform\">";for(var i=0;i<_b.platforms.length;i++){_d+="<p><a target=\"_blank\" href=\"http://www3.ttc.ca/Subway/Stations/"+_b.platforms[i].name+"/station.jsp\" title=\"Show information for ";if(_b.platforms[i].title){_d+="the "+_b.platforms[i].title+"\">"+_b.platforms[i].title+" Station Information</a>";}else{_d+="this station"+"\">Station Information</a>";}_d+="</p>";}_d+="</div>";}if(_b.options&&_b.options.length>0){_b.options.sort();_d+="<div class=\"icons\">";for(var i=0;i<_b.options.length;i++){if(_b.options[i]!="t"){var _f=_c[_b.options[i]];_d+="<img alt=\""+_f+"\" title=\""+_f+"\" src=\""+_b.options[i]+".png\"/>";}}_d+="</div>";}_d+="</div>";return _d;}function addStation(_10,map,_12,_13){if(_10){var _14=getStationHtml(_10,_13);for(var i=0;i<_10.geo.length;i++){var _16=CM_createStationMarker(_10,_10.geo[i],_14,_12);map.addOverlay(_16);_10.marker=_16;}}}function compareStation(a,b){if(a.name==b.name){return 0;}if(a.name>b.name){return 1;}if(a.name<b.name){return -1;}}function addStations(map,_1a){var _1b=new GIcon();_1b.image="http://www.searchingtoronto.com/toronto-transit-map/clear2.png";_1b.shadow="http://www.searchingtoronto.com/toronto-transit-map/clear2.png";_1b.iconSize=new GSize(20,20);_1b.iconAnchor=new GPoint(10,10);_1b.infoWindowAnchor=new GPoint(10,10);var e=document.getElementById(_1a);e.onchange=function(){triggerSelectedStation(e);};GDownloadUrl("torontotransit.json",function(doc){data=eval("("+doc+")");data.stations.sort(compareStation);var _1e=0;for(i=0;i<data.stations.length;i++){addStation(data.stations[i],map,_1b,data.icons);if(data.stations[i]){option=document.createElement("option");optionText=document.createTextNode(data.stations[i].name);option.appendChild(optionText);option.setAttribute("id",i);e.appendChild(option);if(stationParam&&data.stations[i].name.toLowerCase()==stationParam.toLowerCase()){GEvent.trigger(data.stations[i].marker);}if(zoomLevel){map.setZoom(zoomLevel);}}}CM_stations=data.stations;});}function getTileLayers(){layers=[];var _1f=new GTileLayer(new GCopyrightCollection(),12,15);_1f.getTileUrl=function(_20,_21){return "http://www.searchingtoronto.com/toronto-transit-map/grey.gif";};_1f.getOpacity=function(){return 0.5;};layers.push(_1f);_1f=new GTileLayer(new GCopyrightCollection(),12,15);_1f.getTileUrl=function(_22,_23){var _24=17-_23;var _25=Math.pow(2,_23-12);if(_22.x>=1141*_25&&_22.x<=1147*_25+_25-1&&_22.y>=1492*_25&&_22.y<=1495*_25+_25-1){return "http://mt"+(_22.x+_22.y)%4+".crazedmonkey.com/z"+_24+"x"+_22.x+"y"+_22.y+".png";}else{return "http://www.searchingtoronto.com/toronto-transit-map/grey.gif";}};_1f.isPng=function(){return true;};layers.push(_1f);return layers;}function limitZoomAndMovement(map,min,max){var mt=map.getMapTypes();for(var i=0;i<mt.length;i++){mt[i].getMinimumResolution=function(){return min;};mt[i].getMaximumResolution=function(){return max;};}points=[];points.push(mapRegion.getSouthWest());points.push(new GLatLng(mapRegion.getSouthWest().lat(),mapRegion.getNorthEast().lng()));points.push(mapRegion.getNorthEast());points.push(new GLatLng(mapRegion.getNorthEast().lat(),mapRegion.getSouthWest().lng()));points.push(mapRegion.getSouthWest());}function triggerSelectedStation(_2b){var _2c=_2b.options[_2b.selectedIndex].id;if(_2c!=""){GEvent.trigger(CM_stations[_2c].marker);}}function getWindowHeight(){if(window.self&&self.innerHeight){return self.innerHeight;}if(document.documentElement&&document.documentElement.clientHeight){return document.documentElement.clientHeight;}return 0;}function resizeMap(){var _2d=0;var _2e=document.getElementById("map");for(var _2f=_2e;_2f!=null;_2f=_2f.offsetParent){_2d+=_2f.offsetTop;}var _30=getWindowHeight()-_2d-10;if(_30>=0){_2e.style.height=_30+"px";document.getElementById("rightpanel").style.height=_30-10+"px";}}window.onresize=resizeMap;function loadMap(){resizeMap();if(GBrowserIsCompatible()){handleParams(getParams());}else{document.getElementById("loading").innerHtml="Sorry, your browser is unable to display this map.";}}function initMap(_31,_32,_33){map=new GMap2(document.getElementById("map"));map.setUIToDefault();map.addControl(new GMapTypeControl());map.addControl(new GScaleControl());if(_31){map.setCenter(_32,14);}else{map.setCenter(_32,13);}currentMap=map.getCurrentMapType();layers=getTileLayers();type=new GMapType(currentMap.getTileLayers().concat(layers),currentMap.getProjection(),"Transit");map.addMapType(type);map.setMapType(type);limitZoomAndMovement(map,12,15);addStations(map,"stationSel");if(_31){showAddressMarker(_31,_32,_33);}}function createLink(){loc=window.location.href;link=loc.substring(0,loc.lastIndexOf("/"));params=[];if(stationMarker){params.push("s="+stationMarker.name.replace(/ /g,"+"));}if(searchMarkerAddress){params.push("q="+encodeURI(searchMarkerAddress.replace(/ /g,"+")));}if(params.length>0){params.push("z="+map.getZoom());link+="?";for(i=0;i<params.length;i++){link+=params[i];if(i<params.length-1){link+="&";}}}window.location=link;}function handleParams(_34){stationParam=_34["s"];zoomLevel=parseInt(_34["z"]);defaultInit=function(){initMap(null,new GLatLng(43.660241,-79.386871),false);};if(_34["q"]){handleAddress(_34["q"],false,initMap,defaultInit);}else{defaultInit();}}function startProgress(){document.body.style.cursor="progress";document.getElementById("locateStatus").style.display="inline";document.getElementById("submit").style.display="none";document.getElementById("address").disabled=true;}function stopProgress(_35){document.body.style.cursor="default";document.getElementById("locateStatus").style.display="none";document.getElementById("submit").style.display="inline";document.getElementById("address").disabled=false;document.getElementById("address").value=_35;}function handleAddress(_36,_37,_38,_39){oldAddress=_36;if(_37){startProgress();}toronto_address=reformatAddress(_36);geocoder.getLocations(toronto_address,function(_3a){if(!_3a||_3a.Status.code!=200){if(_37){stopProgress(oldAddress);}alert("Sorry, could not locate "+_36);if(_39){_39();}}else{place=_3a.Placemark[0];point=new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);if(checkAddressBounds(point)){searchMarkerAddress=_36;_38(place.address,point,_37);}else{alert(place.address+" is outside bounds of the map.");}if(_37){stopProgress(oldAddress);}}});}function showAddress(_3b,_3c){handleAddress(_3b,_3c,showAddressMarker);}function checkAddressBounds(_3d){if(mapRegion.contains(_3d)){return true;}return false;}function showAddressMarker(_3e,_3f,_40){if(searchMarker){map.removeOverlay(searchMarker);}marker=new GMarker(_3f,locationIcon);map.addOverlay(marker);map.setCenter(_3f);if(_40||!zoomLevel){map.setZoom(14);}_3e=_3e.split(",");addressHtml="<div class=\"address\"><h3>Address:</h3><address>"+_3e[0]+"<br/>"+_3e[1]+", "+_3e[2]+"</address></div>";if(_40||!stationParam){marker.openInfoWindowHtml(addressHtml);}GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml(addressHtml);});searchMarker=marker;}function reformatAddress(_41){elems=_41.split(",");if(elems.length==1){_41+=", Toronto, ON";}else{if(elems.length==2){_41+=", ON";}}return _41;}
