﻿// SEKO Locations Google Map


var map;

$(document).ready(function() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(10, 10), 2);

        /**/
        var customUI = map.getDefaultUI();
        customUI.controls.scalecontrol = false;
        customUI.controls.largemapcontrol3d = false;
        customUI.maptypes.satellite = false;
        customUI.maptypes.hybrid = false;
        customUI.maptypes.physical = false;
        map.setUI(customUI);

        map.addControl(new GLargeMapControl3D(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5, 100)));

        var customIcon = new GIcon(G_DEFAULT_ICON);
        customIcon.image = "/images/map_marker_small.png";
        customIcon.iconSize = new GSize(7, 7);
        customIcon.iconAnchor = new GPoint(4, 3);
        customIcon.shadow = '';

        GDownloadUrl("/map/locations.ashx", function(data) {
            var xml = GXml.parse(data);
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
                createMarker(markers[i]);
            }
        });
    }

    $("#map_locations ul.AspNet-Menu > li:last-child").children('ul').addClass('right');
    $("#map_locations ul.AspNet-Menu > li:nth-child(3)").children(":first-child").addClass('wrap');

    $("#map_locations ul .AspNet-Menu-WithChildren").hover(
      function() { $(this).children('ul').slideDown(250).prev().addClass('open'); },
      function() { $(this).children('ul').slideUp(250).prev().removeClass('open'); }
    );

    function createMarker(location) {
        var latlng = new GLatLng(parseFloat(location.getAttribute("lat")), parseFloat(location.getAttribute("lng")));
        var marker = new GMarker(latlng, { icon: customIcon });
        map.addOverlay(marker);
    }
});

String.format = function()
{
    var s = arguments[0];
    for (var i = 0; i < arguments.length - 1; i++)
    {
        var reg = new RegExp("\\{" + i + "\\}", "gm");
        s = s.replace(reg, arguments[i + 1]);
    }
    return s;
}

function htmlDecode(value)
{
    return value.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}

function moveMapTo(continent)
{
    switch (continent)
    {
        case 'europe':
            map.setCenter(new GLatLng(51.890053935216926, 21.09375), 4);
            break;
        case 'northamerica':
            map.setCenter(new GLatLng(49.837982453084834, -101.07421875), 3);
            break;
        case 'southamerica':
            map.setCenter(new GLatLng(-25.641526373065755, -55.72265625), 3);
            break;
        case 'africa':
            map.setCenter(new GLatLng(3.6888551431470478, 26.3671875), 3);
            break;
        case 'asia':
            map.setCenter(new GLatLng(36.4566360115962, 88.76953125), 3);
            break;
        case 'australianewzealand':
            map.setCenter(new GLatLng(-26.11598592533351, 146.07421875), 3);
            break;
        case 'middleeast':
            map.setCenter(new GLatLng(30.890053935216926, 51.09375), 4);
            break;
        default:
            break;
    }
}

