﻿//general.js
function addLayers() {
    //	ml = new MapLayer("Events", "/WebServices/MapService.svc/GetEventsByBounds", {}, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8 });
    //	ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    //	ml.onMaxResults = function() { $("#tooManyResults").show(); };
    //	ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    //	ml.MarkerOptions = { icon: createicon('/images/map/events_icon_sm.png') };
    //	ml.onClick = evMarkerClick;
    //	cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Architecture & Public Art' };
    ml = new MapLayer("Architecture & Public Art", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.MarkerOptions = { icon: createicon('/images/map/architecture_icon.png') };
    ml.onClick = orgMarkerClick;
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Visual Arts' };
    ml = new MapLayer("Visual Arts", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/visualart_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Museums' };
    ml = new MapLayer("Museums", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/museum_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Live Theater' };
    ml = new MapLayer("Live Theater", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/theatre_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'World Music' };
    ml = new MapLayer("World Music", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/worldmusic_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Opera' };
    ml = new MapLayer("Opera", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/opera_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Symphony' };
    ml = new MapLayer("Symphony", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/symphony_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Dance' };
    ml = new MapLayer("Dance", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/dance_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Film' };
    ml = new MapLayer("Film", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/film_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Band & Ensembles' };
    ml = new MapLayer("Band & Ensembles", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/band_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Farmers Market' };
    ml = new MapLayer("Farmers Market", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.MarkerOptions = { icon: createicon('/images/map/farmers_icon.png') };
    ml.onClick = orgMarkerClick;
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Festival' };
    ml = new MapLayer("Festival", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/festival_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Parks & Gardens' };
    ml = new MapLayer("Parks & Gardens", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/park_icon.png') };
    cgm.addLayer(ml);

    var jdata = { 'orgtype': 'Multidisciplinary' };
    ml = new MapLayer("Multidisciplinary", "/WebServices/MapService.svc/GetOrgsByQuery", jdata, { visible: false, center: false, filterMb: true, cluster: true, maxClusterZoom: 12, minZoom: 8, group: 'dest' });
    ml.ClusterMarkerOptions = { icon: cicon, clickable: true, labelOffset: new GSize(22, 19) };
    ml.onMaxResults = function() { $("#tooManyResults").show(); };
    ml.onLayerLoadComplete = function() { $("#tooManyResults").hide(); };
    ml.onClick = orgMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/multi_icon.png') };
    cgm.addLayer(ml);

    jdata = { 'query': 'airports' };
    ml = new MapLayer("Airports", "/WebServices/MapService.svc/GetMetroByQuery", jdata, { visible: false, center: false, filterMb: false, cluster: false, autoLabel: false });
    ml.onClick = airportMarkerClick;
    ml.MarkerOptions = { icon: createicon('/images/map/airport_icon.png') };
    cgm.addLayer(ml);

    if (typeof (metrovisible) == "undefined") {
        metrovisible = true;
    }

    jdata = { 'query': '' };
    ml = new MapLayer("Metro Points", "/WebServices/MapService.svc/GetMetroByQuery", jdata, { visible: metrovisible, center: false, filterMb: false, cluster: false, autoLabel: false, group: 'Metro' });
    ml.onClick = metroMarkerClick;
    ml.MarkerOptions = { icon: micon };
    cgm.addLayer(ml);

    tl = new TileLayer("Metro Lines", "http://mapserver.civicresource.com/xlamapservice/11111/XLA/_vemap/", { opacity: 1.0, visible: metrovisible, group: 'Metro' });
    cgm.addLayer(tl);
}
function repos() {
    var legendTop = $("#map_canvas").position().top;
    var legendLeft = $("#map_canvas").position().left + $("#map_canvas").width() - $("#layerControl").width();
    $("#layerControl").show()
		.css("top", legendTop + "px").css("left", legendLeft + "px");
}
var infoWindowWidth = 250;
function createicon(url) {
    var icon = new GIcon(G_DEFAULT_ICON);
    icon.image = url;
    icon.iconSize = new GSize(19, 20);
    icon.iconAnchor = new GPoint(5, 5);
    icon.shadowSize = new GSize(0, 0);
    icon.infoWindowAnchor = new GPoint(25, 7);
    return icon;
}
function airportMarkerClickOpen(mo) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/WebServices/MapWebService.asmx/GetAirportInfoWindow",
        data: "{'id':" + mo.Id + "}",
        dataType: "text",
        success: function(data) {
            mo.GOverlay.openInfoWindow(data, { maxWidth: infoWindowWidth });
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            //alert("request:" + XMLHttpRequest + ", status: " + textStatus + ", error: " + errorThrown);
        }
    });
}
function metroMarkerClickOpen(mo) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/WebServices/MapWebService.asmx/GetMetroInfoWindow",
        data: "{'id':" + mo.Id + "}",
        dataType: "text",
        success: function(data) {
            mo.GOverlay.openInfoWindow(data, { maxWidth: infoWindowWidth });
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            //alert("request:" + XMLHttpRequest + ", status: " + textStatus + ", error: " + errorThrown);
        }
    });
}
function orgMarkerClickOpen(mo) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/WebServices/MapWebService.asmx/GetOrgInfoWindow",
        data: "{'id':" + mo.Id + "}",
        dataType: "text",
        success: function(data) {
            mo.GOverlay.openInfoWindow(data, { maxWidth: infoWindowWidth });
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            //alert("request:" + XMLHttpRequest + ", status: " + textStatus + ", error: " + errorThrown);
        }
    });
}
function evMarkerClickOpen(mo) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/WebServices/MapWebService.asmx/GetEventInfoWindow",
        data: "{'id':" + mo.Id + "}",
        dataType: "text",
        success: function(data) {
            mo.GOverlay.openInfoWindow(data, { maxWidth: infoWindowWidth });
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            //alert("request:" + XMLHttpRequest + ", status: " + textStatus + ", error: " + errorThrown);
        }
    });
}
//function homePromoMarkerClickOpen(mo) {
//    $.ajax({
//        type: "POST",
//        contentType: "application/json; charset=utf-8",
//        url: "/WebServices/MapWebService.asmx/GetHomePromoInfoWindow",
//        data: "{'id':" + mo.Id + "}",
//        dataType: "text",
//        success: function(data) {
//            mo.GOverlay.openInfoWindow(data, { maxWidth: infoWindowWidth });
//        },
//        error: function(XMLHttpRequest, textStatus, errorThrown) {
//            //alert("request:" + XMLHttpRequest + ", status: " + textStatus + ", error: " + errorThrown);
//        }
//    });
//}

