/**

 * @author Marco Alionso Ramirez, marco@onemarco.com

 * @url http://onemarco.com

 * @version 1.0

 * This code is public domain

 */



/**

 * The Tooltip class is an addon designed for the Google Maps GMarker class.

 * @constructor

 * @param {GMarker} marker

 * @param {String} text

 * @param {Number} padding

 */



function Tooltip(marker, text, padding, id, type){

	this.marker_ = marker;

	this.text_ = text;

	this.padding_ = padding;

	this.id_ = id;

	this.type_ = type;

}



Tooltip.prototype = new GOverlay();




Tooltip.prototype.initialize = function(map){
         var div = document.createElement("table");



	div.style.width = '150px';

first=this.text_.substring(0,20);
second=this.text_.substring(20);
if (second!='') {
first=first.split("").reverse().join("").replace(' ','>rb<').split("").reverse().join("");
this.text_=first+second;
}
first=this.text_.substring(0,40);
second=this.text_.substring(40);
if (second!='') {
first=first.split("").reverse().join("").replace(' ','>rb<').split("").reverse().join("");
this.text_=first+second;
}

    div.innerHTML='<tr><td align=center><img width="150" height="150" src="images/'+this.id_+'av.jpg"><tr><td align=center>'+this.text_+'</center>';
	div.className = 'tooltip';

	div.style.position = 'absolute';

	div.style.visibility = 'hidden';



	div.style.visibility = 'hidden';


	div.className = 'tooltip';

	div.style.position = 'absolute';

	div.style.visibility = 'hidden';


	if (this.type_=='small') {
	div.style.width = '6px';


}

	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);

	this.map_ = map;

	this.div_ = div;



}



Tooltip.prototype.remove = function(){

	this.div_.parentNode.removeChild(this.div_);

}



Tooltip.prototype.copy = function(){

	return new Tooltip(this.marker_,this.text_,this.padding_,this.id_);

}



Tooltip.prototype.redraw = function(force){

	if (!force) return;

	var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());

	var iconAnchor = this.marker_.getIcon().iconAnchor;

	var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2);

	var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_;

	this.div_.style.top = yPos + 'px';

	this.div_.style.left = xPos + 'px';

}



Tooltip.prototype.show = function(){

	this.div_.style.visibility = 'visible';

}



Tooltip.prototype.hide = function(){

	this.div_.style.visibility = 'hidden';

}
