var IS_IE = true;
var IS_LT_IE7;


function jsonToDom(e) {
    if (null != e.txt) return document.createTextNode(e.txt);
    if (null == e.el) return null;
    var node = document.createElement(e.el.toUpperCase());
    if (null != e.att) {
        for (var i in e.att) {
            if (IS_IE) {
                node = applyAttribute(node, i, e.att[i]);
            } else {
                applyAttribute(node, i, e.att[i]);
            }
        }
    }
 
    if (null != e.ch) {
        for (var j in e.ch) {
            var childNode = jsonToDom(e.ch[j]);
            if (null !== childNode) node.appendChild(childNode);
        }
    }
    return node;
}
function applyAttribute(node, attribute, value) {
    if (IS_IE) {
        return ieApplyAttribute(node, attribute, value);
    } else {
        node.setAttribute(attribute, value);
    }
}

function ieApplyAttribute(node, attribute, value) {
    switch (attribute.toLowerCase()) {
        case 'for':
            node.htmlFor = value;
            break;
        case 'class':
            node.className = value;
            break;
        case 'style':
            node.style.textCss = value;
            break;
        case 'name':
            node = document.createElement(node.outerHTML.replace(">", " name=" + value + ">"));
            break;
        default:
            node.setAttribute(attribute, value);
    }
    return node;
}


 
function Tooltip(marker, content, padding) {
    this.marker = marker;
    this.content =content;
    this.padding = padding;
    this.div = null;
    this.map = null;
}

Tooltip.prototype = new GOverlay();

Tooltip.prototype.initialize = function(map) {

    this.div = document.createElement("div");
    var innerContainer = this.div.cloneNode(false);
    this.div.appendChild(innerContainer);
    this.div.style.position = 'absolute';
    this.div.style.visibility = 'hidden';
    this.div.style.border_width = "5px";
    this.div.style.border_style = "Ridge";
    this.div.style.border_color = "Black";
    this.div.style.border_top_style = "solid";
    this.div.style.border_top_color = "Red";
    this.div.style.border_top_width = "5px";


    innerContainer.className = 'tooltip';
    var child = typeof this.content == 'string' ?
		document.createTextNode(this.content) :
		this.content;
    
    innerContainer.appendChild(child);
    map.getPane(G_MAP_FLOAT_PANE).appendChild(this.div);
    this.map = map;
}

Tooltip.prototype.remove = function(){
	this.div_.parentNode.removeChild(this.div_);
}

Tooltip.prototype.copy = function(){
	return new Tooltip(this.marker_,this.text_,this.padding_);
}
Tooltip.prototype.redraw = function(force) {
    if (!force) return;

    //draw tooltip
    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';
    this.div.style.backgroundColor = "#85C1E6";
    this.div.style.color = "Black";
    this.div.style.backgroundColor = "#85C1E6";
    this.div.style.border_width = "5px";
    this.div.style.border_style = "Ridge";
    this.div.style.border_color = "Black";
    this.div.style.border_top_style = "solid";
    this.div.style.border_top_color = "Red";
    this.div.style.border_top_width = "5px";
    this.div.style.width = "100px";
    //    this.div.style.border= "5px";
    this.div.style.border = "2px solid " + "Blue";
}

Tooltip.prototype.show = function() {
    this.div.style.visibility = 'visible';
}

Tooltip.prototype.hide = function() {
    this.div.style.visibility = 'hidden';
}
