
var Globals = {
    map                 : null,
    search              : null,
    tooltipRegion       : null,
    tooltipMap          : null,
    tooltipSearch       : null
}

var Preferences = {
    map : {
        containerId         : "map",
        iconImage           : "http://www.hotel-in-czech.com/images/general/marker.png",
        iconWidth           : 10,
        iconHeight          : 10,
        iconAnchorX         : 5,
        iconAnchorY         : 5,
        infoWindowAnchorX   : 3,
        infoWindowAnchorY   : 0,
        zoomDefault         : 13,
        zoomLocate          : 15
    },
    
    search : {
        textboxId           : "search",
        divId               : "result",
        textboxTextDefault  : "",
        url                 : "http://www.hotel-in-czech.com/search.php?s=",
        htmlHeader          : "<div class=\"fA11n\" style=\"margin:10px 0px 10px 0px\">",
        htmlFooter          : "</div>",
        htmlLoading         : "<img src=\"http://www.hotel-in-czech.com/images/general/loading.gif\" style=\"margin-bottom:20px;\" />",
        htmlNotFound        : ""
    }
}

function onLoad(m)
{
    if (m && GBrowserIsCompatible())
    {
        Globals.map = new Map(Preferences.map);

        addMapMarkers();
        Globals.map.showMap();
    }

    Globals.search = new Search(Preferences.search);
    Globals.search.onLoad();
    Globals.search.textbox.focus();

    Globals.tooltipRegion = new Tooltip("tooltipRegion", "http://www.hotel-in-czech.com/images/tooltip/tooltip.png");
    Globals.tooltipRegion.divClient.className = "fA11n cTx";
    Globals.tooltipRegion.divFrame.style.MozOpacity = 0.95;
    Globals.tooltipRegion.edgeType = Tooltip.EdgeType.right;
    Globals.tooltipRegion.edgePosition = 10;    

    Globals.tooltipMap = new Tooltip("tooltipMap", "http://www.hotel-in-czech.com/images/tooltip/tooltip.png");
    Globals.tooltipMap.divClient.className = "fA11n cTx";
    Globals.tooltipMap.divFrame.style.MozOpacity = 0.9;
    Globals.tooltipMap.edgeType = Tooltip.EdgeType.bottomRight;
    Globals.tooltipMap.edgePosition = 170;    
        
    Globals.tooltipSearch = new Tooltip("tooltipSearch", "http://www.hotel-in-czech.com/images/tooltip/tooltip.png");
    Globals.tooltipSearch.divClient.className = "fA11n cTx";
    Globals.tooltipSearch.edgeType = Tooltip.EdgeType.topLeft;
    Globals.tooltipSearch.edgePosition = 20;    
}

function onUnload(m)
{
    if (m && GBrowserIsCompatible())
        GUnload();
}

function showRegionTooltip(x, y, s)
{
	if (Globals.tooltipRegion && Globals.tooltipHTML)
	    Globals.tooltipRegion.openAbsolute(230 - document.body.scrollLeft, y - 40, 190, -1, Globals.tooltipHTML[s]);
}

function hideRegionTooltip()
{
	if (Globals.tooltipRegion)
        Globals.tooltipRegion.hide();
}

function showMapTooltip(x, y, s)
{
	if (Globals.tooltipMap && Globals.tooltipHTML)
	    Globals.tooltipMap.openAbsolute(x - 190, y - 110, 190, -1, Globals.tooltipHTML[s]);
}

function hideMapTooltip()
{
	if (Globals.tooltipMap)
        Globals.tooltipMap.hide();
}


/* Search */


function Search(o)
{
    this.request;
    this.textbox = document.getElementById(o.textboxId);
    this.div = document.getElementById(o.divId);
    this.textboxTextDefault = o.textboxTextDefault;
    this.url = o.url;
    this.htmlHeader = o.htmlHeader;
    this.htmlFooter = o.htmlFooter;
    this.htmlLoading = o.htmlLoading;
    this.htmlNotFound = o.htmlNotFound;
}

