$(document).ready(function() {

    // set jquery marker for css tricks

    $('html').addClass('jq');

    // mobile browser?

    if ($.browser.mobile) {
        $('html').addClass('mobile');
    }

    // attach fancybox

    $('a[rel^="lightbox"]').fancybox({
        'overlayColor': '#222',
        'overlayOpacity': 0.9,
        'titlePosition' : 'inside'
    });

    // adjust height of frontpage teasers

    $('.teaserline .blockitem').each(function(index) {
        $(this).css('height',($(this).parent().attr('clientHeight')-20) + 'px');
    });

    // spam protection

    $('span.tacitum').each(function(index) {
        var a = $(this).text().replace(/\s\[dot\]\s/g,".").replace(/\s\[at\]\s/g,"@");
        $(this).replaceWith('<a class="email" href="m' + 'ailto:' + a + '">' + a + '</a>');
    })

    // add mail icon to all mailto: links

    $('a[href^="mailto:"]').addClass('email');

    // add link icon to all http: links, add/modify target. handle exception for linked images

    $('a[href^="http"]:not([target])').addClass('external').attr('target','external');
    $('a.external').has('img').removeClass('external');
    $('a#player').removeClass('external').attr('title','Video').removeAttr('target');

    // add title attribute to links, if not present

    $('a[href^="http"]:not([title])').each(function(index) {
        $(this).attr('title', $(this).attr('href'));
    })

    // adjust column widths if content-sidebar is present

    $('#content-sidebar').each(function(index) {
        $('.mr40').removeClass('mr40').addClass('mr20');
        $('#content-sidebar').css('margin-right','-170px');
        $('#maincontent .attribute-description').css('margin-right','150px');
        $('#maincontent .attribute-pdf_file').css('margin-right','150px');
        $('#maincontent .content-view-children').css('margin-right','-20px');
    });

});


