var roundFloat = function (a, p) {
    if (p == null)
        p = 0;
    p = Math.pow(10, p);
    return Math.round(a * p) / p;
};

Effect.MoveAndScale = function (element, x, y, procent) {
    element = $(element);
    return new Effect.Scale(element, procent, Object.extend({
        scaleContent: false,
        moveFromX: parseFloat(element.getStyle('left') || '0') + element.getWidth() / 2,
        moveFromY: parseFloat(element.getStyle('top') || '0') + element.getHeight() / 2,
        moveToX: x,
        moveToY: y,
        afterUpdateInternal: function(effect) {
            effect.element.setStyle({
                top: Math.round(effect.options.moveToY + (effect.options.moveFromY - effect.options.moveToY) * (1 - effect.position) - effect.element.getHeight() / 2.0) + 'px',
                left: Math.round(effect.options.moveToX + (effect.options.moveFromX - effect.options.moveToX) * (1 - effect.position) - effect.element.getWidth() / 2.0) + 'px'
            });
        },
        afterFinishInternal: function(effect) {
        	effect.element.setStyle({
        		top: Math.round(effect.options.moveToY - effect.element.getHeight() / 2.0) + 'px',
                left: Math.round(effect.options.moveToX - effect.element.getWidth() / 2.0) + 'px'
        	});
        }
    }, arguments[4] || {}))
};

Thumb = Class.create();
Object.extend(Thumb.prototype, {
    height: 90,
    width: 110,
    currentEffect: null,
    loaded: false,
    element: null,
    parent: null,
    imgUrl: null,
    linkUrl: null,
    minimalUrl: null,
    address: null,

    initialize: function(parent, thumbs) {
	        this.parent = $(parent);
	        this.imgUrl = thumbs.img;
	        this.linkUrl = thumbs.url;
	        this.minimalUrl = thumbs.minimal_url;
	        this.address = thumbs.address;
    },

    set: function(x, y, w, h) {
        if (!this.loaded) {
            this.element = Builder.node('a', {title: 'Click here.', href: this.linkUrl}, [Builder.node('img', {src: this.imgUrl, alt: 'Click here.'})]);
            this.element = $(this.element);
            this.element.setStyle({
                    width: Math.round(w) + 'px',
                    height: Math.round(h) + 'px',
                    position: 'absolute',
                    top: Math.round(y - (h / 2.0)) + 'px',
                    left: Math.round(x - (w / 2.0)) + 'px'
                });
            this.element.observe('mousedown', (function(event) {
            	if (!event.isLeftClick())
            		return;
            	myLightWindow.activateWindow({
                    href: this.minimalUrl,
                    title: trans.property_details,
                    width: 900
                });
                event.stop();}).bind(this));
           	this.element.observe('click', function(event) {
           		if (event.isLeftClick())
            		event.stop();
           	});
            this.parent.appendChild(this.element);
            this.loaded = true;
        }
        else {
            this.element.setStyle({
                    width: w,
                    height: h,
                    top: y - h / 2.0,
                    left: x - w / 2.0
                });
        }
        return this;
    },

    set_dataset: function(x, y, w, h) {
        if (!this.loaded) {
            this.element = Builder.node('a', {title: 'Click here.', href: 'google.com'}, [Builder.node('img', {src: 'google.com', alt: 'Click here.'})]);
            this.element = $(this.element);
            this.element.setStyle({
                    width: Math.round(w) + 'px',
                    height: Math.round(h) + 'px',
                    position: 'absolute',
                    top: Math.round(y - (h / 2.0)) + 'px',
                    left: Math.round(x - (w / 2.0)) + 'px'
                });
            this.element.observe('mousedown', (function(event) {
            	if (!event.isLeftClick())
            		return;
            	myLightWindow.activateWindow({
                    href: this.minimalUrl,
                    title: trans.property_details,
                    width: 900
                });
                event.stop();}).bind(this));
           	this.element.observe('click', function(event) {
           		if (event.isLeftClick())
            		event.stop();
           	});
            //this.parent.appendChild(this.element);
            this.loaded = true;
        }
        else {
            this.element.setStyle({
                    width: w,
                    height: h,
                    top: y - h / 2.0,
                    left: x - w / 2.0
                });
        }
        return this;
    },

    set_right: function() {
        if (!this.loaded)
            return this.set(280, 60, 1, 1);
        return this.hide_right();
    },

    set_left: function() {
        if (!this.loaded)
            return this.set(-20, 60, 1, 1);
        return this.hide_left();
    },

    remove: function() {
        this.loaded = false;
        this.element.remove();
        delete this.element;
        this.element = null;
    },

    move: function(x, y, procent) {
        if (this.currentEffect)
            this.currentEffect.cancel();
        this.currentEffect = new Effect.MoveAndScale(this.element, x, y, procent, Object.extend({
                scaleMode: { originalHeight: this.height, originalWidth: this.width },
                scaleFrom: this.element.getWidth() * 1.0 / this.width * 100.0,
                duration: 0.5
            }, arguments[3] || {}));
        return this;
    },

    move_center: function() {
        return this.move(130, 60, 100, arguments[0] || {});
    },

    move_right: function() {
        return this.move(222, 60, 50, arguments[0] || {});
    },

    move_left: function() {
        return this.move(37, 60, 50, arguments[0] || {});
    },

    hide_right: function() {
        return this.move(280, 60, 1, arguments[0] || {})
    },

    hide_left: function() {
        return this.move(-20, 60, 1, arguments[0] || {})
    },

    remove_right: function() {
        return this.move(280, 60, 1, Object.extend({afterFinishInternal: this.remove.bind(this)}, arguments[0] || {}));
    },

    remove_left: function() {
        return this.move(-20, 60, 1, Object.extend({afterFinishInternal: this.remove.bind(this)}, arguments[0] || {}));
    }
});