Search.prototype.onLoad = function()
{
    this.textbox.removeAttribute("readOnly");
    this.textbox.value = this.textboxTextDefault;
}

Search.prototype.onTextboxFocus = function()
{
    if (this.textbox.value == this.textboxTextDefault)
        this.textbox.value = "";
}

Search.prototype.onTextboxBlur = function()
{
    if (this.isTextboxEmpty())
        this.textbox.value = this.textboxTextDefault;
}

Search.prototype.onTextboxKeyDown = function(e)
{
    var k = e.keyCode || key.which;
    
	switch (k)
	{
	    case 27:
	        if (this.isTextboxEmpty())
                this.textbox.blur();
            else
                this.reset();
		    return false;
		    
        case 13:
            if (this.isTextboxEmpty())
                this.reset();
            else
                this.search();                  
            return false;
	}

	return true;
}

Search.prototype.onButtonPress = function()
{
    if (this.textbox.value == this.textboxTextDefault)
    {
        var _this = this;
        this.textbox.value = "";
        setTimeout(function() { _this.textbox.focus(); }, 100);
    }
    else if (!this.isTextboxEmpty())
        this.search();
}

Search.prototype.isTextboxEmpty = function()
{
    return this.textbox.value.replace(/^\s*|\s*$/g, "").length == 0;
}

Search.prototype.reset = function()
{
    if (this.div.offsetHeight > 0)
        this.div.innerHTML = "<!-- -->";

    var _this = this;
    setTimeout(function() { _this.textbox.value = ""; }, 50);
}

Search.prototype.search = function()
{
    if (typeof(this.request) == "undefined")
        this.request = Ajax.createRequest();
        
    var _this = this;        

    this.request.open("GET", this.url + encodeURIComponent(this.textbox.value.replace(/^\s*|\s*$/g, "")), true);
    this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    this.request.setRequestHeader("Cache-Control", "no-cache");
    this.request.onreadystatechange = function() 
    {
        switch (_this.request.readyState)
        {
            case 0:
            case 1:
            case 2:
                break;            
            case 3:
                if (_this.htmlLoading.length > 0)
                    _this.div.innerHTML = _this.htmlHeader + _this.htmlLoading + _this.htmlFooter;
                break;

            case 4:
                if (_this.request.status == 200)
                {
                    if (_this.request.responseText.length == 0 && _this.htmlNotFound.length > 0)
                        _this.div.innerHTML = _this.htmlHeader + _this.htmlNotFound + _this.htmlFooter;
                    else
                        _this.div.innerHTML = _this.htmlHeader + _this.request.responseText + _this.htmlFooter;
                }
                break;
        }
    }
    
    this.request.send(null);
}


//////////////////// Map ////////////////////


function Map(o)
{
    this.markerIcon = new GIcon();
    this.markerIcon.image = o.iconImage;
    this.markerIcon.iconSize = new GSize(o.iconWidth, o.iconHeight);
    this.markerIcon.iconAnchor = new GPoint(o.iconAnchorX, o.iconAnchorY);
    this.markerIcon.infoWindowAnchor = new GPoint(o.infoWindowAnchorX, o.iconAnchorY);

    this.markerOptions = { icon:this.markerIcon };
    this.div = document.getElementById(o.containerId);    
    this.zoomDefault = o.zoomDefault;
    this.zoomLocate = o.zoomLocate;
    this.items = new Array();
    this.latSum = 0;
    this.lngSum = 0;
    this.length = 0;
    this.map = undefined;
}

Map.prototype.addMarker = function(id, lat, lng)
{
    if (isNaN(id = parseInt(id.substring(1), 10)))
        return false;

    this.latSum += lat;
    this.lngSum += lng;
    this.length++;
    this.items[id] = { lat:lat, lng:lng };
}

