

var CM_yongeLineDayNorthEastPoints = [
 new GPoint(-79.46220427751541, 43.74919180376368),
 new GPoint(-79.45009142160416, 43.73435602693744),
 new GPoint(-79.4475594162941, 43.724760034632034),
 new GPoint(-79.44396525621414, 43.7153815729365),
 new GPoint(-79.44098263978958, 43.709098074196895),
 new GPoint(-79.43636387586594, 43.69903319977416),
 new GPoint(-79.41501885652542, 43.683780981337236)
 ];

 var CM_youngLinePoints

var CM_yongeLinePoints = [
 new GPoint(-79.41501885652542, 43.683780981337236),
 new GPoint(-79.40665572881699, 43.674787981119245),
 new GPoint(-79.40360605716705, 43.667324474662834),
 new GPoint(-79.39787417650223, 43.66863797940801),
 new GPoint(-79.39368188381195, 43.66730701281089),
 new GPoint(-79.39076900482178, 43.659927955678334),
 new GPoint(-79.38793122768402, 43.654756448242985),
 new GPoint(-79.38624680042267, 43.65094690668266),
 new GPoint(-79.38471794128418, 43.64778148483318),
 new GPoint(-79.38069999217987, 43.64512247919548),
 new GPoint(-79.3778944015503, 43.648848935736545),
 new GPoint(-79.37927037477493, 43.65237915187759),
 new GPoint(-79.38093066215515, 43.65602171373054),
 new GPoint(-79.38269823789597, 43.66133670189694),
 new GPoint(-79.38460797071457, 43.66485842282958),
 new GPoint(-79.38602417707443, 43.670717798144565),
 new GPoint(-79.38869565725327, 43.67685982714917),
 new GPoint(-79.3907555937767, 43.682256378607114),
 new GPoint(-79.3930783867836, 43.68798798559691),
 new GPoint(-79.39727336168289, 43.69771397725964),
 new GPoint(-79.39836770296097, 43.70673068583634)
 ];

var CM_yongeLineDayNorthWestPoints = [
 new GPoint(-79.39836770296097, 43.70673068583634),
 new GPoint(-79.4019216299057, 43.72525624966812),
 new GPoint(-79.4058832526207, 43.74326452254364),
 new GPoint(-79.41296964883804, 43.76875212250278),
 new GPoint(-79.41568404436111, 43.78191400941247)
];

var CM_bloorLineDayWestPoints = [
 new GPoint(-79.53542858362198, 43.6376960488635),
 new GPoint(-79.52391654253006, 43.645227288945236),
 new GPoint(-79.51128333806992, 43.64826281049803),
 new GPoint(-79.49348956346512, 43.64950492342589),
 new GPoint(-79.48387116193771, 43.64995518301882),
 new GPoint(-79.47576552629471, 43.6517542469277),
 new GPoint(-79.46645021438599, 43.654063645875866),
 new GPoint(-79.45968300104141, 43.65554433141758)
 ];

var CM_bloorLinePoints = [ 
 new GPoint(-79.45968300104141, 43.65554433141758),
 new GPoint(-79.45311427116394, 43.65691825074471),
 new GPoint(-79.44306671619415, 43.65898683269404),
 new GPoint(-79.4354036450386, 43.65987556365253),
 new GPoint(-79.42629754543304, 43.662353462375705),
 new GPoint(-79.41835284233093, 43.66408812466335),
 new GPoint(-79.41117525100708, 43.66589258593267),
 new GPoint(-79.40360605716705, 43.667324474662834),
 new GPoint(-79.39787417650223, 43.66863797940801),
 new GPoint(-79.38997238874435, 43.67011248520139),
 new GPoint(-79.37649697065353, 43.67220195308347),
 new GPoint(-79.36862468719482, 43.67378695122794),
 new GPoint(-79.35838401317596, 43.67680357010253),
 new GPoint(-79.35248047113419, 43.678149844953424),
 new GPoint(-79.34494614601135, 43.67982391693447),
 new GPoint(-79.33775782585144, 43.68088691869681),
 new GPoint(-79.33021008968353, 43.68247556688051),
 new GPoint(-79.32302713394165, 43.684108785260214),
 new GPoint(-79.31263357400894, 43.68636457078064)
 ];

var CM_bloorLineDayEastPoints = [
 new GPoint(-79.31263357400894, 43.68636457078064),
 new GPoint(-79.30182695388794, 43.68888404520687),
 new GPoint(-79.28879678249359, 43.694905916707164),
 new GPoint(-79.27906304597855, 43.711383940317916),
 new GPoint(-79.26386028528214, 43.7324354009901)
];

CM_rtLinePoints = [
 new GPoint(-79.25164014101028, 43.774895729824394),
 new GPoint(-79.25830274820328, 43.77431664623901),
 new GPoint(-79.27198201417923, 43.770423664542285),
 new GPoint(-79.27621185779572, 43.76662340516728),
 new GPoint(-79.27034050226212, 43.75067401674027),
 new GPoint(-79.26386028528214, 43.7324354009901)
];

