//<![CDATA[

// 111 is for zooming to a city, selected in dropdown box "which", where the coordinates of the city are given in an array called "cities"

// 222 is for zooming to a train station or airport, selected in dropdown box "train", where the coordinates of the place to zoom are given in an array called "stations"
// when a group of stations is chosen, instead of zooming, it draws markers for those stations, and at the end, draws applicable polylines
// the stations array has one more variable than the cities array

// 777 just draws the map with no overlays

 // Creates a marker at the given point waiting to be clicked
 function createMarkerWithInfo(point, html) {
   var marker = new GMarker(point);
   GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
   });
   return marker;
 }

    function showmaps(check)
    {
    
if (check==777){

    var map = new GMap2(document.getElementById("map"));   
    map.setCenter(MapDefaultCenter, MapDefaultZoom);
	map.setUIToDefault();

    drawCounty(map);  // from javascript folder

};//end 777

if (check==111){

var cow=document.getElementById("which")
var city=cow.options[cow.selectedIndex].text

for (count=0;count<cities.length;count=count+3)
    {
if (city==cities[count])
 {
 
 var map = new GMap2(document.getElementById("map"));
 var point = new GLatLng(cities[count+1], cities[count+2]);
 map.setCenter(point, 14);
 map.setUIToDefault();

 drawCounty(map);  // from javascript folder
 
 var marker = new GMarker(point);
 var html = "<b>"+cities[count]+"</b>";
 html=html+"<p><a href='http://hotels.ocny.com/'>Click for area hotels</a>";
 
 map.addOverlay(marker);  // This line actually displays the marker
 marker.openInfoWindowHtml(html);  // This line displays the popup window
 
 };// end if
    }; //end for loop   

};//end 111

if (check==222){

var cow=document.getElementById("train")
var station=cow.options[cow.selectedIndex].text

var inArray = 0;

for (count=0;count<stations.length;count=count+4)  
    {
if (station==stations[count])
 {
 
 inArray=1;   // this indicates a station has been chosen, not a group
 
 var map = new GMap2(document.getElementById("map"));
 var point = new GLatLng(stations[count+2], stations[count+3]);
 map.setCenter(point, 12);
 map.setUIToDefault();
 
 drawCounty(map);  // from javascript folder

 var marker = new GMarker(point);
 var html = "<b>"+stations[count]+"</b><p>";
 if (stations[count+1]=="P") html=html+"Metro-North Railroad<br>Port Jervis Line<p><a href='http://www.ocny.com/transportation/rail.php'>Click for information</a>";
 if (stations[count+1]=="H") html=html+"Metro-North Railroad<br>Hudson Line<p><a href='http://www.ocny.com/transportation/rail.php'>Click for information</a>";
 if (stations[count+1]=="I") html=html+"<a href='http://www.ocny.com/transportation/air.php'>Click for airport information</a>";
 if (stations[count+1]=="G") html=html+"General aviation<p><a href='http://www.ocny.com/transportation/air.php'>Click for airport information</a>";
 if (stations[count+1]=="A") html=html+"Amtrak<p><a href='http://www.ocny.com/transportation/rail.php'>Click for information</a>";
 
 map.addOverlay(marker);  // This line actually displays the marker
 marker.openInfoWindowHtml(html);  // This line displays the popup window
 };
    };   // end for loop
    
if (station=="Passenger airports") {
 var searchLetter = "I";
 var addHtml = "Passenger service<p><a href='http://www.ocny.com/transportation/air.php'>Click for airport information</a>";
 };
if (station=="General aviation airports") {
 var searchLetter = "G";
 var addHtml = "General aviation<p><a href='http://www.ocny.com/transportation/air.php'>Click for airport information</a>";
 };
if (station=="Hudson Line train stations") {
 var searchLetter = "H";
 var addHtml = "Metro-North Railroad<br>Hudson Line<p><a href='http://www.ocny.com/transportation/rail.php'>Click for information</a>";
 };
if (station=="Port Jervis Line train stations") {
 var searchLetter = "P";
 var addHtml = "Metro-North Railroad<br>Port Jervis Line<p><a href='http://www.ocny.com/transportation/rail.php'>Click for information</a>";
 };
if (station=="Amtrak stations") {
 var searchLetter = "A";
 var addHtml = "Amtrak<p><a href='http://www.ocny.com/transportation/rail.php'>Click for information</a>";
 };
if (station=="Choose an airport or train station") inArray=1;
   
if (inArray==0)   // runs if a group has been chosen
 {
 // Make a new map
 var map = new GMap2(document.getElementById("map"));
 map.setCenter(MapDefaultCenter, MapDefaultZoom);
 map.setUIToDefault();

 drawCounty(map);  // from javascript folder     
 
 for (count=0;count<stations.length;count=count+4)
    {
    
 if (stations[count+1]==searchLetter)
 {
 var html = "<b>"+stations[count]+"</b><p>";   
 html=html+addHtml;
 var point = new GLatLng(stations[count+2], stations[count+3]);
 map.addOverlay(createMarkerWithInfo(point, html));
 };

   };   // end for loop  
   
 };

};//end 222

    }    // end function showmaps
//]]>