Thumbs = Class.create();
Object.extend(Thumbs.prototype, {
    thumbs: null,
    current: null,
    size: null,
    container: null,
    info: null,
    desc: null,
    started: false,

    initialize: function(thumbs, container, info_container, desc_container) {

        this.container = $(container);
        this.info = $(info_container);
        this.desc = $(desc_container);
        this.thumbs = new Array();
        this.thumbs[0] = null;
        var i = 1;
        for (j in thumbs)
            if (thumbs[j].address)
            {
                this.thumbs[i] = new Thumb(this.container, thumbs[j]);
                ++i;
            }
        --i;
        this.size = i;
        this.current = 1;
    },

    start: function(record_type ,from) {

    	this.current = typeof (from) != 'undefined' ? from : 1;
    	if (this.current < 1)
    		this.current = 1;
    	if (this.current > this.size)
    		this.current = this.size;
        this.info.update(this.current + " " + trans.of + " " + this.size);
        this.desc.update(this.thumbs[this.current].address);

        if (this.current > 2)
            this.thumbs[this.current - 2].set_left();


        if (record_type == 'Dataset')
        {
	        if (this.current > 1)
	            this.thumbs[this.current - 1].set_dataset(37, 60, 1, 1).move_left();
	        if (this.current > 0)
	            this.thumbs[this.current].set_dataset(130, 60, 1, 1).move_center();
	        if (this.current + 1 <= this.size)
	            this.thumbs[this.current + 1].set_dataset(222, 60, 1, 1).move_right();
        }
        else
        {
            if (this.current > 1)
	            this.thumbs[this.current - 1].set(37, 60, 1, 1).move_left();
	        if (this.current > 0)
	            this.thumbs[this.current].set(130, 60, 1, 1).move_center();
	        if (this.current + 1 <= this.size)
	            this.thumbs[this.current + 1].set(222, 60, 1, 1).move_right();
        }


        if (this.current + 2 <= this.size)
            this.thumbs[this.current + 2].set_right();
        this.started = true;
    },

    next: function() {
        if (!this.started || this.current >= this.size)
            return this;

        if (this.current + 3 <= this.size)
            this.thumbs[this.current + 3].set_right();
        if (this.current + 2 <= this.size)
            this.thumbs[this.current + 2].move_right();
        this.thumbs[this.current + 1].move_center();
        this.thumbs[this.current].move_left();
        if (this.current - 1 >= 1)
            this.thumbs[this.current - 1].hide_left();
        if (this.current - 2 >= 1)
            this.thumbs[this.current - 2].remove_left();
        this.current = this.current + 1;
        this.info.update(this.current + " " + trans.of + " " + this.size);
        this.desc.update(this.thumbs[this.current].address);
        return this;
    },

    prev: function() {
        if (!this.started || this.current <= 1)
            return this;

        if (this.current >= 4)
            this.thumbs[this.current - 3].set_left();
        if (this.current >= 3)
            this.thumbs[this.current - 2].move_left();
        this.thumbs[this.current - 1].move_center();
        this.thumbs[this.current].move_right();
        if (this.current + 1 <= this.size)
            this.thumbs[this.current + 1].hide_right();
        if (this.current + 2 <= this.size)
            this.thumbs[this.current + 2].remove_right();
        this.current = this.current - 1;
        this.info.update(this.current + " " + trans.of + " " + this.size);
        this.desc.update(this.thumbs[this.current].address);
        return this;
    }
});