Map.prototype.showMap = function()
{
    if (typeof(this.div) != "object" || 
        this.map || 
        this.items.length == 0)
        throw new Error("showMap() error");

    this.map = new GMap2(this.div);        
    this.map.addControl(new GSmallMapControl());
    this.map.addControl(new GMapTypeControl());
    this.map.addControl(new GScaleControl());    
    this.map.addControl(new GOverviewMapControl()); 
    this.map.setCenter(new GLatLng(this.latSum / this.length, this.lngSum / this.length), this.zoomDefault);

    for (var id in this.items)
        this.map.addOverlay(this.createMarker(id, this.map, this.items[id].lat, this.items[id].lng));        
}

Map.prototype.createMarker = function(id, map, lat, lng)
{
    var latlng = new GLatLng(lat, lng);
    var marker = new GMarker(latlng, this.markerOptions);
    var html = this.getInfoWindowHTML(id);
    GEvent.addListener(marker, "click", function() { map.openInfoWindowHtml(latlng, html) });
    
    return marker;
}

Map.prototype.locateOnMap = function(id)
{
    if (typeof(this.map) == "undefined" || 
        this.items.length == 0 || 
        !this.items[id])
        throw new Error("locateOnMap() error");
        
    if (this.map.getZoom() < this.zoomLocate)    
        this.map.setZoom(this.zoomLocate);
        
    this.map.openInfoWindowHtml(new GLatLng(this.items[id].lat, this.items[id].lng), this.getInfoWindowHTML(id));
}

Map.prototype.getInfoWindowHTML = function(id)
{
    return "<div class=\"fA11n cTx\">" + document.getElementById("h" + id).innerHTML + "</div>";
}


/* Tooltip */


function Tooltip(id, image)
{
    this.image = {
        src                     : image,
        width                   : 892,
        height                  : 752,
        borderTop               : { left:13, top:45, width:0, height:13 },
        borderLeft              : { left:0, top:58, width:13, height:0 },   
        borderRight             : { left:879, top:58, width:13, height:0 },
        borderBottom            : { left:13, top:739, width:0, height:13 },        
        cornerWidth             : 13,
        cornerHeight            : 13,        
        cornerTopLeft           : { left:0, top:45, width:13, height:13 },
        cornerTopRight          : { left:879, top:45, width:13, height:13 },
        cornerBottomLeft        : { left:0, top:739, width:13, height:13 },
        cornerBottomRight       : { left:879, top:739, width:13, height:13 },
        edgeTopBottomWidth      : 51,
        edgeTopBottomHeight     : 32,
        edgeLeftRightWidth      : 32,
        edgeLeftRightHeight     : 31,
        edgeOffset              : 13, 
        edgeTop                 : { left:204, top:0, width:31, height:32 },
        edgeBottom              : { left:235, top:0, width:31, height:32 },
        edgeLeft                : { left:266, top:0, width:32, height:31 },
        edgeRight               : { left:298, top:0, width:32, height:31 },                  
        edgeTopLeft             : { left:102, top:0, width:51, height:32 },
        edgeTopRight            : { left:153, top:0, width:51, height:32 },
        edgeBottomLeft          : { left:0, top:0, width:51, height:32 },
        edgeBottomRight         : { left:51, top:0, width:51, height:32 }
    };
    
    this.flipVerticalOffset = 0;
    this.flipVerticalEnabled = false;
    this.edgeType = Tooltip.EdgeType.none;
    this.edgePosition = 0;
    this.htmlHeader = "";
    this.htmlFooter = "";
    this.htmlLoading = "";
    this.hideDelay = 1000;
        
    this.request;
    this.timeout;
    this.width = 0;
    this.height = 0;
    this.idDivFrame = id + "_frame";
    this.idDivClient = id + "_client";    

    this.divFrame = document.createElement("div");
    this.divFrame.id = this.idDivFrame;
    this.divFrame.style.visibility = "hidden";    
    this.divFrame.style.position = "absolute";
    document.body.appendChild(this.divFrame);
    
    this.divClient = document.createElement("div");
    this.divClient.id = this.idDivClient;
    this.divClient.style.position = "absolute";
    this.divClient.style.backgroundColor = "white";
    this.divFrame.appendChild(this.divClient);

    var _preload = new Image(this.image.width, this.image.height);
    _preload.src = this.image.src;
}