//function funMeterMarkerClickOpen(mo) {
//    $.ajax({
//        type: "POST",
//        contentType: "application/json; charset=utf-8",
//        url: "/WebServices/MapWebService.asmx/GetFunMeterInfoWindow",
//        data: "{'id':" + mo.Id + "}",
//        dataType: "text",
//        success: function(data) {
//            mo.GOverlay.openInfoWindow(data, { maxWidth: infoWindowWidth });
//        },
//        error: function(XMLHttpRequest, textStatus, errorThrown) {
//            //alert("request:" + XMLHttpRequest + ", status: " + textStatus + ", error: " + errorThrown);
//        }
//    });
//}

function hotelMarkerClickOpen(mo) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/WebServices/MapWebService.asmx/GetHotelInfoWindow",
        data: "{'id':" + mo.Id + "}",
        dataType: "text",
        success: function(data) {
            mo.GOverlay.openInfoWindow(data, { maxWidth: infoWindowWidth });
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            //alert("request:" + XMLHttpRequest + ", status: " + textStatus + ", error: " + errorThrown);
        }
    });
}
function metroMarkerClick(o, ll, oll) {
    var crgmap = this;
    var mo = crgmap.findOverlay(o);
    metroMarkerClickOpen(mo);
}
function airportMarkerClick(o, ll, oll) {
    var crgmap = this;
    var mo = crgmap.findOverlay(o);
    airportMarkerClickOpen(mo);
}
function orgMarkerClick(o, ll, oll) {
    var crgmap = this;
    var mo = crgmap.findOverlay(o);
    orgMarkerClickOpen(mo);
}
function evMarkerClick(o, ll, oll) {
    var crgmap = this;
    var mo = crgmap.findOverlay(o);
    evMarkerClickOpen(mo);
}
//function homePromoMarkerClick(o, ll, oll) {
//    var crgmap = this;
//    var mo = crgmap.findOverlay(o);
//    homePromoMarkerClickOpen(mo);
//}
//function funMarkerMarkerClick(o, ll, oll) {
//    var crgmap = this;
//    var mo = crgmap.findOverlay(o);
//    funMeterMarkerClickOpen(mo);
//}

