document.observe("dom:loaded", function() {

$('content').setStyle({ minHeight: $('sidebar').getHeight() + 'px' });
if (document.viewport.getHeight() < ($('sidebar').getHeight() + $('footer').getHeight()))
{
    $('sidebar').setStyle({ position: 'absolute' });

}
else
{
    $('sidebar').setStyle({ position: 'fixed' });
}

window.onresize = function()
{
    if (document.viewport.getHeight() < ($('sidebar').getHeight() + $('footer').getHeight()))
    {
        $('sidebar').setStyle({ position: 'absolute' });

    }
    else
    {
        $('sidebar').setStyle({ position: 'fixed' });
    }
};

$$('#content img').each(function (s) {
    s.setStyle({ 'display' : 'inline' });
});

snext = function(id)
{
    lis = $(id).childElements()
    lis.each(function(s, index) {
        if ('none' != s.getStyle('display'))
        {
            $(id).setStyle({ height: s.getHeight() + 'px' });
            Effect.Fade(
                s,
                {
                    duration: 0.1,
                    afterFinish: function()
                    {
                        if (s.next())
                        {
                            $(id).setStyle({ height: s.next().getHeight() + 'px' });
                            Effect.Appear(s.next(), { duration: 0.1 });
                            $(id + '_cntr').update(index + 2);

                        }
                        else
                        {
                            $(id).setStyle({ height: lis[0].getHeight() + 'px' });
                            Effect.Appear(lis[0], { duration: 0.1 });
                            $(id + '_cntr').update('1');
                        }
                    }
                }
            );
            throw $break;
        }
        return;
    });
}

sprev = function(id)
{
    lis = $(id).childElements()
    lis.each(function(s, index) {
        if ('none' != s.getStyle('display'))
        {
            $(id).setStyle({ height: s.getHeight() + 'px' });
            Effect.Fade(
                s,
                {
                    duration: 0.1,
                    afterFinish: function()
                    {
                        if (s.previous())
                        {
                            $(id).setStyle({ height: s.previous().getHeight() + 'px' });
                            Effect.Appear(s.previous(), { duration: 0.1 });
                            $(id + '_cntr').update(index);
                        }
                        else
                        {
                            $(id).setStyle({ height: lis[lis.length - 1].getHeight() + 'px' });
                            Effect.Appear(lis[lis.length - 1], { duration: 0.1 });
                            $(id + '_cntr').update(lis.length);
                        }
                    }
                }
            );
            throw $break;
        }
        return;
    });
}

});
