
/*
 * Library functions.
 */

function baseUrl()
{
    return $('head > meta[name=baseUrl]').attr('content');
}

function reloadCaptcha(captchaType, captchaId)
{
    var now = new Date();
    $('img.captcha#captcha_' + captchaId).each(function() {
        this.src = baseUrl() + '/captcha.php?type=' + captchaType + '&amp;time=' + now.getTime();
    });
}

/*
 * Inline links.
 */
$(document).ready(function() {
    $('a.inline').each(function() {
        var div = null;
        var link = this;
        
        $(link).addClass('inline-link');
        
        function initDiv() {
            div = document.createElement('div');
            div.className = 'inline-content';
            $(link).after(div);
        }
        
        function filterLoadedContent() {
            // e.g. $(div).find('h3:first-child').remove();
            // But nothing for now.
        }
        
        $(this).click(function() {
            if (div == null) {
                initDiv();
                $(div).load(this.href + ' #tekstisolu > *', 'inline-request=1', function() {
                    filterLoadedContent();
                });
            } else {
                $(div).remove();
                div = null;
            }
            return false;
        });
    });
});

/*
 * External links in articles 
 */
$(document).ready(function() {
    $('#artikkeli a').each(function() {
        if (this.href.indexOf(baseUrl()) != 0) {
            this.target = '_blank';
        }
    });
});