Tooltip.EdgeType = {
    none                    : 0,
    left                    : 1,
    right                   : 2,
    topLeft                 : 3,
    topRight                : 4,
    bottomLeft              : 5,
    bottomRight             : 6
}

Tooltip.prototype.openRelative = function(element, offsetX, offsetY, width, height, source)
{
    if (typeof(element) != "object")
        throw new Error("Ivalid element");

    var p = Tooltip.findPos(element);
    var left = p[0] + offsetX - document.body.scrollLeft;
    var top = p[1] + offsetY - document.body.scrollTop;
    this.openAbsolute(left, top, width, height, source);
}

Tooltip.prototype.openAbsolute = function(left, top, width, height, source)
{
    if (this.flipVerticalEnabled)
        this.divFrame.style.top = Math.max(0, (top + this.height > document.body.clientHeight ? top - this.height + this.flipVerticalOffset : top))  + document.body.scrollTop + "px";
    else
        this.divFrame.style.top = Math.max(0, (top + this.height > document.body.clientHeight ? document.body.clientHeight - this.height : top)) + document.body.scrollTop + "px";

    this.divFrame.style.left = Math.max(0, (left + this.width > document.body.clientWidth ? document.body.clientWidth - this.width : left)) + document.body.scrollLeft + "px";

    if (!this.isAlive())
    {
        if (/^http/.test(source))
        {
            if (typeof(this.request) == "undefined")
                this.request = Ajax.createRequest();
                
            this.drawTooltip(left, top, width, height, "");                

            var _this = this;        

            this.request.open("GET", source, true);
            this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            this.request.setRequestHeader("Cache-Control", "no-cache");
            this.request.onreadystatechange = function() 
            {
                switch (_this.request.readyState)
                {
                    case 0:
                    case 1:
                    case 2:
                        break;                    
                    case 3:
                        if (_this.htmlLoading.length > 0)
                            _this.divClient.innerHTML = _this.htmlHeader + _this.htmlLoading + _this.htmlFooter;
                        break;

                    case 4:
                        if (_this.request.status == 200)
                            _this.divClient.innerHTML = _this.htmlHeader + _this.request.responseText + _this.htmlFooter;
                        break;
                }
            }
            
            this.request.send(null);
        }
        else
        {
            this.drawTooltip(left, top, width, height, source);
        }
    }
    else
        this.divClient.innerHTML = source;

    this.show();
}

Tooltip.prototype.show = function()
{
    if (this.timeout)
    {
        clearTimeout(this.timeout);
        this.timeout = null;
    }
        
    this.divFrame.style.visibility = "visible";
}

Tooltip.prototype.hide = function()
{
    var delay = this.hideDelay;
    
    if (this.divFrame.style.visibility == "visible")
    {    
        if (arguments.length > 0)
        {
            var d = parseInt(arguments[0], 10);
            
            if (!isNaN(d))
            {
                if (d <= 0)
                {
                    this.divFrame.style.visibility = "hidden";
                    
                    if (this.timeout)
                    {
                        clearTimeout(this.timeout);
                        this.timeout = null;
                    }
                    
                    return;               
                }
                else
                    delay = d;
            }
        }

        var _this = this;
        this.timeout = setTimeout(function() { if (_this.timeout) { _this.divFrame.style.visibility = "hidden"; _this.timeout = null;} }, delay);
    }
}

Tooltip.prototype.close = function()
{
    this.divFrame.style.visibility = "hidden";
    
    var o = this.divFrame.firstChild;
    var t;

    while (o)
    {
        if (o.id != this.idDivClient)
        {
            t = o;
            o = o.nextSibling;
            this.divFrame.removeChild(t);
        }
        else
            o = o.nextSibling;            
    }     

    this.divFrame.style.height = "";
    this.divFrame.style.width = "";
}