CM_sheppardLinePoints = [new GPoint(-79.4121327996254, 43.761608320294094),
 new GPoint(-79.38771396875381, 43.76699336967006),
 new GPoint(-79.37952786684036, 43.76842090758474),
 new GPoint(-79.36580568552017, 43.77117710216893),
 new GPoint(-79.34604316949844, 43.775569706334004)
];

CM_yongeLineDayNorthEastHtml = [
"Downsview|1035 Sheppard Ave West",
"Wilson|570 Wilson Ave",
"Yorkdale|Yorkdale Shopping Centre",
"Lawrence West|655 Lawrence Ave West",
"Glencairn|765 Glencairn Ave",
"Eglinton West|1300 Eglinton Ave West",
"St. Clair West|370 St Clair Ave West"];

CM_yongeLineHtml = [
"St. Clair West|370 St Clair Ave West",
"Dupont|278 Dupont St",
"Spadina|371 Bloor St West",
"St George|323 Bloor St West",
"Museum|75 Queen's Park",
"Queen's Park|671 University Ave",
"St. Patrick|449 University Ave",
"Osgoode|260 University Ave",
"St. Andrew|147 University Ave",
"Union|55 Front St. West",
"King|70 Yonge St",
"Queen|171 Yonge St",
"Dundas|300 Yonge St",
"College|448 Yonge St",
"Wellesley|551 Yonge St",
"Bloor-Yonge|733 Yonge St",
"Rosedale|1009 Yonge St",
"Summerhill|1189 Yonge St",
"St Clair|1441 Yonge St",
"Davisville|1900 Yonge St",
"Eglinton|2190 Yonge St"];

CM_yongeLineDayNorthWestHtml = [
"Eglinton|2190 Yonge St",
"Lawrence|3101 Yonge St",
"York Mills|4015 Yonge St",
"North York Centre|5152 Yonge St",
"Finch|5714 Yonge St"];

CM_bloorLineDayWestHtml = [
"Kipling|5247 Dundas St West",
"Islington|3286 Bloor St West",
"Royal York|3012 Bloor St West",
"Old Mill|2672 Bloor St West",
"Jane|2440 Bloor St West",
"Runnymede|2218 Bloor St West",
"High Park|1874 Bloor St West",
"Keele|1733 Bloor St West"
];

CM_bloorLineHtml = [
"Keele|1733 Bloor St West",
"Dundas West|1525 Bloor St West",
"Lansdowne|1287 Bloor St West",
"Dufferin|1126 Bloor St West",
"Ossington|883 Bloor St West",
"Christie|726 Bloor St West",
"Bathurst|565 Bloor St West",
"Spadina|371 Bloor St West",
"St George|323 Bloor St West",
"Bay|64 Bloor St West",
"Sherbourne|420 Bloor St East",
"Castle Frank|600 Bloor St East",
"Broadview|90 Danforth Ave",
"Chester|370 Danforth Ave",
"Pape|650 Danforth Ave",
"Donlands|990 Danforth Ave",
"Greenwood|1177 Danforth Ave",
"Coxwell|1568 Danforth Ave",
"Woodbine|2072 Danforth Ave"
];

CM_bloorLineDayEastHtml = [
"Woodbine|2072 Danforth Ave",
"Main Street|2550 Danforth Ave",
"Victoria Park|777 Victoria Park Ave",
"Warden|3276 St Clair Ave East",
"Kennedy|2455 Eglinton Ave East"];

CM_rtLineHtml = ["McCowan|1275 McCowan Rd",
"Scarborough Centre|Scarborough Town Centre",
"Midland|2085 Midland Ave",
"Ellesmere|1025 Ellesmere Rd",
"Lawrence East|2444 Lawrence Ave East"];

CM_sheppardLineHtml = ["Sheppard-Yonge|4800 Yonge St",
"Bayview|550 Sheppard Ave East",
"Bessarion|701 Sheppard Ave East",
"Leslie|1209 Sheppard Ave East",
"Don Mills|1700 Sheppard Ave East"];


var CM_stationMarkers = new Array(CM_yongeLineDayNorthWestHtml.length + CM_yongeLineHtml.length + CM_yongeLineDayNorthEastHtml.length +
                        CM_bloorLineDayWestHtml.length + CM_bloorLineHtml.length + CM_bloorLineDayEastHtml.length +
                       
                        CM_sheppardLineHtml.length 
                        );
var CM_stations = new Array(CM_stationMarkers.length);

var CM_RouteLines = new Array(13);

// Creates a marker whose info window displays the given number
function CM_createMarker(point, html, icon) 
{
    var marker = new GMarker(point,icon);
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
    return marker;
}

function CM_getStationHtml(station)
{
    return "<div class=\"station\"><h3>" + station.replace( "|", "</h3><p>" ) + "</p></div>";
}

