﻿function mapView(){
    document.getElementById('listmapview').className='selected';
    document.getElementById('liststandardview').className='';
    document.getElementById('property-grid').style.display='none';
    document.getElementById('map-view').style.display='block';
}

function standardView(){
    document.getElementById('listmapview').className='';
    document.getElementById('liststandardview').className='selected';
    document.getElementById('property-grid').style.display='block';
    document.getElementById('map-view').style.display='none';
}

function GoogleMapControlObj(containerName)
{
    this.ContainerName = containerName;
    this.Map;
    this.Geocoder;
    this.Properties = null;
    this.PropertiesLoaded = false;
    //this.PropertyIndex = 0;
    var me = this;
    
    // methods
    
    this.InitMap = function()
    {
        if (GBrowserIsCompatible()) {
            // map
            this.Map = new GMap2(document.getElementById(this.ContainerName));
            this.Map.setCenter(new GLatLng(50.728748, -1.847307), 8);
            this.Map.addControl(new GLargeMapControl());
            this.Map.enableScrollWheelZoom();
            var mapControl = new GMapTypeControl();
            this.Map.addControl(mapControl);
            // geocoder
            this.Geocoder = new GClientGeocoder();
        }
    }
    
    this.LoadProperties = function()
    {
        this.PropertiesLoaded = true;
        this.Map.clearOverlays();
        for (var i=0; i<this.Properties.length; i++)
        {
            var point = new GLatLng(me.Properties[i][0], me.Properties[i][1])
            var marker = new GMarker(point, { clickable: true });
            marker.bindInfoWindowHtml(me.Properties[i][2]);
            me.Map.addOverlay(marker);
            me.Map.setCenter(point, 9);
        }
    }
    
//    this.LoadProperties = function()
//    {
//        //this.Properties = properties;
//        this.Map.clearOverlays();
//        this.PropertiesLoaded = true;
//        this.PropertyIndex = 0;
//        this.LoadNextProperty();
//    }
//    
//    this.LoadNextProperty = function()
//    {
//        if (this.PropertyIndex < this.Properties.length)
//        {
//            this.PropertyIndex++;
//            this.Geocoder.getLatLng(this.Properties[this.PropertyIndex-1][0]+', UK', this.TestCallback);
//        }
//    }
//    
//    this.TestCallback = function(point)
//    {
//        if (point != null)
//        {
//            var marker = new GMarker(point, { clickable: true });
//            if (me.PropertyIndex == 1) me.Map.setCenter(point, 9);
//            marker.bindInfoWindowHtml(me.Properties[me.PropertyIndex-1][1]);
//            me.Map.addOverlay(marker);
//        }
//        me.LoadNextProperty();
//    }
//    
    this.InitMap();
}