//******************************************************************************
var markerFile='';
var mapMode=0;
var theHint=false;
var map=false;
// A MMMhint is a simple overlay that outlines a lat/lng bounds on the
// map. It has a border of the given weight and color and can optionally
// have a semi-transparent background color.
function MMMhint(coords, opt_weight, opt_color) {
  var rectBounds = new GLatLngBounds(
    new GLatLng(coords.lat(), coords.lng() ),
    new GLatLng(coords.lat() , coords.lng()));
  this.intCOORDS = coords;
  this.bounds_ = rectBounds;
  this.weight_ = opt_weight || 2;
  this.color_ = opt_color || "#888888";
}
MMMhint.prototype = new GOverlay();

// Creates the DIV representing this rectangle.
MMMhint.prototype.initialize = function(map) {
  // Create the DIV representing our rectangle
  var div = document.createElement("div");
  div.style.border = this.weight_ + "px solid " + this.color_;
  div.style.className = 'blurry';
  div.style.display = 'none';
  div.style.position = "absolute";
  div.id='MMMhint';
  // Our rectangle is flat against the map, so we add our selves to the
  // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
  // below the marker shadows)
  map.getPane(G_MAP_MAP_PANE).appendChild(div);

  this.map_ = map;
  this.div_ = div;
}

// Remove the main DIV from the map pane
MMMhint.prototype.remove = function() {
  this.div_.parentNode.removeChild(this.div_);
}

// Copy our data to a new MMMhint
MMMhint.prototype.copy = function() {
  return new MMMhint(this.bounds_, this.weight_, this.color_,
                       this.backgroundColor_, this.opacity_);
}

// Redraw the rectangle based on the current projection and zoom level
MMMhint.prototype.redraw = function(force) {
  // We only need to redraw if the coordinate system has changed
  if (!force) return;

  // Calculate the DIV coordinates of two opposite corners of our bounds to
  // get the size and position of our rectangle
  var c1 = this.map_.fromLatLngToDivPixel(this.intCOORDS);
  var c2 = this.map_.fromLatLngToDivPixel(this.intCOORDS);

  // Now position our DIV based on the DIV coordinates of our bounds
  this.div_.style.width = "100px";
//  this.div_.style.height =  "150px";
  this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_+10) + "px";
  this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_ - 10) + "px";
}

function getPNG(imgsrc){
var imght='';
if(document.all){
   var imgStyle = "cursor:hand;display:inline-block;" ;
   var imgwidth = 12;
   var imgheight = 20;
    imght ="<span " +
          " style=\"" + "width:" + imgwidth + "px; height:" + imgheight + "px;" + imgStyle + ";" +
           "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"   +
           "(src=\'" +imgsrc + "\', sizingMethod='scale');\"></span>" ;

  }
  else {
    imght =   '<img src="'+imgsrc+'" '+
                ' border="0" style="cursor: pointer;cursor: hand" '+
                '/>';
  }
  return imght;
}
// A MMMarker is a simple overlay that outlines a lat/lng bounds on the
// map. It has a border of the given weight and color and can optionally
// have a semi-transparent background color.
var allMMMmarkers=[];
function MMMarker(coords,dbID,imgsrc,markerWidth,markerHeight) {
  var rectBounds = new GLatLngBounds(
    new GLatLng(coords.lat(), coords.lng() ),
    new GLatLng(coords.lat() , coords.lng()));
  this.intCOORDS = coords;
  this.bounds_ = rectBounds;
  this.weight_ = 0;
  this.color_ = '#0F0';
  this.intID=dbID;
  this.intIMGSRC=imgsrc;
  this.intMARKERHEIGHT= markerHeight;
  this.intMARKERWIDTH = markerWidth;
  allMMMmarkers[dbID]=this;
}

MMMarker.prototype = new GOverlay();

