$(function() {
	$("input.autofocus").focus();
	toggle();
	removeIfEmpty("#information");
})

function toggle() {
	$(".toggle").each(function(){
        var that = $(this);
        var text = that.html();
        var limit = that.data("toggle-limit") || 1000;
        if (text && text.length > limit) {
            that.after($("<span></span>").toggle(
                function(){ show(that, text, limit); },
                function(){ hide(that, text, limit); }
            ));
            hide(that, text, limit);
        }
    });
}
function hide(that, text, limit) {
	that.html(text.substring(0, limit) + "...");
    that.next("span").text("Visa hela texten");
}
function show(that, text, limit) {
	that.html(text);
	that.next("span").text("Dölj text");
}

function removeIfEmpty(elem) {
	info = $(elem);
	if (info.width() < 20)
		info.css("display", "none");
}
