﻿function HideMap()  {
    if (document.getElementById('MapDisplay').innerHTML=='Show Map') {
            document.getElementById('map').style.display='block';
            if (document.getElementById('ShowOnMap'))   {
                document.getElementById('ShowOnMap').style.display='block';
                }
            document.getElementById('MapDisplay').innerHTML='Hide Map'; }
    else if (document.getElementById('MapDisplay').innerHTML=='Hide Map') {
            document.getElementById('map').style.display='none';
            if (document.getElementById('ShowOnMap'))   {
                document.getElementById('ShowOnMap').style.display='none';
                }
	    document.getElementById('MapDisplay').innerHTML='Show Map';}
        }
        
function EnableStreetView()  {
    if (document.getElementById('PanoramaFrameInfo').style.display=='block') {
        document.getElementById('PanoramaFrameInfo').style.display='none';
        document.getElementById('PanoramaFrame').style.display='none';
        map.removeOverlay(svOverlay);
        document.getElementById('StreetMapView').innerHTML='Enable Street View';
        }
    else {
        document.getElementById('PanoramaFrameInfo').style.display='block';
        document.getElementById('StreetMapView').innerHTML='Disable Street View';
        svOverlay = new GStreetviewOverlay();
        map.addOverlay(svOverlay);
        GEvent.addListener(map,"click", function(overlay,latlng) {
            document.getElementById('PanoramaFrame').style.display='block';
            myPano.setLocationAndPOV(latlng);
            });
        }
    }

function MapResize()  {
    if (document.getElementById('MapResize').innerHTML=='Enlarge Map') {
        if (document.getElementById('MapDisplay').innerHTML=='Show Map') {
            document.getElementById('map').style.display='block';
            document.getElementById('MapDisplay').innerHTML='Hide Map';
            }              
        document.getElementById('map').className='MapLarge';
        document.getElementById('MapResize').innerHTML='Reduce Map';
    }
    else if (document.getElementById('MapResize').innerHTML=='Reduce Map') {
        if (document.getElementById('MapDisplay').innerHTML=='Show Map'){
            document.getElementById('map').style.display='block';
            document.getElementById('MapDisplay').innerHTML='Hide Map';
            }        
        document.getElementById('map').className='MapNormal';
        document.getElementById('MapResize').innerHTML='Enlarge Map';
    }
} 
       
function MapIcon(iconType) {
    var baseIcon = new GIcon();
    var icons=[];
    var type;
    
    baseIcon.image = "../../Common/img/icons/BlankMapIcon.png";
    baseIcon.shadow = "";  
    
    if ((typeof(iconType)=="undefined") || (iconType==null)) { 
        type = "PointOfInterest" 
    } else { 
        type = iconType; 
    }
    
    if  ((type="Town") || (type="County"))   {
        baseIcon.iconAnchor = new GPoint(23, 2);
        baseIcon.iconSize = new GSize(25, 28);
        baseIcon.infoWindowAnchor = new GPoint(12, 20);
        }
    else    {
        baseIcon.iconAnchor = new GPoint(28, 31);
        baseIcon.iconSize = new GSize(30, 33);
        baseIcon.infoWindowAnchor = new GPoint(15, 1);
        }   
    
    if (!icons[iconType]) {
        var icon = new GIcon(baseIcon);
        icon.image = "../../Common/img/icons/"+ type +"MapIcon.png";
        icons[iconType]=icon;
    } 
    return icons[iconType];
}

function Markers(Type, SubType){
    map.closeInfoWindow();
    if (SubType=="Neighborhood" | SubType=="Condominium") {
        if (document.getElementById(SubType)) { 
            if (document.getElementById(SubType).checked==false) { // hide the marker
                for (var i=0;i<gmarkers.length;i++) {
                    if (gmarkers[i].subtype==SubType)  {
                        map.removeOverlay(gmarkers[i]);
                    }
                }
            }
            else { // show the marker again
                for (var i=0;i<gmarkers.length;i++) {
                if (gmarkers[i].subtype==SubType)  {                                            
                    map.addOverlay(gmarkers[i], icon);
                    }
                }
            }
        }
        else { // show the marker again
            for (var i=0;i<gmarkers.length;i++) {
                if (gmarkers[i].subtype==SubType)  {                                            
                    map.addOverlay(gmarkers[i], icon);
                    }
            }
        }
    }
    else    {   
        if (document.getElementById(Type)) { 
            if (document.getElementById(Type).checked==false) { // hide the marker
                for (var i=0;i<gmarkers.length;i++) {
                    if (gmarkers[i].type==Type)  {
                        map.removeOverlay(gmarkers[i]);
                    }
                }
            }
            else { // show the marker again
                for (var i=0;i<gmarkers.length;i++) {
                if (gmarkers[i].type==Type)  {                                            
                    map.addOverlay(gmarkers[i], icon);
                    }
                }
            }
        }
        else { // show the marker again
            for (var i=0;i<gmarkers.length;i++) {
                if (gmarkers[i].type==Type)  {                                            
                    map.addOverlay(gmarkers[i], icon);
                    }
            }
        }
    }
}

function showTooltip(marker) {
    tooltip.innerHTML = marker.tooltip;
	var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor = marker.getIcon().iconAnchor;
	var width = marker.getIcon().iconSize.width;
	var height = tooltip.clientHeight;
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - 15 - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
}