var Circle = Class.create();
Object.extend(Circle.prototype, {
    map: null,
    circle: null,
    circle_latlng: null,
    circle_info: null,
    centre: null,
    grid: null,

    initialize: function(map, circle_info) {
        this.map = map;
        this.circle_info = circle_info;

        this.calculate_circle_latlng(circle_info);
        this.centre = new google.maps.LatLng((parseFloat(circle_info.min_latitude) + parseFloat(circle_info.max_latitude)) / 2, (parseFloat(circle_info.min_longitude) + parseFloat(circle_info.max_longitude)) / 2);

        /*this.grid = new google.maps.Polyline([
                                                  new google.maps.LatLng(circle_info.min_latitude, circle_info.min_longitude),
                                                new google.maps.LatLng(circle_info.min_latitude, circle_info.max_longitude),
                                                new google.maps.LatLng(circle_info.max_latitude, circle_info.max_longitude),
                                                new google.maps.LatLng(circle_info.max_latitude, circle_info.min_longitude),
                                                new google.maps.LatLng(circle_info.min_latitude, circle_info.min_longitude),
                                              ]);
        map.map.addOverlay(this.grid);*/

        var circle_options = {icon: this.generate_icon(circle_info.record_type, circle_info.image_name, circle_info.num_recs,  circle_info.circle_size)};


        this.circle = new google.maps.Marker(this.circle_latlng, circle_options);

        google.maps.Event.addListener(this.circle, "click", this.on_click_callback.bind(this));

        this.map.map.addOverlay(this.circle);
    },

    generate_icon: function(record_type, image_name, num, size) {
        var icon = new google.maps.Icon();

        if (record_type == 'Property')
        {
        	icon.image = this.map.base_url + 'img/circle/' + num + '.png';
        	icon.shadow = this.map.base_url + 'img/circle_shadow/' + size + '.png';
        }
        else
        {
            icon.image = this.map.base_url + 'upload/images/dataset/' + image_name;

        }


        icon.iconSize = new google.maps.Size(size, size);
        icon.shadowSize = new google.maps.Size(parseInt(size) + 2, parseInt(size) + 2);
        icon.iconAnchor = new google.maps.Point(size / 2, size / 2);
        icon.infoWindowAnchor = new google.maps.Point(size / 2, size / 2);
        return icon;
    },

    calculate_circle_latlng: function (circle_info) {
        var se = this.map.map.fromLatLngToDivPixel(new google.maps.LatLng(circle_info.min_latitude, circle_info.max_longitude));
        var nw = this.map.map.fromLatLngToDivPixel(new google.maps.LatLng(circle_info.max_latitude, circle_info.min_longitude));
        var avg = this.map.map.fromLatLngToDivPixel(new google.maps.LatLng(circle_info.avg_latitude, circle_info.avg_longitude));
        var radius = parseInt(parseFloat(circle_info.circle_size) / 2) + 1;
        var min_x = nw.x + radius;
        var min_y = nw.y + radius;
        var max_x = se.x - radius;
        var max_y = se.y - radius;

        if (min_x >= max_x)
            avg.x = (min_x + max_x) / 2;
        else if (avg.x < min_x)
            avg.x = min_x;
        else if (avg.x > max_x)
            avg.x = max_x;

        if (min_y >= max_y)
            avg.y = (min_y + max_y) / 2;
        else if (avg.y < min_y)
            avg.y = min_y;
        else if (avg.y > max_y)
            avg.y = max_y;

        this.circle_latlng = this.map.map.fromDivPixelToLatLng(avg);
    },

    on_click_callback: function() {
        this.map.open_area(this.circle_info.dataset_id, this.circle_info.record_type, this.centre, this.circle.getLatLng(), this.circle_info.min_latitude, this.circle_info.max_latitude, this.circle_info.min_longitude, this.circle_info.max_longitude);
    }
});