function CM_addLine( map, points, html, color, stationMarkers, stations, startIndex, icon, i_PolyLine)
{
    var PolyLine = new GPolyline(points, color, 10);
    map.addOverlay(PolyLine);
    CM_RouteLines[i_PolyLine] = PolyLine;
    for( var i = 0; i < html.length; i++, startIndex++ )
    {
        var marker = CM_createMarker( points[ i ], CM_getStationHtml( html[ i ] ), icon )
        map.addOverlay( marker );
        stationMarkers[ startIndex ] = marker; 
        var name = html[ i ].substring( 0, html[ i ].indexOf( "|" ) );
        stations[ startIndex ] = "<li id=\"" + name + "\" onclick=\"GEvent.trigger(CM_stationMarkers[" + startIndex + "],'click')\" style=\"background-color:" + color + "\">" + name  + "</li>";
    }

    return startIndex;
}

function drawTtcSubwayMapColor( map, yongeColor, bloorColor, rtColor, sheppardColor, streetCarColor, blueNightColor ) {

    var CM_ttcStationIcon = new GIcon();
    /*
    CM_ttcStationIcon.image = "/images/logos/logoTTC_sm.gif";
    CM_ttcStationIcon.shadow = "/images/logos/logoTTCshadow_sm.png";
    */
    CM_ttcStationIcon.iconSize = new GSize(11, 11);
    CM_ttcStationIcon.shadowSize = new GSize(11, 11);
    CM_ttcStationIcon.iconAnchor =  new GPoint(11, 11);
    CM_ttcStationIcon.infoWindowAnchor =  new GPoint(15, 1);
    
    var lastIndex = 0;
 
    lastIndex = CM_addLine(map, CM_yongeLinePoints, CM_yongeLineHtml, yongeColor, CM_stationMarkers, CM_stations, lastIndex, CM_ttcStationIcon, 1);
    lastIndex = CM_addLine(map, CM_bloorLinePoints, CM_bloorLineHtml, bloorColor, CM_stationMarkers, CM_stations, lastIndex, CM_ttcStationIcon, 2);
    
    lastIndex = CM_addLine(map, CM_yongeLineDayNorthWestPoints, CM_yongeLineDayNorthWestHtml, yongeColor, CM_stationMarkers, CM_stations, lastIndex, CM_ttcStationIcon, 3);
    lastIndex = CM_addLine(map, CM_yongeLineDayNorthEastPoints, CM_yongeLineDayNorthEastHtml, yongeColor, CM_stationMarkers, CM_stations, lastIndex, CM_ttcStationIcon, 4);
    lastIndex = CM_addLine(map, CM_bloorLineDayWestPoints, CM_bloorLineDayWestHtml, bloorColor, CM_stationMarkers, CM_stations, lastIndex, CM_ttcStationIcon, 5);
    lastIndex = CM_addLine(map, CM_bloorLineDayEastPoints, CM_bloorLineDayEastHtml, bloorColor, CM_stationMarkers, CM_stations, lastIndex, CM_ttcStationIcon, 6);

    lastIndex = CM_addLine(map, CM_sheppardLinePoints, CM_sheppardLineHtml, sheppardColor, CM_stationMarkers, CM_stations, lastIndex, CM_ttcStationIcon, 8);
    
 
    
}

function drawTtcSubwayMap( map )
{
    drawTtcSubwayMapColor(map, "#CC6600", "#003300", "#6666FF", "#330033", "#990000", "#000099");
}

function writeTtcSubwayStations() {

}

function TTCDay() {

    map.setCenter(new GLatLng(43.684012, -79.312363), 11);

    //Hide Nigthly Service
    var i_DailyServiceMarkers = CM_yongeLineHtml.length + CM_bloorLineHtml.length + CM_rtLineHtml.length + CM_sheppardLineHtml.length;
    for (i = i_DailyServiceMarkers; i < CM_stations.length; i++) {
        CM_stationMarkers[i].hide();
    }

    for (i = 3; i < 9; i++)
    {
        if (CM_RouteLines[i]) 
        CM_RouteLines[i].show();
    }
    
        for (i = 9; i < CM_RouteLines.length; i++) {
            if (CM_RouteLines[i]) 
            CM_RouteLines[i].hide();
    }
    

}

function TTCNightly() {

    map.setCenter(new GLatLng(43.684012, -79.312363), 11);

    //Hide Nigthly Service
    var i_DailyServiceMarkers = CM_yongeLineHtml.length + CM_bloorLineHtml.length + CM_rtLineHtml.length + CM_sheppardLineHtml.length ;
    for (i = i_DailyServiceMarkers; i < CM_stations.length; i++) {
        CM_stationMarkers[i].show();
    }
    for (i = 3; i < 9; i++)
        CM_RouteLines[i].hide();
    for (i = 9; i < CM_RouteLines.length; i++) {
        CM_RouteLines[i].show();
    }

    

}
