function MapTypeControl(routeId, mapId) {
    this.routeId = routeId;
    this.mapId = mapId;
}

MapTypeControl.prototype = new GControl();

MapTypeControl.prototype.initialize = function(map) {
    map.removeMapType(G_SATELLITE_MAP);
    map.addMapType(G_PHYSICAL_MAP);

    var container = document.createElement("div");
    container.innerHTML = mapTypeControlHtml.gsub('!{mapId}', this.routeId + "-" + this.mapId);
    map.getContainer().appendChild(container);
    return container;
}



// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
MapTypeControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(20, 0));
}


function resetMapTypeButtons(routeId, mapId) {
    document.getElementById(routeId + '-' + mapId + 'mapTypeNormalUnselected').style.display = "block";
    document.getElementById(routeId + '-' + mapId + 'mapTypeNormalSelected').style.display = "none";
    document.getElementById(routeId + '-' + mapId + 'mapTypeSatelliteUnselected').style.display = "block";
    document.getElementById(routeId + '-' + mapId + 'mapTypeSatelliteSelected').style.display = "none";
    document.getElementById(routeId + '-' + mapId + 'mapTypePhysicalUnselected').style.display = "block";
    document.getElementById(routeId + '-' + mapId + 'mapTypePhysicalSelected').style.display = "none";
}
function showNormalMap(suffix) {
    bqc.gaLogger.log(bqc.params.p_mode_org, bqc.GAnalyticsStrings.level2.mapType, bqc.GAnalyticsStrings.level3.normalType);
    var targetMap = map;
    var ids = suffix.split("-");
    var mapId = ids[1];
    var routeId = ids[0];
    if(!mapId){
        mapId = '';
    }
    if(!routeId){
        routeId = '';
    }
    if (mapId != '' && routeId != '') {
        targetMap = bqc.routerDetail.segmentMaps[routeId][mapId];
    }
    resetMapTypeButtons(routeId, mapId);
    document.getElementById(routeId + '-' + mapId + 'mapTypeNormalUnselected').style.display = "none";
    document.getElementById(routeId + '-' + mapId + 'mapTypeNormalSelected').style.display = "block";
    targetMap.setMapType(G_NORMAL_MAP);
}
function showSatelliteMap(suffix) {
    bqc.gaLogger.log(bqc.params.p_mode_org, bqc.GAnalyticsStrings.level2.mapType, bqc.GAnalyticsStrings.level3.satelliteType);
    var targetMap = map;
    var ids = suffix.split("-");
    var mapId = ids[1];
    var routeId = ids[0];
    if(!mapId){
        mapId = '';
    }
    if(!routeId){
        routeId = '';
    }
    if (mapId != '' && routeId != '') {
        targetMap = bqc.routerDetail.segmentMaps[routeId][mapId];
    }
    resetMapTypeButtons(routeId, mapId);
    document.getElementById(routeId + '-' + mapId + 'mapTypeSatelliteUnselected').style.display = "none";
    document.getElementById(routeId + '-' + mapId + 'mapTypeSatelliteSelected').style.display = "block";
    targetMap.setMapType(G_HYBRID_MAP);
}
function showPhysicalMap(suffix) {
    bqc.gaLogger.log(bqc.params.p_mode_org, bqc.GAnalyticsStrings.level2.mapType, bqc.GAnalyticsStrings.level3.reliefType);
    var targetMap = map;
    var ids = suffix.split("-");
    var mapId = ids[1];
    var routeId = ids[0];
    if(!mapId){
        mapId = '';
    }
    if(!routeId){
        routeId = '';
    }
    if (mapId != '' && routeId != '') {
        targetMap = bqc.routerDetail.segmentMaps[routeId][mapId];
    }
    resetMapTypeButtons(routeId, mapId);
    document.getElementById(routeId + '-' + mapId + 'mapTypePhysicalUnselected').style.display = "none";
    document.getElementById(routeId + '-' + mapId + 'mapTypePhysicalSelected').style.display = "block";
    targetMap.setMapType(G_PHYSICAL_MAP);
}



function applyMapType(targetMap, mapType) {
    if (mapType == 1) {
        targetMap.setMapType(G_NORMAL_MAP);
    } else if (mapType == 2) {
        targetMap.setMapType(G_HYBRID_MAP);
    } else if (mapType == 3) {
        targetMap.setMapType(G_PHYSICAL_MAP);
    } else {
    }
}

function getMapType(targetMap) {
    var mapType = targetMap.getCurrentMapType();
    if (mapType == G_NORMAL_MAP) {
        return 1;
    } else if (mapType == G_HYBRID_MAP) {
        return 2;
    } else if (mapType == G_PHYSICAL_MAP) {
        return 3;
    } else {
        return -1;
    }
}

