// Function used to show/hide information with slide.
// The 'toggle' button must have class='js_toggle'
// and id='X', where 'X' is the class of the element to show/hide.
//
// EXAMPLE:
//
// <span id='slide_x' class='js_toggle'>click me</span>
// ...
// <div class='slide_x'> ... </div>
//
$('.js_toggle').click(function(){
    $('.'+$(this).attr('id')).slideToggle('slow');
})

// Function to hide mailt links form bots, crawlers, sniffers, etc.
// by adding '@igc.gulbenkian.pt' when the user clicks the mailto link
// to the href
//
// USAGE:
//      <a href='name' class='mailto'>name</a>
//  will open a mail to: name@igc.gulbenkian.pt
//
$(function () {
$('.mailto').click(function() {
        var atigc = '@igc.gulbenkian.pt';
        var name = $(this).attr('name');
        $(this).attr('href','mailto:'+name+atigc);
    })
})

function tick () {
    if (document.getElementById ('time')) {
        if (document.getElementById ('time').firstChild.data > 1) {
            document.getElementById ('time').firstChild.data = document.getElementById ('time').firstChild.data - 1
            setTimeout ('tick()', 1000)
        }
    }}
    if (document.getElementById) onload = function () {
        tick()
    }


// returns a 4 element array where each
// value is the sum of padding, morder and margin
// for [top,bottom,left,right].
// uses the JSize plugin
function pb (elem) {
    t = elem.padding().top + elem.border().top;
    b = elem.padding().bottom + elem.border().bottom;
    r = elem.padding().right + elem.border().right;
    l = elem.padding().left + elem.border().left;
    return [t,b,r,l];
}

// set the height of left and right panels equal
//
$(window).bind('load',
    function () {
    if ($(".panel_left.a").length) {
        // special case for rabifier output, with two panels on the left
        var rh = $(".panel_right").outerHeight();
        var lhab = $(".panel_left.a").outerHeight() + $(".panel_left.b").outerHeight() + pb($(".panel_left.a"))[1] + pb($(".panel_left.b"))[0];
        if (lhab > rh) {
            var newh = $(".panel_left.a").outerHeight() + $(".panel_left.b").outerHeight() + $(".panel_left.a").margin().bottom + $(".panel_left.b").margin().top - pb($(".panel_right"))[0] - pb($(".panel_right"))[1];
            $(".panel_right").height(newh);
        } else {
            var newh = $(".panel_right").outerHeight() - $(".panel_left.a").outerHeight() - $(".panel_left.a").margin().bottom - $(".panel_left.b").margin().top - pb($(".panel_left.b"))[0] - pb($(".panel_left.b"))[1];
            $(".panel_left.b").height(newh);
        };
    }

    if ($(".panel_left:not(.a,.b)").length) {
        var lh = $(".panel_left").height();
        var rh = $(".panel_right").height();
        if (lh > rh) {
            $(".panel_right").height(lh);
        } else {
            $(".panel_left").height(rh);
        };
    }

    // show all elements
    $("#menu").css({visibility:'visible',display:'none'});
    $("#menu").fadeIn(1000);
    $("#footer").css({visibility:'visible',display:'none'});
    $("#footer").fadeIn(1000);
    $("#content").css({visibility:'visible',display:'none'});
    $("#content").fadeIn(800);
});



