/*
 * Builti-in section folding for MoniWiki
 * 
 * $Id: folding.js,v 1.4 2009/01/02 16:38:23 wkpark Exp $
 */

function foldingSection(btn, id)
{
    var sect;
    if (typeof id == 'object') sect = id;
    else sect=document.getElementById(id);
    if (!sect) return;
    var toggle = true;
    if (sect.style.display != 'none') {
        toggle = false;
    }

    var icon=null;
    if (btn) {
        icon=btn.getElementsByTagName('img')[0];
        if (!icon) {
            icon = new Image();
            icon.src = _url_prefix + '/imgs/misc/open.png';
            btn.insertBefore(icon, btn.firstChild);
            //btn.appendChild(icon);
        }
    }

    if (typeof Effect != 'undefined') { // prototype.js
        var dur = 0.5;
        if (toggle) {
          new Effect.SlideDown(sect, { duration: dur, afterFinish: function() {Element.show(sect);} });
        } else {
          new Effect.SlideUp(sect, { duration: dur, afterFinish: function() {Element.hide(sect);} });
        }
    } else if (typeof MooTools != 'undefined') { // get sectpages for the first time.
        var mySlide = new Fx.Slide(sect); // mootools
        mySlide.toggle();
    } else {
        if (sect.style.display == 'none') {
            sect.style.display = 'block';
        } else {
            sect.style.display = 'none';
        }
    }
    if (icon) {
        var name=icon.getAttribute('class');
        if (name == 'close') {
            icon.src = _url_prefix + '/imgs/misc/close.png';
            icon.setAttribute('class','');
        } else {
            icon.src = _url_prefix + '/imgs/misc/open.png';
            icon.setAttribute('class','close');
        }
    }
}

// vim:et:sts=4:sw=4:
