
/**
 * getDocHeight()
 *
 * @see http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/index.html
 */
 
function getDocHeight()
{
    if (window.innerHeight)
    {
    	theHeight = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
    	theHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
    	theHeight = document.body.clientHeight;
    }
    
    return theHeight;
}

/**
 * findPos()
 *
 * @see http://www.quirksmode.org/js/findpos.html
 */

function findPos(obj) 
{
    var curleft = curtop = 0;

    if (obj.offsetParent) 
    {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop

        while (obj = obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }

    return [curleft,curtop];
}


/**
 * setHeights()
 */
 
function setHeights()
{
    var theBodyHeight    = getDocHeight();
    
    if(theBodyHeight < 650)
    {
        theBodyHeight = 650;
    }
    
    var yuiDocHeight     = theBodyHeight-35;
    var yuiElementHeight = '';
    
    // yui doc
     
    if(document.getElementById)
    {
        document.getElementById('custom-doc').style.height = yuiDocHeight+"px";
    }
    
    // yui hd
    
    yuiElementHeight = yuiDocHeight*0.20;
    
    if(document.getElementById)
    {
        document.getElementById('hd').style.height = yuiElementHeight+"px";
    }
    
    // yui bd
    
    yuiElementHeight = yuiDocHeight*0.75;
    
    if(document.getElementById)
    {
        document.getElementById('content').style.height = yuiElementHeight+"px";
    }
    
    // yui ft
    
    yuiElementHeight = (yuiDocHeight*0.05)-3;
    
    if(document.getElementById)
    {
        document.getElementById('ft').style.height = yuiElementHeight+"px";
    }
     
}

/**
 * setCaption()
 */

function setCaption()
{
    if(!document.getElementById)
    {
        return;
    }
    
    var caption = document.getElementById('captionInText');
    
    if(!caption)
    {   
        return;
    }
        
    caption.style.visibility  = "hidden";
    
    var captionHeight  = caption.offsetHeight;
    var picHeight      = getByClassName('div','thePic').offsetHeight;
    var textHeight     = getByClassName('div','theText').offsetHeight;;
    var marginToTop    = picHeight-textHeight-captionHeight;
    
    if(marginToTop > 0)
    {
        caption.style.paddingTop = marginToTop+"px";  
    }
    
    caption.style.visibility  = "visible";
}

function getByClassName(elem, elemClassName)
{
    var elemAll = document.getElementsByTagName(elem);
    
    for(var i = 0; i < elemAll.length; i++)
    {
        if(elemAll[i].className == elemClassName)
        {
            return elemAll[i];    
        }
    }
}

/**
 * placeElem()
 */

function placeElem(elemId)
{
    if(!document.getElementById)
    {
        return;
    }

    var maxHeightChunk = 340;

    var elemToPlace    = document.getElementById(elemId);
    var elemHeight     = elemToPlace.offsetHeight;

    var contentHeight  = document.getElementById('content').offsetHeight;
    var maxHeight      = document.getElementById('contentContainer').offsetHeight;
    
    var spaceLeft      = maxHeight-contentHeight-elemHeight;

    if(spaceLeft >= 0)
    {
        elemToPlace.style.paddingTop = spaceLeft+'px';
    }
    else
    {
        elemToPlace.style.paddingTop = '0px';
    }     
}

/*
 * placeLogos()
 */

function placeLogos()
{
    return;

    if(!document.getElementById)
    {
        return;
    }
    
    var firstParam = '';
    
    var logos      = document.getElementById('logos');
    var logoBlock  = document.getElementById('logoBlock');
    var content    = document.getElementById('pagedContent-1');
    
    var posTop     = 0;
    var posLeft    = 0;

    for(var i=0; content.childNodes.length; i++)
    {
        if(content.childNodes[i].nodeName.toLowerCase() == 'p')
        {
            firstParam = content.childNodes[i];
            break;
        }
    }

    if(firstParam)
    {
        posTop = findPos(logos);
    }

    posLeft = findPos(logos);    
    
    logoBlock.style.top  = posTop[1]+'px';
    //logoBlock.style.left = posLeft[0]+'px';
}

/**
 * doPopup()
 */

function doPopup()
{
    var thePic    = document.getElementsByTagName('img');
    var theHeight = thePic[0].offsetHeight;
    var theWidth  = thePic[0].offsetWidth;

    self.moveTo((screen.width*0.30),50); 
    self.resizeTo(theWidth+30,theHeight+100); 
}

/**
 * popupClose()
 */

function winClose()
{
    self.close();
}




