﻿$(function () {

    var fmax = 16;
    var fmin = 8;
    var pmin = -1;
    var pmax = 0;
    var tags = $('#tagCloud > .tag');

    tags.each(function (i) {

        var postCount = $(this).attr('posts');

        if (postCount > pmax) {
            pmax = postCount;
        }

        if (postCount < pmin || pmin == -1) {
            pmin = postCount;
        }
    });

    tags.each(function (i) {

        var pn = $(this).attr('posts');

        $(this).css('font-size', CalculateFontSize(fmin, fmax, pmin, pmax, pn));
        $(this).css('display', 'inline');
    });
});

function CalculateFontSize(fmin, fmax, pmin, pmax, pn) {

    return fmin + (((fmax - fmin) / 100) * ((100 / (pmax - pmin)) * (pn - pmin)));
}