// Creates the DIV representing this rectangle.
MMMarker.prototype.initialize = function(map) {
  // Create the DIV representing our rectangle
  var div = document.createElement("div");
  div.id='divMMMarker'+this.intID;
  div.style.border = "0px solid " + this.color_;
  div.background = 'none';
  div.onMouseOver='alert(5)';
  div.style.position = "absolute";
  var imght='';
  if(this.intIMGSRC==''){
  var ih=this.intMARKERHEIGHT / 2;
  var ih1=ih+1;
  var clFill='yellow';
  var clStick='#551111';
  var clStick2='gray';
  var imght = ''+
              '<div style="position:absolute;top:'+ih1+'px;left:1px;'+
              'width:0px;'+
              'height:'+ih+'px;'+
              'border:1px solid '+clStick2+';'+
              'background:'+clFill+';"></div>'+
              '<div style="position:absolute;top:1px;left:1px;'+
              'width:'+this.intMARKERWIDTH+'px;'+
              'height:'+ih+'px;'+
              'border:1px solid '+clStick2+';'+
              'background:'+clFill+';"></div>'+
              '<div style="position:absolute;top:'+ih+'px;left:0px;'+
              'width:0px;'+
              'height:'+ih+'px;'+
              'border:1px solid '+clStick+';'+
              'background:'+clFill+';"></div>'+
              '<div style="position:absolute;top:0px;left:0px;'+
              'width:'+this.intMARKERWIDTH+'px;'+
              'height:'+ih+'px;'+
              'border:1px solid '+clStick+';'+
              'background:'+clFill+';"></div>';
  }
  else {
    imght=getPNG( this.intIMGSRC );
  }
  div.innerHTML='<a href="javascript:MMMmouseclick('+this.intID+')" onMouseOver="MMMmouseover('+this.intID+')"'+
                ' onMouseOut="MMMmouseout('+this.intID+')" '+
                ' onMouseOver="MMMmouseover('+this.intID+')" '+
                ' style="border:0px solid #000;font-size:1px">'+
                imght+
                '</a>';
  // Our rectangle is flat against the map, so we add our selves to the
  // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
  // below the marker shadows)

  map.getPane(G_MAP_MAP_PANE).appendChild(div);

  this.map_ = map;
  this.div_ = div;
}

// Remove the main DIV from the map pane
MMMarker.prototype.remove = function() {
  this.div_.parentNode.removeChild(this.div_);
}

// Copy our data to a new MMMarker
MMMarker.prototype.copy = function() {
  return new MMMarker(this.intCOORDS, this.weight_, this.color_,
                       this.backgroundColor_, this.opacity_);
}

// Redraw the rectangle based on the current projection and zoom level
MMMarker.prototype.redraw = function(force) {
  // We only need to redraw if the coordinate system has changed
  if (!force) return;

  // Calculate the DIV coordinates of two opposite corners of our bounds to
  // get the size and position of our rectangle
  var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
  var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());

  // Now position our DIV based on the DIV coordinates of our bounds
  this.div_.style.width = this.intMARKERWIDTH  + "px";
  this.div_.style.height = this.intMARKERHEIGHT + "px";
  var ddx=this.intMARKERWIDTH/2;
  if(this.intIMGSRC==''){ddx=0;}
  this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_ -ddx ) + "px";
  this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_ -this.intMARKERHEIGHT ) + "px";
}


var plotNum=0;
var insideIE=false;
if(document.all){insideIE=true;}
function startPlotting(){
 var d=parseInt((intNum+10)/10)+1;
 for(i=0;i<d;i++){
   if(allMMMmarkers[plotNum+i]){
      usermap.addOverlay(allMMMmarkers[plotNum+i]);
   }
 }
 plotNum = plotNum + d;
 if(plotNum<=intNum){
        setTimeout("startPlotting();",55);
 }
}

var intNum=0;
var HT=[];
function addMarker(Point,ht,unk){
//°°
 var lat=Point.y;
 var lon=Point.x;
// var mk = new MMMarker(new GLatLng(lat,lon),intNum,'',7,10);
 HT[intNum]=ht;
 var mk = new MMMarker(new GLatLng(lat,lon),intNum,markerFile,12,20);
// alert(intNum);
 if(!insideIE){usermap.addOverlay(mk);}
 intNum++;
 return true;
}

//******************************************************************************

function MMMmouseover(callerID){
    if (callerID==-1){
      //document.getElementById('gmapCoords').style.display = 'block';
	  return false;
	}
    var K=allMMMmarkers[callerID].intCOORDS;
    if(theHint!=false){
        map.removeOverlay(theHint);
    }
    theHint = new MMMhint(K);
    map.addOverlay(theHint);
    document.getElementById('MMMhint').style.display = 'block';
    document.getElementById('MMMhint').style.width='auto';
    document.getElementById('MMMhint').style.cssText+="color:#FFF;background-color:#FFFFFF;";
    document.getElementById('MMMhint').innerHTML=HT[callerID];
}

function MMMmouseout(callerID){
  if(theHint){
	document.getElementById('MMMhint').style.display = 'none';
	map.removeOverlay(theHint);
  }
  theHint=false;
}

function MMMmouseclick(callerID){
    if(callerID==-1){
      map.openInfoWindowHtml (allMMMmarkers[callerID].intCOORDS,'Your position');
	}
	else {
		map.openInfoWindowHtml (allMMMmarkers[callerID].intCOORDS,HT[callerID]);
	}
}
function centerOnMe(){
  map.setCenter(thispoint.intCOORDS);
}