Tooltip.prototype.drawTooltip = function(left, top, width, height, html)
{
    if (!this.isValidDimension(width))
        throw new Error("Invalid width specified");
        
    var x = 0;        
    var y = 0;
    var isEdgeTop = (this.edgeType == Tooltip.EdgeType.topLeft || this.edgeType == Tooltip.EdgeType.topRight || this.edgeType == Tooltip.EdgeType.top);
    var isEdgeBottom = (this.edgeType == Tooltip.EdgeType.bottomLeft || this.edgeType == Tooltip.EdgeType.bottomRight || this.edgeType == Tooltip.EdgeType.bottom);
    var isEdgeLeft = (this.edgeType == Tooltip.EdgeType.left);
    var isEdgeRight = (this.edgeType == Tooltip.EdgeType.right);
    
    this.divClient.style.left = (isEdgeLeft ? this.image.edgeLeftRightWidth : this.image.cornerWidth) + "px";
    this.divClient.style.top = (isEdgeTop ? this.image.edgeTopBottomHeight : this.image.cornerHeight) + "px";
    
    var w = width - 2 * this.image.cornerWidth;
    
    if (isEdgeLeft || isEdgeRight)
        w -= this.image.edgeLeftRightWidth - this.image.edgeOffset;

    if (w >= 0)
        this.divClient.style.width = w + "px";

    if (this.isValidDimension(height))
    {
        var h = height - 2 * this.image.cornerHeight;
        
        if (isEdgeTop || isEdgeBottom)
            h -= this.image.edgeTopBottomHeight - this.image.edgeOffset;
            
        if (h >= 0)
            this.divClient.style.height = h + "px";            
    }
    
    this.divClient.innerHTML = html;
        
    var clientWidth = this.divClient.offsetWidth;
    var clientHeight = this.divClient.offsetHeight;
    var edgePositionMax = (isEdgeLeft || isEdgeRight) ? clientHeight - this.image.edgeLeftRightHeight : clientWidth - this.image.edgeTopBottomWidth;
    
    if (isEdgeLeft)
        x += this.image.edgeLeftRightWidth - this.image.edgeOffset;    
    
    this.edgePosition = this.edgePosition ? Math.max(Math.min(this.edgePosition, edgePositionMax), 0) : 0;
    
    if (isEdgeTop)
    {
        y = this.image.edgeTopBottomHeight - this.image.edgeOffset;
        
        if (this.edgePosition > 0)
            this.addBorderTop(x + this.image.cornerWidth, y, this.edgePosition)

        this.addEdge(x + this.image.cornerWidth + this.edgePosition, 0, this.edgeType);

        if (this.edgePosition < edgePositionMax)
            this.addBorderTop(x + this.image.cornerWidth + this.edgePosition + this.image.edgeTopBottomWidth, y, clientWidth - this.edgePosition - this.image.edgeTopBottomWidth);
    }
    else
        this.addBorderTop(x + this.image.cornerWidth, y, clientWidth);
        
    this.addCornerTopLeft(x, y);
    this.addCornerTopRight(x + this.image.cornerWidth + clientWidth, y);        

    y += this.image.cornerHeight;
    
    if (isEdgeLeft)
    {
        if (this.edgePosition > 0)
           this.addBorderLeft(x, y, this.edgePosition);
           
        this.addEdge(0, this.image.cornerHeight + this.edgePosition, this.edgeType);           

        if (this.edgePosition < edgePositionMax)
            this.addBorderLeft(x, this.image.cornerHeight + this.edgePosition + this.image.edgeLeftRightHeight, clientHeight - this.edgePosition - this.image.edgeLeftRightHeight);
    }
    else
        this.addBorderLeft(x, y, clientHeight);
        
    if (isEdgeRight)
    {
        if (this.edgePosition > 0)
           this.addBorderRight(x + this.image.cornerWidth + clientWidth, y, this.edgePosition);
           
        this.addEdge(x + this.image.cornerWidth + clientWidth, this.image.cornerHeight + this.edgePosition, this.edgeType);           

        if (this.edgePosition < edgePositionMax)
            this.addBorderRight(x + this.image.cornerWidth + clientWidth, this.image.cornerHeight + this.edgePosition + this.image.edgeLeftRightHeight, clientHeight - this.edgePosition - this.image.edgeLeftRightHeight);
    }
    else
        this.addBorderRight(x + this.image.cornerWidth + clientWidth, y, clientHeight);         

    y += clientHeight;
    this.addCornerBottomLeft(x, y);
    this.addCornerBottomRight(x + this.image.cornerWidth + clientWidth, y);    

    if (isEdgeBottom)
    {
        if (this.edgePosition > 0)
            this.addBorderBottom(x + this.image.cornerWidth, y, this.edgePosition);

        this.addEdge(x + this.image.cornerWidth + this.edgePosition, y, this.edgeType);            
        
        if (this.edgePosition < edgePositionMax)
                this.addBorderBottom(x + this.image.cornerWidth + this.edgePosition + this.image.edgeTopBottomWidth, y, clientWidth - this.edgePosition - this.image.edgeTopBottomWidth);
                
        y += this.image.edgeTopBottomHeight;
    }
    else
    {
        this.addBorderBottom(x + this.image.cornerWidth, y, clientWidth);
        y += this.image.cornerHeight;
    }
        
    this.width = width;
    this.height = (this.isValidDimension(height)) ? height : y;
    
    this.divFrame.style.left = left + "px";
    this.divFrame.style.top = top + "px";
    this.divFrame.style.width = this.width + "px";
    this.divFrame.style.height = this.height + "px";
}