function hotelsMarkerClick(o, ll, oll) {
    var crgmap = this;
    var mo = crgmap.findOverlay(o);
    hotelMarkerClickOpen(mo);
}
function toggle(name) {
    cgm.toggleLayer(name);
}
function pan(id) {
    cgm.panToOverlayById(id);
}
function mapResize() {
    $("#map_canvas").height(800);
}
var photosVisible = false;
function togglePhotos() {
    if (photosVisible) {
        photosLayer.hide();
        photosVisible = false;
    }
    else {
        photosLayer.show();
        photosVisible = true;
    }
}
function layerClick() {
    if ($(this).attr("checked")) {
        cgm.showLayer($(this).attr("name"));
    } else {
        cgm.hideLayer($(this).attr("name"));
    }
}
function toggleGroup(chk, gname) {
    if ($(chk).attr("checked")) {
        cgm.showLayerGroup(gname);
        $(":checkbox." + gname).attr("checked", "true");
    } else {
        cgm.hideLayerGroup(gname);
        $(":checkbox." + gname).removeAttr("checked");
    }
}
function toggleGroupDiv(img, gdiv) {
    $("#" + gdiv).toggle();
}
function setupLayers() {
    enableLayerGroup("Public Transit", "Metro");
    //enableLayerGroup("Destinations", "dest");
    enableLayer("Architecture & Public Art");
    enableLayer("Visual Arts");
    enableLayer("Museums");
    enableLayer("Live Theater");
    enableLayer("World Music");
    enableLayer("Opera");
    enableLayer("Symphony");
    enableLayer("Dance");
    enableLayer("Film");
    enableLayer("Band & Ensembles");
    enableLayer("Farmers Market");
    enableLayer("Festival");
    enableLayer("Parks & Gardens");
    enableLayer("Multidisciplinary");
}
function enableLayer(name) {
    _enableLayer(name, cgm.isLayerEnabled(name));
}
function enableLayerGroup(name, gname) {
    _enableLayer(name, cgm.isLayerGroupEnabled(gname));
}
function _enableLayer(name, enable) {
    var chkbox = $("input[name='" + name + "']");

    if (!enable) {
        chkbox.attr("disabled", "disabled");
        chkbox.next().css("color", "Gray");
    }
    else {
        chkbox.removeAttr("disabled");
        chkbox.next().css("color", "Black");
    }
}
var layerControlVisible = true;
function toggleLayerControl() {
    if (layerControlVisible) {
        $("#layers").hide(); //, { direction: "right" });
        layerControlVisible = false;
        $("#layer-toggle img").attr("src", "images/map/sidebarArrowLeft.png");
        //alignLayerControl();
    }
    else {
        $("#layerControl").css("left", 0);
        $("#layers").show();
        layerControlVisible = true;
        $("#layer-toggle img").attr("src", "images/map/sidebarArrow.png");
        //alignLayerControl();
    }
}

var destV = true;
function toggleDest() {
    if (destV) {
        $("#dest-expand").text("-");
        $("#dest-group").hide();
        destV = false;
    }
    else {
        $("#dest-expand").text("+");
        $("#dest-group").show();
        destV = true;
    }
}

function openEventGeo(eventid) {
    var zoom = 13;
    var overlays = cgm.findOverlaysById(eventid);
    if (overlays.length > 0) {
        var mo = overlays.pop();
        if (cgm.GMap.getZoom() > zoom)
            zoom = cgm.GMap.getZoom();

        cgm.panToOverlay(mo, zoom);
        evMarkerClickOpen(mo);
    }
}
//general.js


//icons.js
var micon = new GIcon(G_DEFAULT_ICON);
micon.image = '/images/map/ico_metro.png';
micon.iconSize = new GSize(13, 13);
micon.iconAnchor = new GPoint(0, 0);
micon.shadowSize = new GSize(0, 0);
micon.infoWindowAnchor = new GPoint(25, 7);

var cicon = new GIcon(G_DEFAULT_ICON);
cicon.image = '/images/map/marker_cluster.png';
cicon.iconSize = new GSize(53, 52);
cicon.iconAnchor = new GPoint(0, 0);
cicon.shadowSize = new GSize(0, 0);
cicon.infoWindowAnchor = new GPoint(25, 7);

var sicon = new GIcon(G_DEFAULT_ICON);
sicon.image = '/images/map/search_marker.png';
sicon.iconSize = new GSize(26, 34);
//sicon.iconAnchor = new GPoint(0, 0);
//sicon.shadowSize = new GSize(0, 0);
//sicon.infoWindowAnchor = new GPoint(25, 7);

var dicon = new GIcon(G_DEFAULT_ICON);
dicon.image = '/images/map/dest_num_icon.png';
dicon.iconSize = new GSize(31, 32);

var evicon = new GIcon(G_DEFAULT_ICON);
evicon.image = '/images/map/event_num_mapicon.png';
evicon.iconSize = new GSize(34, 31);

var pinicon = new GIcon(G_DEFAULT_ICON);
pinicon.image = '/images/map/events_icon.png';
pinicon.iconSize = new GSize(32, 32);

var funicon = new GIcon(G_DEFAULT_ICON);
funicon.image = '/images/map/map_glass.png';
funicon.iconSize = new GSize(34, 31);
funicon.iconAnchor = new GPoint(0, 0);
funicon.infoWindowAnchor = new GPoint(25, 7);
//icons.js
