oldOnLoad = window.onload;
if (typeof window.onload != 'function') {
    window.onload = function() {
    CreateTooltip();
    SetTooltips();
    };
}
else {
    window.onload = function() {
        oldOnLoad();
    CreateTooltip();
    SetTooltips();
    };
}



function CreateTooltip() {
    tooltip = document.createElement('DIV');
    tooltip.setAttribute('id', 'tooltip');

    tooltipHeader = document.createElement('DIV');
    tooltipHeader.setAttribute('id', 'tooltipHeader');
    tooltipHeader.setAttribute('class', 'direct');

    tooltipBody   = document.createElement('DIV');
    tooltipBody.setAttribute('id', 'tooltipBody');

    tooltipFooter = document.createElement('DIV');
    tooltipFooter.setAttribute('id', 'tooltipFooter');

    tooltipBody.innerText = 'tooltip';

    tooltip.appendChild(tooltipHeader);
    tooltip.appendChild(tooltipBody);
    tooltip.appendChild(tooltipFooter);
    tooltipcanclose=true;

    tooltip.onmouseover   = function(e) { this.style.filter = "Alpha(Opacity='100')"; this.style.MozOpacity = '1';  tooltipcanclose=false;}
    tooltip.onmouseout    = function(e) { this.style.filter = "Alpha(Opacity='85')"; this.style.MozOpacity = '0.85'; tooltipcanclose=true; setTimeout("CloseTooltip();", 1000);}

    tooltip.onclick       = function(e) {   tooltipcanclose=true; CloseTooltip(); }

    document.body.appendChild(tooltip);

    window.onresize      = function(e) {  tooltipcanclose=true; CloseTooltip(); }
    document.body.onclick= function(e) {  tooltipcanclose=true; CloseTooltip(); }
    
    adminpanel = document.createElement('div');
    adminpanel.style.cssText = "position: absolute; left: 3%; top: 0px; z-index: 1000;";
    adminpanel.setAttribute('style', 'position: absolute; left: 3%; top: 0px; z-index: 1000;');
    //minpanel.innerHTML = "<a href='admin/'><img  title='Перейти в панель управления' alt='Перейти в панель управления' border=0 src='/data/js/admintooltip/i/bookmark.gif'></a>";
    document.body.appendChild(adminpanel);
    
    
}

function CloseTooltip()
{
  if(tooltipcanclose)
    document.getElementById('tooltip').style.display = 'none';
}

function SetTooltips() {
    elements = document.getElementsByTagName("body")[0].getElementsByTagName("*");
//alert(elements);
    for (i = 0; i <elements.length; i++)
    {
        tooltip = elements[i].getAttribute('tooltip');
        if(tooltip)
        {
            elements[i].onmouseout = function(e) {tooltipcanclose=true;setTimeout("CloseTooltip();", 1000);};        
            switch(tooltip)
            {    
                case 'product':                                      
                   elements[i].onmouseover = function(e) {AdminProductTooltip(this,  this.getAttribute('product_id'));tooltipcanclose=false;}
                break;
                case 'hit':                                      
                   elements[i].onmouseover = function(e) {AdminHitTooltip(this,  this.getAttribute('product_id'));tooltipcanclose=false;}
                break;
                case 'category':                                          
                   elements[i].onmouseover = function(e) {AdminCategoryTooltip(this,  this.getAttribute('category_id'));tooltipcanclose=false;}
                break;
                case 'brand':                                          
                   elements[i].onmouseover = function(e) {AdminBrandTooltip(this,  this.getAttribute('brand_id'));tooltipcanclose=false;}
                break;
                case 'news':                                          
                   elements[i].onmouseover = function(e) {AdminNewsTooltip(this,  this.getAttribute('news_id'));tooltipcanclose=false;}
                break;
                case 'article':                                          
                   elements[i].onmouseover = function(e) {AdminArticleTooltip(this,  this.getAttribute('article_id'));tooltipcanclose=false;}
                break;
                case 'section':                                          
                   elements[i].onmouseover = function(e) {AdminSectionTooltip(this,  this.getAttribute('section_id')); tooltipcanclose=false;}
                break;
                case 'currency':                                          
                   elements[i].onmouseover = function(e) {AdminCurrencyTooltip(this); tooltipcanclose=false;}
                break;
                case 'comment':                                          
                   elements[i].onmouseover = function(e) {AdminCommentTooltip(this, this.getAttribute('comment_id')); tooltipcanclose=false;}
                break;
            }


        }
        
    }

}


function ShowTooltip(i, content) {

    tooltip = document.getElementById('tooltip');

    document.getElementById('tooltipBody').innerHTML = content;
    tooltip.style.display = 'block';

    var xleft=0;
    var xtop=0;
    o = i;

    do {
        xleft += o.offsetLeft;
        xtop  += o.offsetTop;

    } while (o=o.offsetParent);

    xwidth  = i.offsetWidth  ? i.offsetWidth  : i.style.pixelWidth;
    xheight = i.offsetHeight ? i.offsetHeight : i.style.pixelHeight;

    bwidth =  tooltip.offsetWidth  ? tooltip.offsetWidth  : tooltip.style.pixelWidth;

    w = window;

    xbody  = document.compatMode=='CSS1Compat' ? w.document.documentElement : w.document.body;
    dwidth = xbody.clientWidth  ? xbody.clientWidth   : w.innerWidth;
    bwidth = tooltip.offsetWidth ? tooltip.offsetWidth  : tooltip.style.pixelWidth;

    flip = !( 25 + xleft + bwidth < dwidth);

    tooltip.style.top  = xheight - 3 + xtop + 'px';
    tooltip.style.left = (xleft - (flip ? bwidth : 0)  + 25) + 'px';

    document.getElementById('tooltipHeader').className = flip ? 'tooltipHeaderFlip' : 'tooltipHeaderDirect';

    return false;
}