Tooltip.prototype.addCornerTopLeft = function(left, top)
{
    this.addImageSlice(left, top, this.image.cornerTopLeft.left, this.image.cornerTopLeft.top, this.image.cornerTopLeft.width, this.image.cornerTopLeft.height);
}

Tooltip.prototype.addCornerTopRight = function(left, top)
{
    this.addImageSlice(left, top, this.image.cornerTopRight.left, this.image.cornerTopRight.top, this.image.cornerTopRight.width, this.image.cornerTopRight.height);
}

Tooltip.prototype.addCornerBottomLeft = function(left, top)
{
    this.addImageSlice(left, top, this.image.cornerBottomLeft.left, this.image.cornerBottomLeft.top, this.image.cornerBottomLeft.width, this.image.cornerBottomLeft.height);
}

Tooltip.prototype.addCornerBottomRight = function(left, top)
{
    this.addImageSlice(left, top, this.image.cornerBottomRight.left, this.image.cornerBottomRight.top, this.image.cornerBottomRight.width, this.image.cornerBottomRight.height);
}

Tooltip.prototype.addBorderLeft = function(left, top, height)
{
    this.addImageSlice(left, top, this.image.borderLeft.left, this.image.borderLeft.top, this.image.borderLeft.width, height);        
}

Tooltip.prototype.addBorderRight = function(left, top, height)
{
    this.addImageSlice(left, top, this.image.borderRight.left, this.image.borderRight.top, this.image.borderRight.width, height);
}

Tooltip.prototype.addBorderTop = function(left, top, width)
{
    this.addImageSlice(left, top, this.image.borderTop.left, this.image.borderTop.top, width, this.image.borderTop.height);
}

Tooltip.prototype.addBorderBottom = function(left, top, width)
{
    this.addImageSlice(left, top, this.image.borderBottom.left, this.image.borderBottom.top, width, this.image.borderBottom.height);
}

