/**
 * Functions for doing DOM animations
 */

TOOLBOX.Animate = {}; // Namespace

TOOLBOX.Animate.reveal = function(element,config)
{
    config = TOOLBOX.mergeConfig(config,{
    });
    element = YAHOO.util.Dom.get(element);
    if (element!=null && element.style.display=='none') {
        if (!element.animInit) {
            TOOLBOX.Animate.initElement(element);
        }
        var showAnimation = new YAHOO.util.Anim(
                element,
                {height: {to: element.origHeight}},
                0.3
            );
        element.style.overflow = 'hidden';
        element.style.height = "0px";
        element.style.display = "";
        return showAnimation;
    }
};

TOOLBOX.Animate.conceal = function(element, config)
{
    config = TOOLBOX.mergeConfig(config,{
    });
    element = YAHOO.util.Dom.get(element);
    if (element!=null) {
        if (!element.animInit) {
            TOOLBOX.Animate.initElement(element);
        }
        var hideAnimation = new YAHOO.util.Anim(element,
                                                {height: {to: 0}},
                                                0.3,
                                                YAHOO.util.Easing.easeIn);
        hideAnimation.onComplete.subscribe(function(){this.style.display='none';},this,true);
        element.style.overflow = 'hidden';
        element.style.display = 'block';
        element.style.height = element.origHeight;
        return hideAnimation;
    }
};

TOOLBOX.Animate.initElement = function(element)
{
    // store the elements original display properties
    element.origPos = element.style.position;
    element.origVis = element.style.visibility;
    element.origDisplay = element.style.display;
    element.origOverflow = element.style.overflow;
    element.origClass = YAHOO.util.Dom.getAttribute(element,'class');

    // hide the element to grab out it's height and width
    element.style.position = 'absolute';
    element.style.visbility = 'hidden';
    element.style.display = 'block';
    element.style.overflow = 'hidden';

    element.origHeight = (YAHOO.util.Dom.getRegion(element).height);
    element.origWidth  = (YAHOO.util.Dom.getRegion(element).width);

    // reset the element
    element.style.position = element.origPos;
    element.style.visibility = element.origVis;
    element.style.display = element.origDisplay;
    element.style.overflow = element.origOverflow;

    element.animInit = true; // set as init-ed
};
