// File: jsblame
// Javascript library. It contains functions for manipulate html objects
// over the page. Release: $Name:  $
// 
// Edit by: $Author: mcbig $
// Edit Date: $Date: 2006/10/05 19:23:25 $
// Version: $Revision: 1.4 $

// Function: GetLeftFromDocument
// returns real left offset from left side, without regard to his position in html tree
function GetLeftFromDocument(DomObject){
    if ((DomObject == document.body) || (DomObject.tagName == "HTML")){ 
        // the HTML is hack of shit IE, i don't know, how that hogs
        // can developing full system, when they can't manage web browser
        return 0;
    } else {
        return DomObject.offsetLeft + GetLeftFromDocument(DomObject.offsetParent);
    }
}

// Function: Center
// center object on html page (<Form> for example)
// id - html object id
function Center(id){
    IdObject = document.getElementById(id);
    IdObject.style.left = (document.body.clientWidth / 2) - (IdObject.offsetWidth / 2);
    IdObject.style.top = (document.body.clientHeight / 2) - (IdObject.offsetHeight / 2);
}

// Function: RollHeightDown
// Roll down object in high
// r - step
// id - object id
// lnOHeight - real object heigh
function RollHeightDown(r,id,lnOHeight){
    IdObject = document.getElementById(id);
    if (r < 10){
        var newheigh = lnOHeight * (r/10);
        IdObject.style.height = ''+newheigh+'px'; 
        setTimeout('RollHeightDown('+(r+5)+',"'+id+'",'+lnOHeight+');',10);
    }else {
        IdObject.style.height = ''+lnOHeight+'px'; 
    }
}

// Function: RollHeightUp
// Roll up object in high
// r - step
// id - object id
// lnOHeight - real object heigh
function RollHeightUp(r,id,lnOHeight){
    IdObject = document.getElementById(id);
    if (r > 0){
        var newheigh = lnOHeight * (r/10);
        IdObject.style.height = ''+newheigh+'px'; 
        setTimeout('RollHeightUp('+(r-5)+',"'+id+'",'+lnOHeight+');',10);
    }else {
        IdObject.style.height = '0px'; 
        IdObject.style.visibility='hidden';
    }
}

// Function: AnimateDown
// Animate object down from hide to full visible
// id - object id
// Be carefull, when you change steping algorithm in <RollHeightDown>, firefox
// has so slow javascript engine.
function AnimateDown(id){
    IdObject = document.getElementById(id);
    if (IdObject.style.visibility == 'hidden'){
        try{
            eval('var lnOHeight = '+id+'_height;');
        }
        catch(e) {
            eval(id+'_height = IdObject.offsetHeight;'); 
            eval('var lnOHeight = '+id+'_height;');
        }
        IdObject.style.overflow = 'hidden';
        IdObject.style.height = '0px';
        // todo: litle hack, couse explorer don't know heigh after writing object to pege
        IdObject.style.position = 'static';
        IdObject.style.visibility='visible';
        RollHeightDown(1,id,lnOHeight);
    }
}

// Function: AnimateUp
// Animate object up from full visible to hide
// id - object id
// Be carefull, when you change steping algorithm in <RollHeightUp>, firefox
// has so slow javascript engine.
function AnimateUp(id){
    IdObject = document.getElementById(id);
    if (IdObject.style.visibility == 'visible'){
        try{
            eval('var lnOHeight = '+id+'_height;');
        }
        catch(e) {
            eval(id+'_height = IdObject.offsetHeight;'); 
            eval('var lnOHeight = '+id+'_height;');
        }
        IdObject.style.overflow = 'hidden';
        RollHeightUp(10,id,lnOHeight);
    }
}

// Function: Show(id)
// object can be visible by two variants, via visibility attribute
// or via animation (see code).
function Show(id){
    //document.getElementById(id).style.visibility='visible';
    AnimateDown(id);
}

// Function: MShow
// Show submenu div. When DomObject has MainMenuBar parent, then
// left is reltive to it's item. See <menu>.php or generated html with menu for
// mor details.
function MShow(DomObject, id){
    if (DomObject.parentNode.id == 'MainMenuBar'){
        document.getElementById(id).style.left = GetLeftFromDocument(DomObject)+'px';
    }
    document.getElementById(id).style.visibility='visible';
}

// Function: Hide
// Set visibility hidden.
function Hide(id){
    document.getElementById(id).style.visibility='hidden';
}

// Function: MHide
// Set visibility hidden. This function is duplicate for submenu. 
function MHide(id){
    document.getElementById(id).style.visibility='hidden';
}

// Function: CloseHeight
// Hides object on page, to it could be roll down via <AnimateDown>
function CloseHeight(id){
    IdObject = document.getElementById(id);
    IdObject.style.position = 'absolute';
    IdObject.style.visibility = 'hidden';
}

// Function: ChangeVisibility
// Simple change visivility of id object
function ChangeVisibility(id){
    IdObject = document.getElementById(id); 
    if (IdObject.style.visibility == 'visible'){
        IdObject.style.visibility='hidden';
    } else {
	   Center(id);
	   IdObject.style.visibility='visible';
    }
}
