function popup(url) {
			 $.ajax({
				   type: "POST",
				   url: "/includes/p/"+url+".php",
				   data: "add",
				   success: function(data){
				   $('#popupcenter').html(data);
					}
					});
}

$(function() {
$('a[rel^=lightbox]').lightBox({ fixedNavigation:true });


 val_src=$('.fdes .ind').attr('src');
 $('.fdes').before('<p class="bimg"><img src="'+val_src+'" /></p>');
 $('.bimg img').attr('height','270');

    $('.fdes .img_news').click(function(){
            val_src=$(this).attr('src');
             $('.bimg').remove();
            	$('.fdes').before('<p class="bimg"><img src="'+val_src+'" /></p>');
                $('.bimg img').attr('height','270');


		});

});


function MapWrapper(ad)
{
    var _this = this;
    this.map = null;
    this.setMarker = null;
    this.geocoder = null;
    this.markerClusterer = null;
    this.init = function () {
        //инициализируем Geocoder
        if (_this.geocoder == null) {
            _this.geocoder = new google.maps.Geocoder();
        }
        //инициализируем карту
        if (_this.map == null) {
            var latlng = new google.maps.LatLng(_this.centerX, _this.centerY);
            var myOptions = {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            _this.map = new google.maps.Map(document.getElementById("map_canvas"),
            myOptions);
        }
    run(ad);
    }



    //Установить карту на город
     function run(address) {
        var address = address;

        _this.geocoder.geocode({ 'address': address }, function (results, status) {

            if (status == google.maps.GeocoderStatus.OK) {
                _this.map.setCenter(results[0].geometry.location);
                //установить Zoom таким образом, чтобы город был показан весь
                _this.map.setZoom(14);
                //и поставить маркет для отметки адреса
                _this.addMarker();
                $(".info-put-marker").show();
            } else {
                alert("Пошло что-то не так, потому что: " + status);
            }
        });
    }

    //вычисление значения Zoom по границам
    this.getZoom = function (bounds) {

        var width = $(".map").width();
        var height = $(".map").height();

        var dlat = Math.abs(bounds.getNorthEast().lat() - bounds.getSouthWest().lat());
        var dlon = Math.abs(bounds.getNorthEast().lng() - bounds.getSouthWest().lng());

        var max = 0;
        if (dlat > dlon) {
            max = dlat;
        } else {
            max = dlon;
        }

        // Center latitude in radians
        var clat = Math.PI * Math.abs(bounds.getSouthWest().lat() + bounds.getNorthEast().lat()) / 360.;

        var C = 0.0000107288;
        var z0 = Math.ceil(Math.log(dlat / (C * height)) / Math.LN2);
        var z1 = Math.ceil(Math.log(dlon / (C * width * Math.cos(clat))) / Math.LN2);

        return 18 - ((z1 > z0) ? z1 : z0);
    }

    //добавить маркер
    this.addMarker = function () {
        if (_this.setMarker != null) {
            _this.setMarker.setMap(_this.map);
            _this.setMarker.setPosition(_this.map.getCenter());
        } else {
            _this.setMarker = new google.maps.Marker({
                map: _this.map,
                draggable: true,
                animation: google.maps.Animation.DROP,
                position: _this.map.getCenter()
            });
            google.maps.event.addListener(_this.setMarker, 'click', _this.toggleBounceMarker);
            //при окончании перемещения маркера установить функцию
            google.maps.event.addListener(_this.setMarker, 'dragend', _this.markerPositionChanged);
        }
    }


    //при клике на маркет он будет подыматься и показывать куда упадет когда его отпустим
    this.toggleBounceMarker = function() {
        if (_this.setMarker.getAnimation() != null) {
            _this.setMarker.setAnimation(null);
        } else {
            _this.setMarker.setAnimation(google.maps.Animation.BOUNCE);
        }
    }


}

