// ==== handle_minimise_boxes =====================================================================
function handle_minimise_boxes(obj)
{
    // get the object
    var obj = typeof(obj) == 'undefined' ? this : obj;
    if (obj.target) obj = obj.target;
    var parent = obj.parentNode.parentNode;
    
    // check to see if the size is needed to store
    if (!parent.size)
        size = parent.offsetHeight;
    
    // change the class name
    var is_hiding = obj.className == '' ? true : false;
    obj.className = is_hiding ? 'shrunk_box' : '';
    parent.className = is_hiding ? parent.className + ' shrunk_box' : parent.className.substr(0, parent.className.length - 10);
    obj.title = is_hiding ? 'Maximise box' : 'Minimise box';
    
    // get the child info
    var child = obj.parentNode.parentNode.firstChild;
    
    // hide the minimised box
    while(child != null)
    {
        if (child.nodeName.toLowerCase() != 'h2' && typeof(child.style) != 'undefined')
            child.style.display = is_hiding ? 'none' : 'block';
        child = child.nextSibling;
    }
    
    // write the cookie
    write_cookie(obj.id, is_hiding ? 'true' : 'false');
}

// ==== setup_minimise_boxes ======================================================================
function setup_minimise_boxes()
{
    // get the boxes
    var boxes = new Array();
    var h2s = document.getElementsByTagName('h2');
    for (var i = 0; i < h2s.length; i ++)
        if (h2s[i].firstChild.nodeName.toLowerCase() == 'span' && (h2s[i].firstChild.title == 'Minimise box' || h2s[i].firstChild.title == 'Maximise box'))
            boxes.push(h2s[i].firstChild);
    
    // set up the boxes for clicking
    for (var i = 0; i < boxes.length; i ++)
        boxes[i].onclick = handle_minimise_boxes;
}

// ==== reload_boxes ==============================================================================
function reload_boxes()
{
    // get the pairs from the cookie
    var pairs = read_cookie();
    
    // loop through the pairs to hide the given boxes
    for (var data in pairs)
    {
        var obj = document.getElementById(data);
        if (obj != null && pairs[data] == 'true')
            handle_minimise_boxes(obj);
    }
}

// init boxes
setup_minimise_boxes();
reload_boxes();