// ************** Geometry *************** //

var Geometry = {};
if (window.screenLeft === undefined) { // Для IE и других
    Geometry.getWindowX = function() { return window.screenLeft; };
    Geometry.getWindowY = function() { return window.screenTop; };
}
else if (window.screenX) { // Для Firefox и других
    Geometry.getWindowX = function() { return window.screenX; };
    Geometry.getWindowY = function() { return window.screenY; };
}
if (window.innerWidth) { // Все броузеры, кроме IE
    Geometry.getViewportWidth = function() { return window.innerWidth; };
    Geometry.getViewportHeight = function() { return window.innerHeight; };
    Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
    Geometry.getVerticalScroll = function() { return window.pageYOffset; };
}
else if (document.documentElement && document.documentElement.clientWidth) {

    Geometry.getViewportWidth =
        function() { return document.documentElement.clientWidth; };
    Geometry.getViewportHeight =
        function() { return document.documentElement.clientHeight; };
    Geometry.getHorizontalScroll =
        function() { return document.documentElement.scrollLeft; };
    Geometry.getVerticalScroll =
        function() { return document.documentElement.scrollTop; };
}
else if (document.body.clientWidth) {

    Geometry.getViewportWidth =
        function() { return document.body.clientWidth; };
    Geometry.getViewportHeight =
        function() { return document.body.clientHeight; };
    Geometry.getHorizontalScroll =
        function() { return document.body.scrollLeft; };
    Geometry.getVerticalScroll =
        function() { return document.body.scrollTop; };
}

if (document.documentElement && document.documentElement.scrollWidth) {
    Geometry.getDocumentWidth =
        function() { return document.documentElement.scrollWidth; };
    Geometry.getDocumentHeight =
        function() { return document.documentElement.scrollHeight; };
}
else if (document.body.scrollWidth) {
    Geometry.getDocumentWidth =
        function() { return document.body.scrollWidth; };
    Geometry.getDocumentHeight =
        function() { return document.body.scrollHeight; };
}


// ************** Tooltip *************** //
function Tooltip( ) {
    this.tooltip = document.createElement("div"); 
    this.tooltip.style.visibility = "hidden"; 
    this.tooltip.className = "tooltip";
}

Tooltip.prototype.show = function(text, x, y) {
    this.tooltip.innerHTML = text;             
    this.tooltip.style.left = x + "px";       
    this.tooltip.style.top = y + "px";
    this.tooltip.style.visibility = "visible";
	if (this.tooltip.parentNode != document.body)
		var content = document.getElementById("content");
        content.appendChild(this.tooltip);
};

Tooltip.prototype.hide = function() {
    this.tooltip.style.visibility = "hidden"; 
};

Tooltip.X_OFFSET = 15; 
Tooltip.Y_OFFSET = -25; 
Tooltip.DELAY = 50;
Tooltip.Coords = [
				  {x: 370, y: 10},
				  {x: 370, y: 95},
				  {x: 80, y: 240},
				  {x: 300, y: 400},
				  {x: 430, y: 400},
				  {x: 550, y: 640},
				  {x: 660, y: 140},
				  {x: 660, y: 270},
				  {x: 910, y: 370},
				  {x: 910, y: 700},
];

Tooltip.prototype.schedule = function(target, e) {
    var text = target.getAttribute("tip");
    if (!text) return;
	var id = target.getAttribute("id").substring(4);
	var x = Tooltip.Coords[id-1].x;
	var y = Tooltip.Coords[id-1].y;

    var self = this; 
    var timer = window.setTimeout(function() { self.show(text, x, y); },
                                  Tooltip.DELAY);
    if (target.addEventListener) target.addEventListener("mouseout", mouseout,
                                                         false);
    else if (target.attachEvent) target.attachEvent("onmouseout", mouseout);
    else target.onmouseout = mouseout;
   
    function mouseout() {
        self.hide(); 
        window.clearTimeout(timer); 
        if (target.removeEventListener)
            target.removeEventListener("mouseout", mouseout, false);
        else if (target.detachEvent) 
            target.detachEvent("onmouseout",mouseout);
        else target.onmouseout = null;
    }
}
Tooltip.tooltip = new Tooltip();

Tooltip.schedule = function(target, e) {Tooltip.tooltip.schedule(target, e);

}
