/* 
Gizmo(QP) Web Framework - http://gizmojo.org/
------------------------------------------------------------------------------
Copyright (C) 2007 Mario Ruggier
License: GNU LGPL, http://www.gnu.org/copyleft/lesser.html
------------------------------------------------------------------------------
$Id: collapsable.js 522 2007-04-09 08:11:14Z mario $ 
*/

// collapsable box

/* Sample generated HTML for a Collapsable : 
<div class="collapsable" id="%(gizmoid)s_box">
    <div class="head" id="%(gizmoid)s_head">
        <table border="0" width="100%">
        <tr class="toggle" onclick="%(gizmoid)s.toggle_expand();">
        <td width="5%">
        <div class="expand" id="%(gizmoid)s_expand">%(icon_expand)s</div> 
        <div class="collapse invisible" id="%(gizmoid)s_collapse">%(icon_collapse)s</div> 
        </td>
        <td class="title" id="%(gizmoid)s_title">%(title)s</td>
        <td class="status" id="%(gizmoid)s_status"></td>
        </tr>
        </table>
    </div>
    <div class="body invisible" id="%(gizmoid)s_body">
        <div class="content" id="c_content">%(contents)s</div>
    </div>
</div>
*/

function Collapsable (gizmoid) {
    this.gizmoid = gizmoid;
    //this.set_event_handler('toggle_expand', this.on_toggle_expand); 
}
Collapsable.prototype = new Gizmo;
Collapsable.prototype.elem_names = ['box', 'head', 'body', 
    'expand', 'collapse', 'title', 'status', 'content'];
Collapsable.prototype.event_handlers = { 'toggle_expand': null };

Collapsable.prototype.onload = function () {
    makeInvisible(this.get_elem('collapse'));
    makeInvisible(this.get_elem('body'));
    makeVisible(this.get_elem('expand'));
};
Collapsable.prototype.toggle_expand = function () {
    if (this.is_expanded()) {
        makeInvisible(this.get_elem('collapse'));
        makeInvisible(this.get_elem('body'));
        makeVisible(this.get_elem('expand'));
    }
    else {
        makeInvisible(this.get_elem('expand'));
        makeVisible(this.get_elem('collapse'));
        makeVisible(this.get_elem('body'));
    }
    this.handle_event('toggle_expand');
};
Collapsable.prototype.is_expanded = function () {
    return isVisible(this.get_elem('collapse'));
};
Collapsable.prototype.set_status_text = function (text) {
    replaceChildNodes(this.get_elem('status'), text); 
};
Collapsable.prototype.on_toggle_expand = function () {};
