function htmlspecialchars_decode (string, quote_style) {
    var optTemp = 0,
        i = 0,
        noquotes = false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE': 1,
        'ENT_HTML_QUOTE_DOUBLE': 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE': 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i = 0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            } else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
        // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }
    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');
    return string;
}

function InfoBox(opts) {
	google.maps.OverlayView.call(this);
	this.latlng_ = opts.latlng;
	this.map_ = opts.map;
	this.offsetVertical_ = -160;
	this.offsetHorizontal_ = -25;
	this.height_ = 133;
	this.width_ = 153;
	this.name_ = opts.name;
	this.theimg = opts.img;
	this.theprice = opts.price;
	this.thedestins = opts.destins;
	this.destinid = opts.destinid;
	this.stars = opts.stars;
	var me = this;
	this.boundsChangedListener_ =
	google.maps.event.addListener(this.map_, "bounds_changed", function() {
		return me.panMap.apply(me);
	});
	this.setMap(this.map_);
}

InfoBox.prototype = new google.maps.OverlayView();

InfoBox.prototype.remove = function() {
  if (this.div_) {
    this.div_.parentNode.removeChild(this.div_);
    this.div_ = null;
  }
};


InfoBox.prototype.draw = function() {
  this.createElement();
  if (!this.div_) return;
  var pixPosition = this.getProjection().fromLatLngToDivPixel(this.latlng_);
  if (!pixPosition) return;
  this.div_.style.width = this.width_ + "px";
  this.div_.style.left = (pixPosition.x + this.offsetHorizontal_) + "px";
  this.div_.style.height = this.height_ + "px";
  this.div_.style.top = (pixPosition.y + this.offsetVertical_) + "px";
  this.div_.style.display = 'block';
};

InfoBox.prototype.createElement = function() {
  var panes = this.getPanes();
  var div = this.div_;
  if (!div) {
    div = this.div_ = document.createElement("div");
    div.style.border = "0px none";
    div.style.position = "absolute";
    div.style.background = "url('" + my_url + "im/infowindow.png')";
    div.style.width = this.width_ + "px";
	div.id = "infowin";
    div.style.height = this.height_ + "px";
    var contentDiv = document.createElement("div");
    contentDiv.style.padding = "0 17px";
	contentDiv.innerHTML = "<img src='" + this.theimg + "' border='0' alt='' style='margin-bottom:5px;' />";
	if(this.stars!=''){
		contentDiv.innerHTML += this.stars;
	}
	contentDiv.innerHTML += "<span style='display:block;color:#c12100;text-transform:uppercase;font-size:10px;font-weight:bold;line-height:15px;'>" + this.name_ + "</span>";
	if(this.stars==''){
		contentDiv.innerHTML += "<a href='" + my_url + "offers/destin_" + this.destinid + "/'>виж оферти</a>";
	}else{
		
		contentDiv.innerHTML += "<span style='color:#616161;font-weight:bold;font-size:9px;display:block;line-height:10px;'>" + this.thedestins + "</span>";
	}
    var topDiv = document.createElement("div");
    topDiv.style.textAlign = "right";
    var closeImg = document.createElement("img");
    closeImg.style.width = "20px";
    closeImg.style.height = "19px";
    closeImg.style.cursor = "pointer";
    closeImg.src =  my_url + "im/closebigger.gif";
    topDiv.appendChild(closeImg);

    function removeInfoBox(ib) {
      return function() {
        ib.setMap(null);
      };
    }

    google.maps.event.addDomListener(closeImg, 'click', removeInfoBox(this));

    div.appendChild(topDiv);
    div.appendChild(contentDiv);
    div.style.display = 'none';
    panes.floatPane.appendChild(div);
    this.panMap();
  } else if (div.parentNode != panes.floatPane) {
    // The panes have changed.  Move the div.
    div.parentNode.removeChild(div);
    panes.floatPane.appendChild(div);
  } else {
    // The panes have not changed, so no need to create or move the div.
  }
}

