// TLabel() GMaps API extension copyright 2005-2006 Tom Mangan
// http://gmaps.tommangan.us/tlabel.html
// free for non-commercial use
// v.3 new icons version - with background borders
// v.5   Blue Point test alerts taken away


function TLabel(){}
TLabel.prototype.initialize=function(a, oWin){
 
 if(!oWin)oWin = window;
 
 this.oWin = oWin;
 this.parentMap=a;
 this.green = 0;
 var b = oWin.document.createElement('div');
 b.setAttribute('id',this.id);
 
/* INSERTION */
  if(this.content == null)
  this.content = "";
  this.layer = b;
  this.anchorPoint = "center";
/* END INSERTION */

 b.innerHTML=this.content;
 oWin.document.body.appendChild(b);
 
 b.style.position='absolute';
 b.style.zIndex=1;
 if(this.percentOpacity){this.setOpacity(this.percentOpacity);}

/* MODIFICATION */

 // styles for garage icons on the map
 this.w = 25;
 this.h = 25;
 this.layer.style.width = this.w + 'px';
 this.layer.style.height = this.h + 'px';
 //this.layer.style.padding = "6.3px 0 0 0";
 this.layer.style.padding = "0 0 0 0";
 this.layer.style.lineHeight = "100%";
 this.layer.style.fontSize = "7.9pt";
 this.layer.style.fontWeight = "bolder";
 this.layer.style.color = "black";
 this.layer.style.textAlign = "center";
 this.layer.style.cursor = "pointer";
 this.markerImage = null;
 this.markerColour = null;
/* END MODIFICATION */

 this.mapTray=a.getPane(G_MAP_MAP_PANE);

 this.mapTray.appendChild(b);
 if(!this.markerOffset){this.markerOffset=new GSize(0,0);}
 this.setPosition();


// INSERTION 
//if(this.layer.id != "label_address")
/*
GEvent.bind(a,"moveend",this,function(){
  this.setPosition()});
// END INSERTION 

 GEvent.bind(a,"zoomend",this,function(){
 this.setPosition()});
*/
}


TLabel.prototype.setPosition=function(a){
 
 
 if(a){this.anchorLatLng=a;}
 var b=this.parentMap.fromLatLngToDivPixel(this.anchorLatLng);
 var x=parseInt(b.x);
 var y=parseInt(b.y);
 with(Math){switch(this.anchorPoint){
  case 'topLeft':break;
  case 'topCenter':x-=floor(this.w/2);break;
  case 'topRight':x-=this.w;break;
  case 'midRight':x-=this.w;y-=floor(this.h/2);break;
  case 'bottomRight':x-=this.w;y-=this.h;break;
  case 'bottomCenter':x-=floor(this.w/2);y-=this.h;break;
  case 'bottomLeft':y-=this.h;break;
  case 'midLeft':y-=floor(this.h/2);break;
  case 'center':x-=floor(this.w/2);y-=floor(this.h/2);break;
  default:break;
 }}
 
 var d=this.oWin.document.getElementById(this.id);
 d.style.left=x-this.markerOffset.width+'px';
 d.style.top=y-this.markerOffset.height+'px';
}
TLabel.prototype.setOpacity=function(b){
 if(b<0){b=0;} if(b>100){b=100;}
 var c=b/100;
 var d=this.oWin.document.getElementById(this.id);
 if(typeof(d.style.filter)=='string'){d.style.filter='alpha(opacity:'+b+')';}
 if(typeof(d.style.KHTMLOpacity)=='string'){d.style.KHTMLOpacity=c;}
 if(typeof(d.style.MozOpacity)=='string'){d.style.MozOpacity=c;}
 if(typeof(d.style.opacity)=='string'){d.style.opacity=c;}
}

/* INSERTION */
TLabel.prototype.setImage=function(url, colour){
 
 /// set image to garage icon on the map
 // RG and R icons especially complex
 
 //  icondiv is DIV that added to RG & R icons. It has background image (currently 'border_bl_n. gif')
 // which becomes borders around RG & R icons. 
 
 if(this.icondiv != null)
  var curr_div = this.icondiv; // border DIV added
  else  
  var curr_div = this.layer; // plain
  
  this.markerImage = url;
  this.markerColour = colour;
  
  if(this.tempImage == null)
  {
    curr_div.style.backgroundImage = "url(" + url + ")";
    curr_div.style.backgroundRepeat = "no-repeat";
    
    if(this.green > 0 && ICON_HIGH) // 
    curr_div.style.backgroundPosition = "3px 3px"; // to hold border DIV
    else  
    curr_div.style.backgroundPosition = "0 0";
    
    curr_div.style.color = colour;
  }
  
}

TLabel.prototype.clearImage=function(){
  this.markerImage = null;
  
  if(this.icondiv != null)
  var curr_div = this.icondiv; // border DIV added
  else  
  var curr_div = this.layer;
  
  curr_div.style.backgroundImage = "none";
  curr_div.style.color = "black";
}

TLabel.prototype.setTempImage=function(url, colour){
  this.tempImage = url;
  
  if(this.icondiv != null)
  var curr_div = this.icondiv; // border DIV added
  else  
  var curr_div = this.layer;
  
  
  curr_div.style.backgroundImage = "url(" + url + ")";
  curr_div.style.color = colour;
  curr_div.style.backgroundRepeat = "no-repeat";
  

   if(this.green > 0 && ICON_HIGH)
    curr_div.style.backgroundPosition = "3px 3px"; // to hold border DIV
   else  
    curr_div.style.backgroundPosition = "0 0";
   
  
}
TLabel.prototype.clearTempImage=function(){
  this.tempImage = null;
  
  if(this.markerImage != null)
    this.setImage(this.markerImage, this.markerColour);
  else
    this.clearImage();
}
TLabel.prototype.setHTML=function(c)
{
  if(this.content != c)
  {
  if(this.icondiv != null)
  var curr_div = this.icondiv;
  else  
  var curr_div = this.layer;
 
    this.content = c;
    curr_div.innerHTML = this.content;
  }
}
TLabel.prototype.clearHTML=function(){
  if(this.content != "")
  {
  if(this.icondiv != null)
  var curr_div = this.icondiv; // border DIV
  else  
  var curr_div = this.layer;
  
  
    this.content = "";
    curr_div.innerHTML = this.content;
  }
}
/* END INSERTION */

GMap2.prototype.addTLabel=function(a, oWin){
 a.initialize(this, oWin);
}
GMap2.prototype.removeTLabel=function(a){
/* MODIFICATION */
 // var b=document.getElementById(a.id);
 // this.getPane(G_MAP_MAP_PANE).removeChild(b);
 // delete(b);
 this.getPane(G_MAP_MAP_PANE).removeChild(a.layer);
 delete(a.layer);
// a = null;
/* END MODIFICATION */
}

