///////////////////////////
// CopyRight(C) 2007 Imm //
// imm@artsolve.ru       //
// Version 1.0 build 001 //
///////////////////////////



// Возвращает реальную область окна
function getWndRect()
{
    //Создаем CRect, если функция вызвана без параметров
    var rect = {left:0, right:0, top:0, bottom:0};
 
    if (BrowserType.ie) // IE
    {
        var wnd = document.body;
        rect.left = wnd.scrollLeft;
        rect.top = wnd.scrollTop;
        rect.right = rect.left + wnd.clientWidth;
        rect.bottom = rect.top + wnd.clientHeight;     
    }
    else // Opera, Mozilla
    {
        var wnd = window;
        rect.left = wnd.pageXOffset;
        rect.top = wnd.pageYOffset;
        rect.right = rect.left + wnd.innerWidth;
        rect.bottom = rect.top + wnd.innerHeight;    
    }
    return rect;
}



function ChgLayer(layer_id)
{
    var node = document.getElementById(layer_id);
    if (!node) return 0;
    
    node.style.display = (node.style.display) ? '' : 'none';
}    


function ShowLayer(layer_id)
{
    var node = document.getElementById(layer_id);
    if (!node) return 0;

    node.style.display = '';
}

function HideLayer(layer_id)
{
    var node = document.getElementById(layer_id);
    if (!node) return 0;
    
    node.style.display = 'none';
}

function ShowLayer2(ctrl_node, layer_id)
{
   if (!ctrl_node) return 0;    
    var node2 = ctrl_node;

    var node = document.getElementById(layer_id);
    if (!node) return 0;                
    if (!node.style.display) return 0;
    
    var wwidth = 250, wheight = 250;
       
    node.style.visibility = 'hidden';    
    node.style.display = ''; 
            
    var img = $(node).find('img').eq(0);
    
    var w = (img.css('width').substr(img.css('width').length-2) == 'px') ?
            img.css('width').substr(0,img.css('width').length-2) : img.css('width');
    
    var h = (img.css('height').substr(img.css('height').length-2) == 'px') ?
            img.css('height').substr(0,img.css('height').length-2) : img.css('height');                
                
    if (w > wwidth)
    {
        img.css({'height': ((h*wwidth)/w)+'px', 'width': wwidth+'px'});
        $(node).css({'height': (h*wwidth/w)+'px', 'width': wwidth+'px'});
    }
    
    var w = (img.css('width').substr(img.css('width').length-2) == 'px') ?
            img.css('width').substr(0,img.css('width').length-2) : img.css('width');
    
    var h = (img.css('height').substr(img.css('height').length-2) == 'px') ?
            img.css('height').substr(0,img.css('height').length-2) : img.css('height');                
            
    if (h > wheight)
    {
        img.css({'width': (w*wheight/h)+'px', 'height': wheight+'px'});
        $(node).css({'width': (w*wheight/h)+'px', 'height': wheight+'px'});
    }       
    
    var w = (img.css('width').substr(img.css('width').length-2) == 'px') ?
            img.css('width').substr(0,img.css('width').length-2) : img.css('width');
    
    var pos = $(ctrl_node).offset();    
            
    $(node).css({
                'position': 'absolute',
                'left': Math.min(pos.left, (window.innerWidth ? window.innerWidth : document.body.clientWidth)-w-30)+'px',
                'top': (pos.top + 25)+'px'
            }); 
    
    node.style.visibility = 'visible';
}

function ShowLayer3(img, pos)
{
    if (!img.get(0)) return false;
    
    img.css({'position': 'absolute'});

    var wwidth = 250, wheight = 250;
    
    var w = img.width();    
    var h = img.height();                
                
    if (w > wwidth)
    {        
        var h = (h*wwidth)/w;
        var w = wwidth;
        img.css({'height': h+'px', 'width': w+'px'});                 
    }    
            
    if (h > wheight)
    {
        var w = (w*wheight)/h;
        var h = wheight;
        img.css({'width': w + 'px', 'height': h + 'px'});       
    }
            
    img.css({
                'left': Math.min(pos.left, (window.innerWidth ? window.innerWidth : document.body.clientWidth)-w-30)+'px',
                'top': (pos.top + 25)+'px',
                'border' : '5px solid #f0f4ff'
            }).show(); 
}


function HideLayer2(ctrl_node, layer_id)
{
    var node = document.getElementById(layer_id);
    if (!node) return 0;
    
    node.style.display = 'none';
}


function hcontreg(node, id)
{
	node.onmouseover = new Function([], "ShowLayer2(this, '" + id + "')");
	node.onmouseout = new Function([], "HideLayer2(this, '" + id + "')");
	ShowLayer2(node, id);
}




