function isDefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function trim(str)
{  
    while( str.charAt(0) == " " ||  str.charAt(0) == "\n" )
        str = str.substring(1);

    while( str.charAt(str.length-1) == " " || str.charAt(str.length-1) == "\n" )
        str = str.substring(0,str.length-1);

    return str;
}

function divs()
{
    // top left logo
    this.logoDiv          = YAHOO.util.Dom.get("logo");

    // left-hand menu
    this.menuDiv          = YAHOO.util.Dom.get("menu");

    // the gray bar to the left of the left-hand menu
    this.menuLeftDiv      = YAHOO.util.Dom.get("menuLeft");

    // below the left-hand menu div marker
    this.endMenuDiv       = YAHOO.util.Dom.get("endMenu");

    // text that goes in the banner div
    this.bannerContentDiv = YAHOO.util.Dom.get("bannerContent");

    // y position of the top of the left-hand menu
    this.menuTop          = YAHOO.util.Dom.getY(this.menuDiv); 

    // y position of the bottom of the left-hand menu
    this.endMenuTop       = YAHOO.util.Dom.getY(this.endMenuDiv);

    // y position of the banner top
    this.bannerTop        = YAHOO.util.Dom.getY(this.logoDiv);

    // banner area height
    this.bannerHeight     = this.logoDiv.offsetHeight;

    // content area top (just under the banner)
    this.contentTop = this.bannerTop + this.bannerHeight;

    // left-hand menu height
    this.menuHeight       = this.endMenuTop - this.menuTop;

    // photo content div
    this.photoContentDiv  = YAHOO.util.Dom.get("photoContent");

    // main content area div
    this.mainContentDiv   = YAHOO.util.Dom.get("mainContent");
    this.mainContentTop   = YAHOO.util.Dom.getY(this.mainContentDiv);
    this.belowMainContentDiv = YAHOO.util.Dom.get("belowMainContent");
    this.mainContentHeight = YAHOO.util.Dom.getY(this.belowMainContentDiv) - this.mainContentTop;

    // main content full mode divs
    this.menuLeftFullDiv         = YAHOO.util.Dom.get("menuLeftFull");
    this.menuFullDiv             = YAHOO.util.Dom.get("menuFull");
    this.endMenuFullDiv          = YAHOO.util.Dom.get("endMenuFull");
    this.mainContentFullDiv      = YAHOO.util.Dom.get("mainContentFull");
    this.belowMainContentFullDiv = YAHOO.util.Dom.get("belowMainContentFull");
    this.rightContentFullDiv     = YAHOO.util.Dom.get("rightContentFull");

    this.leftToRemove   = YAHOO.util.Dom.get("leftToRemove");
    this.middleToRemove = YAHOO.util.Dom.get("middleToRemove");
    this.rightToRemove  = YAHOO.util.Dom.get("rightToRemove");

    // marker to activate full width mode
    this.mainContentFullwidthDiv = YAHOO.util.Dom.get("mainContentFullwidth");

    // main content sizer
    this.mainContentSizer = YAHOO.util.Dom.get("mainContentSizer");

    // photo content div photo image img tag
    this.photoImage       = YAHOO.util.Dom.get("photoImage");

    // photo content div photo image med-blue box 
    this.photoImageBox    = YAHOO.util.Dom.get("photoImageBox");

    // slideshow content div slideshow images img tags
    this.slideshowImage0  = YAHOO.util.Dom.get("slideshowImage0");
    this.slideshowImage1  = YAHOO.util.Dom.get("slideshowImage1");

    // slideshow content div photo image med-blue box 
    this.slideshowImageBox = YAHOO.util.Dom.get("slideshowImageBox");

    // photo right container
    this.photoRightDiv     = YAHOO.util.Dom.get("photoRight");

    // photo right sub-boxes
    this.photoRightBarDiv  = YAHOO.util.Dom.get("photoRightBar");
    this.photoRightBoxDiv  = YAHOO.util.Dom.get("photoRightBox");
    this.photoRightTextDiv = YAHOO.util.Dom.get("photoRightText");

    // bottom right content div and sizer img
    this.bottomRightDiv      = YAHOO.util.Dom.get("bottomRightContent");
    this.bottomRightTop      = YAHOO.util.Dom.getY(this.bottomRightDiv);
    this.belowBottomRightDiv = YAHOO.util.Dom.get("belowBottomRight");
    this.bottomRightSizer    = YAHOO.util.Dom.get("bottomRightSizer");
    this.bottomRightHeight   = YAHOO.util.Dom.getY(this.belowBottomRightDiv) - this.bottomRightTop;

    this.getMax = function(a, b)
    {
        if ( a > b )
            return a;
        else
            return b;
    }

    this.getMax3 = function(a, b, c)
    {
        return( this.getMax(a, this.getMax(b,c) ) );
    }

    this.getMax4 = function(a, b, c, d)
    {
        return( this.getMax( this.getMax(a,b),this.getMax(c,d) ) );
    }

    this.maxHeight =
        this.getMax3(24, this.mainContentHeight, this.bottomRightHeight);

    this.maxHeightWithMenu =
        this.getMax4(24, this.menuHeight, this.mainContentHeight, this.bottomRightHeight);
    
    this.setTop = function(element, pos)
    {
        YAHOO.util.Dom.setY(element, pos);
    };

    this.setHeight = function(element, height)
    {
        YAHOO.util.Dom.setStyle(element, "height", height);
    };

    this.arrange = function(element, pos, height)
    {
        YAHOO.util.Dom.setY(element, pos);
        YAHOO.util.Dom.setStyle(element, "height", height);
    };

    this.transferContent = function(toElement, fromElement)
    {
        var content = fromElement.innerHTML;
        fromElement.innerHTML = "";
        toElement.innerHTML = content;
    }

    this.clearContent = function(toElement, fromElement)
    {
        fromElement.innerHTML = "";
        YAHOO.util.Dom.setStyle(fromElement, "height", "0px");
        YAHOO.util.Dom.setStyle(fromElement, "visibility", "hidden");
        YAHOO.util.Dom.setStyle(toElement, "visibility", "visible");
    };

    this.clearSection = function(element)
    {
        element.innerHTML = "";
        YAHOO.util.Dom.setStyle(element, "height", "0px");
        YAHOO.util.Dom.setStyle(element, "visibility", "hidden");
        YAHOO.util.Dom.setStyle(element, "overflow", "hidden");
    };

    this.arrangeFullWidthContent = function(pos, height)
    {
        this.transferContent(this.menuFullDiv,  this.menuDiv);
        this.transferContent(this.endMenuFullDiv,  this.endMenuDiv);
        this.transferContent(this.mainContentFullDiv,  this.mainContentDiv);
        this.transferContent(this.belowMainContentFullDiv,  this.belowMainContentDiv); 

        this.clearContent(this.menuLeftFullDiv,         this.menuLeftDiv);
        this.clearContent(this.menuFullDiv,             this.menuDiv);
        this.clearContent(this.endMenuFullDiv,          this.endMenuDiv);
        this.clearContent(this.mainContentFullDiv,      this.mainContentDiv);
        this.clearContent(this.belowMainContentFullDiv, this.belowMainContentDiv);
        this.clearContent(this.rightContentFullDiv,     this.bottomRightDiv);

        //this.arrange(this.menuLeftFullDiv, this.contentTop+48, this.menuHeight);
        this.arrange(this.menuLeftFullDiv, this.menuTop, this.menuHeight);

        this.setTop(this.mainFullContentDiv, pos);
        this.setHeight(this.mainContentSizer, height);
        this.setTop(this.belowMainContentDiv, pos+height+1);

        // now remove all the space-takers.
        this.leftToRemove.parentNode.removeChild(this.leftToRemove);
        this.middleToRemove.parentNode.removeChild(this.middleToRemove);
        this.rightToRemove.parentNode.removeChild(this.rightToRemove);
        this.menuLeftDiv.parentNode.removeChild(this.menuLeftDiv);
    };

    this.arrangeMainContent = function(pos, height)
    {
        this.setTop(this.mainContentDiv, pos);
        this.setHeight(this.mainContentSizer, height);
        this.setTop(this.belowMainContentDiv, pos+height+1);
    };

    this.arrangeBottomFull = function(pos, height)
    {
        // noop for now.
        //this.setTop(this.bottomRightDiv, pos);
        this.setHeight(this.rightFullContentDiv, height);
    };

    this.arrangeBottomRight = function(pos, height)
    {
        this.setTop(this.bottomRightDiv, pos);
        this.setHeight(this.bottomRightSizer, height);
    };
}


function getDivs()
{
    return new divs();
}

