
var HcCs = {};

HcCs.TheMap = null;

// The indeces of data types in the maps data array
HcCs.Dt = {};
HcCs.Dt.Title = 0;
HcCs.Dt.Lat = 1;
HcCs.Dt.Long = 2;
HcCs.Dt.Flags = 3;
HcCs.Dt.Type = 4;
HcCs.Dt.Days = 5;
HcCs.Dt.Vehicle = 6;
HcCs.Dt.Date = 7;
HcCs.Dt.Country = 8;

HcCs.Elem = {};
HcCs.Elem.None = 0;
HcCs.Elem.Pins = 1;
HcCs.Elem.Lines = 2;
HcCs.Elem.Both = 3;

HcCs.GetMap = function (cityIndex, zoom, elements)
{
    var point;

    var numberOfCities = MapLocations.length - 1;
    // last place
    if (cityIndex === 0)
    {
       cityIndex = numberOfCities;
    }
    if (cityIndex === -1)
    {
        // choose a point to show the whole globe
       point = new google.maps.LatLng(25,30);
    }
    else
    {
        point = HcCs.GetPoint(cityIndex);
    }
     

    var myOptions = {
        zoom: zoom,
        center: point,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    HcCs.TheMap = new google.maps.Map(document.getElementById("map"), myOptions);

    for (i = 1; i <= numberOfCities; i++)
    {
        var flag = parseInt(MapLocations[i][HcCs.Dt.Flags]);

        // add route
        if ((elements & HcCs.Elem.Lines) === HcCs.Elem.Lines)
        {
            if (i > 1)
            {
                var flightPlanCoordinates = [
                    HcCs.GetPoint(i - 1), HcCs.GetPoint(i)];
                var flightPath = new google.maps.Polyline({
                    path: flightPlanCoordinates,
                    strokeColor: HcCs.LineColor(i),
                    strokeOpacity: 1.0,
                    strokeWeight: 2
                });

                flightPath.setMap(HcCs.TheMap);
            }
        }

        if ((elements & HcCs.Elem.Pins) === HcCs.Elem.Pins)
        {
            if ((flag & 1) === 1)
            {
                var name = MapLocations[i][HcCs.Dt.Title] + " (" + MapLocations[i][HcCs.Dt.Days] + " nights)";
                if (MapLocations[i][HcCs.Dt.Days] === 1)
                {
                    name = MapLocations[i][HcCs.Dt.Title] + " (one night)";
                }

                var marker = new google.maps.Marker({
                    position: HcCs.GetPoint(i),
                    map: HcCs.TheMap,
                    title: name,
                    icon: HcCs.MarkerImage(i)
                });
            }
        }
    }
};

HcCs.GetPoint = function(index)
{
    return new google.maps.LatLng(MapLocations[index][HcCs.Dt.Lat], 
        MapLocations[index][HcCs.Dt.Long]);
};

HcCs.LineColor = function (index)
{
    var vehicle = parseInt(MapLocations[i][HcCs.Dt.Vehicle]);

    var linecolor;

    // we arrived here by plane
    if (vehicle === 10)
    {
        // red
        linecolor = "#FF0000";
    }
    else if (vehicle === 0)
    {
        // in Google maps, this is a plane as well
        linecolor = "#FF0000";
    }
    else if (vehicle === 2)
    {
        // train, green
        linecolor = "#1C7F00";
    }
    else if (vehicle === 4)
    {
        // boat, black
        linecolor = "#000000";
    }
    else if (vehicle === 21)
    {
        // foot, brown #B73819
        linecolor = "#B73819";
    }
    else
    {
        // blue, the default
        linecolor = "#0000FF";
    }

    return linecolor;
};

HcCs.MarkerImage = function (index)
{
    var days = parseInt(MapLocations[index][HcCs.Dt.Days]);
    var image = "";

  if (days > 9)
    {
        if (days > 20)
        {
           image = "mm_20_blue.png"; 
        }
        else
        {
           image = "mm_20_green.png"; 
        }       
    }
    else
    {
        if (days > 4)
        {
           image = "mm_20_gray.png"; 
        }
        else
        {
           image = "mm_20_yellow.png"; 
        } 
        if(days == 2)
         {
           image = "mm_20_brown.png"; 
        }
        if(days == 1)
         {
           image = "mm_20_red.png"; 
        }            
    }

    return "/trip/pix/" + image;
};
