/**
 * Hides text after <br class="read-more" /> and replaces the BR element with
 * the read-more link, which shows the hidden text when clicked.
 */

/*jslint white: true, onevar: true, browser: true, undef: true, nomen: false, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */
/*global jQuery, $, window*/
"use strict";

$(function () {
    $(".collapsing br.read-more").each(function (i) {
        var span, link;
        span = $(this).nextAll().wrapAll($('<span/>')
            // .addClass('hidden')
            .hide()
            .addClass('continue')
        ).parent();
        link = $('<a/>')
            .attr('title', 'Näytä koko teksti')
            .addClass('read-more')
            .text('Lue lisää…')
            .click(function () {
                link.remove();
                // span.removeClass('hidden');
                span.slideDown('fast');
                return false;
            })
            ;
        $(this).replaceWith(link);
    });
    $("br.read-more").remove();
});