var Map = Class.create();
Object.extend(Map.prototype, {
    map_container: null,
    map: null,
    base_url: null,
    start_lat: null,
    start_long: null,
    start_zoom: null,
    start_radius: null,
    original_radius: null,
    min_lat: null,
    max_lat: null,
    min_long: null,
    max_long: null,
    streetOverlayMode:false,
    options: {
        radius: 10
    },
    ajax: null,
    ajax_running: false,
    circles: new Array(),
    thumbs: null,
    map_loading: null,
    open_area_callback_handler: null,
    open_area_callback_options: null,

    initialize: function (map_container, base_url, start_lat, start_long, min_lat, max_lat, min_long, max_long) {
        this.map_container = $(map_container);
        this.base_url = base_url;
        this.start_lat = start_lat;
        this.start_long = start_long;
        this.min_lat = min_lat;
        this.max_lat = max_lat;
        this.min_long = min_long;
        this.max_long = max_long;

        Object.extend(this.options, arguments[8] || {});
        this.start_radius = this.options.radius;
        if (typeof (this.options.map_radius) != 'undefined')
            this.start_radius = this.options.map_radius;
        this.original_radius = this.options.radius;

        google.load('maps', '2');
        google.setOnLoadCallback(this.init.bind(this));

    },

    init: function () {
        var LoadingControl = function() {};
        LoadingControl.prototype = new google.maps.Control();
        LoadingControl.prototype.initialize = function (map) {
            var div = Builder.node('div', {id: 'map_loading'}, [Builder.node('div')]);
            map.getContainer().appendChild(div);
            return div;
        };
        LoadingControl.prototype.getDefaultPosition = function() {
            return new google.maps.ControlPosition(google.maps.ANCHOR_TOP_RIGHT, new google.maps.Size(7, 33));
        }

        this.map = new google.maps.Map2(this.map_container);

        this.map.addControl(new google.maps.MenuMapTypeControl());
        this.map.addControl(new google.maps.LargeMapControl3D());
        this.map.addControl(new google.maps.ScaleControl());
        this.map.addControl(new google.maps.OverviewMapControl());
        this.map.addControl(new LoadingControl());

        this.map_loading = $('map_loading');
        this.map.enableContinuousZoom();
        this.map.enableScrollWheelZoom();
        this.map.enableDoubleClickZoom();
        this.map.setCenter(new google.maps.LatLng(this.start_lat, this.start_long), 6);
        var bounds = new google.maps.LatLngBounds();
        bounds.extend(new google.maps.LatLng(this.min_lat, this.max_long));
        bounds.extend(new google.maps.LatLng(this.max_lat, this.min_long));
        this.start_zoom = this.map.getBoundsZoomLevel(bounds) + 1;
        this.map.setCenter(bounds.getCenter(), this.start_zoom);

        google.maps.Event.addListener(this.map, 'moveend', this.moveend_callback.bind(this));
        google.maps.Event.addListener(this.map, 'zoomend', this.zoomend_callback.bind(this));

        google.maps.Event.addListener(this.map, 'moveend', this.update_list_view_link.bind(this));

        // google street functionality
        this.checkbox = $('streetGrid');
        this.checkbox.checked = false;
        this.checkbox.observe('click', this.updateStreetOverlay.bind(this));

        $('map_streets').style.display = "block";
        $('map_streets').style.display = "none";

        this.update();
    },


    updateStreetOverlay: function (e)
    {
        this.map.clearOverlays();
        this.update();

        if ($('streetGrid').checked == true)
        {
	         $('map_streets').style.display = "none";
             $('map_streets').style.display = "block";

	         var center = this.map.getCenter();
	         x= center.lng();
	         y= center.lat();
	         street_marker_latlng = new GLatLng(y,x);

	         var street_icon = new google.maps.Icon();
	         var imageUrl = "http://maps.google.com/intl/en_us/mapfiles/cb/man_arrow-1.png";

	         street_icon.image = imageUrl;
	         street_icon.iconSize = new google.maps.Size(49,52);
	         street_icon.iconAnchor =  new google.maps.Point(25,36);

	         street_marker = new google.maps.Marker(street_marker_latlng, {"icon":street_icon, "draggable":true});


	         google.maps.Event.addListener(street_marker, "dragstart", function()
	         {
	              dragging = true;
	         });


	         google.maps.Event.addListener(street_marker, "dragend", function()
	         {
	             dragging = false;

	     		 street_marker_latlng = street_marker.getPoint();

	             //select street view
	             var Street = new google.maps.StreetviewPanorama(document.getElementById("map_streets"));
	     		 Street.setLocationAndPOV(street_marker_latlng);
	         });

	         //add google streets overlay
	         this.svOverlay = new google.maps.StreetviewOverlay();
	         this.map.addOverlay(this.svOverlay);

	         this.map.addOverlay(street_marker);
        }
        else
        {
             //remove google streets overlay
	         this.map.removeOverlay(this.svOverlay);

	         $('map_streets').style.display = "block";
             $('map_streets').style.display = "none";
        }
    },


    moveend_callback: function () {
        this.update();
    },

    zoomend_callback: function () {
        //this.map.clearOverlays();
       // this.updateStreetOverlay(this);
    },

    update_list_view_link: function () {
        this.options.radius = this.start_radius * Math.pow(2, this.start_zoom - this.map.getZoom());
        var o = Object.extend({}, this.options);
        o.map_radius =  o.radius;
        o.map_unit = o.unit;
        o.radius = this.original_radius;
        var center = this.map.getCenter();
        o.map_latitude = center.lat();
        o.map_longitude = center.lng();
        var link = '';
        for (i in o)
            link += '/' + i + ':' + o[i];
        $('search_link').href = this.base_url + 'properties/search/' + o.keyword + link;
        $('list_view_link').href = this.base_url + 'properties/list_view/' + o.keyword + link;
        if ($('saved_search_link'))
            $('saved_search_link').href = this.base_url + 'properties/saved_search/' + o.keyword + link;
    },

    update: function () {
        //if (this.ajax_running && this.ajax && this.ajax.transport && this.ajax.transport.abort)
        //    this.ajax.transport.abort();



        this.options.radius = this.start_radius * Math.pow(2, this.start_zoom - this.map.getZoom());
        var center = this.map.getCenter();
        this.map_loading.show();
        this.ajax_running = true;

        this.ajax = new Ajax.Request(this.base_url + 'properties/areas/' + center.lat() +'/' + center.lng() + this.generate_link(), {
                method: 'get',
                onSuccess: this.update_callback.bind(this)
            });
    },

   update_callback: function (transport) {


        this.ajax_running = false;
        eval('var areas = ' + transport.responseText + ';');

        //this.map.clearOverlays();
        this.circles.each((function(circle) {this.map.removeOverlay(circle.circle);/*this.map.removeOverlay(circle.grid);*/ delete circle;}).bind(this));
        delete this.circles;

        this.circles = new Array();

        //in case of dataset show only circle when the scale is >10
       	areas.each(function(area)
       	{
 		    if (area.record_type=='Property' || area.record_type=='Dataset' && this.map.getZoom()>10)
            {
       	    	this.circles.push(new Circle(this, area));
       	    }
       	}.bind(this));


        this.map_loading.hide();

        this.show_starting_property();
    },

    generate_link: function () {
        var link = '';
        for (i in this.options)
            link += '/' + i + ':' + this.options[i];
        return link;
    },

    open_area: function (dataset_id, record_type,clatlng, latlng, min_lat, max_lat, min_long, max_long) {

        var c = this.map.getCenter();
//      this.map.open_area(this.circle_info.dataset_id, this.circle_info.record_type, this.centre, this.circle.getLatLng(), this.circle_info.min_latitude, this.circle_info.max_latitude, this.circle_info.min_longitude, this.circle_info.max_longitude);

//	this.open_area(this.circles[i].centre, 'Property', this.circles[i].circle.getLatLng(), this.circles[i].circle_info.min_latitude, this.circles[i].circle_info.max_latitude, this.circles[i].circle_info.min_longitude, this.circles[i].circle_info.max_longitude);

//this.map.open_area('undefined', 'Property', this.centre, this.circle.getLatLng(),'51.320216', '51.346531', '-.792677', '-.750559');

//this.open_area_info_window('undefined', 'Property', c,'51.320216', '51.346531', '-.792677', '-.750559');


        if (roundFloat(c.lat(), 6) == roundFloat(clatlng.lat(), 6) && roundFloat(c.lng(), 6) == roundFloat(clatlng.lng(), 6))
        {

            this.open_area_info_window(dataset_id, record_type, latlng, min_lat, max_lat, min_long, max_long);
        }
        else
        {
            this.open_area_callback_handler = google.maps.Event.addListener(this.map, 'moveend', this.open_area_callback.bind(this));
            this.open_area_callback_options = {
                    latlng: latlng,
                    min_lat: min_lat,
                    max_lat: max_lat,
                    min_long: min_long,
                    max_long: max_long,
                    record_type: record_type,
                    dataset_id: dataset_id
                };
        }
        this.map.panTo(clatlng);
    },

    open_area_callback: function() {
        google.maps.Event.clearListeners(this.map, 'moveend');
        google.maps.Event.addListener(this.map, 'moveend', this.moveend_callback.bind(this));
        this.open_area_info_window(this.open_area_callback_options.dataset_id, this.open_area_callback_options.record_type, this.open_area_callback_options.latlng, this.open_area_callback_options.min_lat, this.open_area_callback_options.max_lat, this.open_area_callback_options.min_long, this.open_area_callback_options.max_long);
    },


    open_area_info_window: function (dataset_id, record_type, latlng, min_lat, max_lat, min_long, max_long) {

        if (record_type == 'Property')
        {
            this.map.openInfoWindowHtml(latlng, '<div id="thumbs_container"><div id="desc"></div><div id="thumbs" class="loading"></div><div id="info_container"><span id="info"></span><span id="nav"> <a id="thumb_prev" href="javascript:void(0)">&laquo; ' + trans.prev + '</a> | <a id="thumb_next" href="javascript:void(0)">' + trans.next + ' &raquo;</a></span></div></div>');

	        new Ajax.Request(this.base_url + 'properties/area/' + min_lat + '/' + max_lat + '/' + min_long + '/' + max_long + this.generate_link() + (typeof (this.show_property) != 'undefined' ? '/show_property:' + this.show_property : ''), {
	                method: 'get',
	                onSuccess: this.thumbs_callback.bind(this)
	            });
        }
        else
        {
            this.map.openInfoWindowHtml(latlng, '<div id="thumbs_container"><div id="desc"></div><div id="thumbs" class="loading"></div><div id="info_container"><span id="info"></span><span id="nav"> <a id="thumb_prev" href="javascript:void(0)">&laquo; ' + trans.prev + '</a> | <a id="thumb_next" href="javascript:void(0)">' + trans.next + ' &raquo;</a></span></div></div>');

        	new Ajax.Request(this.base_url + 'properties/dataset_area/' + dataset_id + '/' + min_lat + '/' + max_lat + '/' + min_long + '/' + max_long + this.generate_link() + (typeof (this.show_property) != 'undefined' ? '/show_property:' + this.show_property : ''), {
	                method: 'get',
	                onSuccess: this.thumbs_callback.bind(this)
	            });
        }

        if (typeof (this.show_property) != 'undefined')
        	delete this.show_property;
    },


    thumbs_callback: function (transport) {

        var thumbs = $('thumbs');

        if (!thumbs)
            return;

        eval('var properties_info = ' + transport.responseText + ';');

        thumbs.removeClassName('loading');

        this.thumbs = new Thumbs(properties_info.properties, thumbs, 'info', 'desc');

        $('thumb_prev').observe('click', this.thumbs.prev.bind(this.thumbs));
        $('thumb_next').observe('click', this.thumbs.next.bind(this.thumbs));

        if (typeof (properties_info.show_property != 'undefined'))
        	this.thumbs.start(properties_info.properties[0].record_type, properties_info.show_property);
        else
	        this.thumbs.start(properties_info.properties[0].record_type);
    },


    show_starting_property: function () {
    	if (typeof (this.options.show_property) == 'undefined')
    		return;

    	var p = this.options.show_property;
    	delete this.options.show_property;

    	for (var i = 1; i < this.circles.length; ++i)
    		if (this.circles[i].centre.equals(this.map.getCenter()))
    		{
    			this.show_property = p;

    			var c = this.map.getCenter();

    			//      this.map.open_area(this.circle_info.dataset_id, this.circle_info.record_type, this.centre, this.circle.getLatLng(), this.circle_info.min_latitude, this.circle_info.max_latitude, this.circle_info.min_longitude, this.circle_info.max_longitude);

//	this.open_area(this.circles[i].centre, 'Property', this.circles[i].circle.getLatLng(), this.circles[i].circle_info.min_latitude, this.circles[i].circle_info.max_latitude, this.circles[i].circle_info.min_longitude, this.circles[i].circle_info.max_longitude);

//this.map.open_area('undefined', 'Property', this.centre, this.circle.getLatLng(),'51.320216', '51.346531', '-.792677', '-.750559');

//this.open_area_info_window('undefined', 'Property', c,'51.320216', '51.346531', '-.792677', '-.750559');



	this.open_area('undefined', 'Property', c, c,  this.circles[i].circle_info.min_latitude, this.circles[i].circle_info.max_latitude, this.circles[i].circle_info.min_longitude, this.circles[i].circle_info.max_longitude);

 //   			this.open_area(this.circles[i].centre, 'Property', this.circles[i].circle.getLatLng(), this.circles[i].circle_info.min_latitude, this.circles[i].circle_info.max_latitude, this.circles[i].circle_info.min_longitude, this.circles[i].circle_info.max_longitude);
    			return;
    		}
    }
});