Tooltip.prototype.addEdge = function(left, top, edgeType)
{
    switch (edgeType)
    {
        case Tooltip.EdgeType.left:
            this.addImageSlice(left, top, this.image.edgeLeft.left, this.image.edgeLeft.top, this.image.edgeLeft.width, this.image.edgeLeft.height);
            break;

        case Tooltip.EdgeType.right:
            this.addImageSlice(left, top, this.image.edgeRight.left, this.image.edgeRight.top, this.image.edgeRight.width, this.image.edgeRight.height);
            break;            

        case Tooltip.EdgeType.topLeft:
            this.addImageSlice(left, top, this.image.edgeTopLeft.left, this.image.edgeTopLeft.top, this.image.edgeTopLeft.width, this.image.edgeTopLeft.height);
            break;

        case Tooltip.EdgeType.topRight:
            this.addImageSlice(left, top, this.image.edgeTopRight.left, this.image.edgeTopRight.top, this.image.edgeTopRight.width, this.image.edgeTopRight.height);
            break;

        case Tooltip.EdgeType.bottomLeft:            
            this.addImageSlice(left, top, this.image.edgeBottomLeft.left, this.image.edgeBottomLeft.top, this.image.edgeBottomLeft.width, this.image.edgeBottomLeft.height);
            break;

        case Tooltip.EdgeType.bottomRight:            
            this.addImageSlice(left, top, this.image.edgeBottomRight.left, this.image.edgeBottomRight.top, this.image.edgeBottomRight.width, this.image.edgeBottomRight.height);
            break;
    }
}

Tooltip.prototype.addImageSlice = function(left, top, sliceLeft, sliceTop, sliceWidth, sliceHeight)
{
    var divClip = document.createElement("div");
    divClip.style.position = "absolute";
    divClip.style.left = left + "px";
    divClip.style.top = top + "px";
    divClip.style.width = sliceWidth + "px";
    divClip.style.height = sliceHeight + "px";
    divClip.style.overflow = "hidden";
    
    var divPNG = document.createElement("div");
    divPNG.style.position = "absolute";
    divPNG.style.left = -sliceLeft + "px";
    divPNG.style.top = -sliceTop + "px";
    divPNG.style.width = this.image.width + "px";
    divPNG.style.height = this.image.height + "px";
    
    if (this.isIE())
        divPNG.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"" + this.image.src + "\")";
    else 
    {
        divPNG.style.backgroundImage = "url(" + this.image.src + ")";
        divPNG.style.backgroundPosition = "bottom left";
        divPNG.style.backgroundRepeat = "no-repeat";    
    }

    divClip.appendChild(divPNG);
    this.divFrame.appendChild(divClip);
}

Tooltip.prototype.isAlive = function()
{
    return this.divFrame.childNodes.length > 1;
}

Tooltip.prototype.isValidDimension = function(px)
{
    var r = parseInt(px, 10);
    return (!isNaN(r) && r >= 0);
}

Tooltip.prototype.isIE = function()
{
    return (document.all && !window.opera) ? true : false;
}

Tooltip.findPos = function(o)
{
    var l = t = 0;

    if (o.offsetParent)
    {
        l = o.offsetLeft;
        t = o.offsetTop;

        while (o = o.offsetParent)
        {
            l += o.offsetLeft;
            t += o.offsetTop;
        }
    }

    return [l, t];
}


//////////////////// Ajax ////////////////////


function Ajax()
{
}

Ajax.createRequest = function()
{
    if (typeof(XMLHttpRequest) != "undefined")
    {
        return new XMLHttpRequest();
    }
    else if (typeof(ActiveXObject) != "undefined")
    {
        var versions = new Array(
              "Msxml2.XMLHTTP.7.0",
              "Msxml2.XMLHTTP.6.0",
              "Msxml2.XMLHTTP.5.0",
              "Msxml2.XMLHTTP.4.0",
              "MSXML2.XMLHTTP.3.0",
              "MSXML2.XMLHTTP",
              "Microsoft.XMLHTTP"
              );
           
        for (var i = 0; i < versions.length; i++)
        {
            try 
            {
                var request = new ActiveXObject(versions[i]);
                return request;
            }
            catch (e)
            {
            }
        }
    }

    throw new Error("Unable to create request object");
}