/* Pan the map to fit the InfoBox.
 */
InfoBox.prototype.panMap = function() {
  // if we go beyond map, pan map
  var map = this.map_;
  var bounds = map.getBounds();
  if (!bounds) return;
  

  // The position of the infowindow
  var position = this.latlng_;
  // The dimension of the infowindow
  var iwWidth = this.width_;
  var iwHeight = this.height_;

  // The offset position of the infowindow
  var iwOffsetX = this.offsetHorizontal_;
  var iwOffsetY = this.offsetVertical_;

  // Padding on the infowindow
  var padX = 40;
  var padY = 40;

  // The degrees per pixel
  var mapDiv = map.getDiv();
  var mapWidth = mapDiv.offsetWidth;
  var mapHeight = mapDiv.offsetHeight;
  var boundsSpan = bounds.toSpan();
  var longSpan = boundsSpan.lng();
  var latSpan = boundsSpan.lat();
  var degPixelX = longSpan / mapWidth;
  var degPixelY = latSpan / mapHeight;

  // The bounds of the map
  var mapWestLng = bounds.getSouthWest().lng();
  var mapEastLng = bounds.getNorthEast().lng();
  var mapNorthLat = bounds.getNorthEast().lat();
  var mapSouthLat = bounds.getSouthWest().lat();

  // The bounds of the infowindow
  var iwWestLng = position.lng() + (iwOffsetX - padX) * degPixelX;
  var iwEastLng = position.lng() + (iwOffsetX + iwWidth + padX) * degPixelX;
  var iwNorthLat = position.lat() - (iwOffsetY - padY) * degPixelY;
  var iwSouthLat = position.lat() - (iwOffsetY + iwHeight + padY) * degPixelY;

  // calculate center shift
  var shiftLng =
      (iwWestLng < mapWestLng ? mapWestLng - iwWestLng : 0) +
      (iwEastLng > mapEastLng ? mapEastLng - iwEastLng : 0);
  var shiftLat =
      (iwNorthLat > mapNorthLat ? mapNorthLat - iwNorthLat : 0) +
      (iwSouthLat < mapSouthLat ? mapSouthLat - iwSouthLat : 0);

  // The center of the map
  var center = map.getCenter();

  var centerX = center.lng() - shiftLng;
  var centerY = center.lat() - shiftLat;

  google.maps.event.removeListener(this.boundsChangedListener_);
  this.boundsChangedListener_ = null;
};

	var map;
	function initialize() {
	var myLatlng = new google.maps.LatLng(42.70822603534113, 25.26093198987633);
	var myOptions = {
		scrollwheel: false,
		zoom: 1,
		center: myLatlng,
		sensor: 'true',
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}

	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

		var image = $('#icon_google').val();
		if(gmap_markers.length>0) {
			var markers = gmap_markers;
			for (var i = 1; i < markers.length; i++) {
				var latlng = markers[i][0];
				var lat_arr = latlng.split(", ");
				var location = new google.maps.LatLng(lat_arr[0], lat_arr[1]);
				 var marker = new google.maps.Marker({
					position: location, 
					map: map,
					icon: image
				});
				var j = i + 1;
				var name = htmlspecialchars_decode(markers[i][1]);
				var id = markers[i][2];
				var img = markers[i][3];
				var price = markers[i][4];
				var destins = markers[i][5];
				var stars = markers[i][6];
				marker.setTitle();
				attachSecretMessage(marker, name, id, latlng, map, img, price, destins, stars);
			}
		}
	}
	
	function attachSecretMessage(marker, name, id, latlng, map, img, price, destins, stars) {
		google.maps.event.addListener(marker, 'click', function() {
			var infoBox = new InfoBox({latlng: marker.getPosition(), map: map, name:name, img:img, price:price, destins:destins, destinid:id, stars:stars});
		});
	}
