(function () {
    "use strict";

    function featureThis(thisTag, iden) {
        var posts = tumblr_api_read['posts'] || [],
            blogLen = posts.length,
            p = 0;

        while (p < blogLen) {
            var post = posts[p],
                tags = posts[p]['tags'] || [],
                tagsLen = tags.length,
                t = 0;
            while (t < tagsLen) {
                var tag = tags[t] || "";
                if (thisTag === tag) {
                    return (function () {
                        var type = post['type'];
                        switch (type) {
                        case "regular":
                            $('#' + iden).html("<h1 class='med georgia bold italic black'>" + post['regular-title'] + "</h1><br><div>" + post['regular-body'].substr(0, 300) + "...</div><br><a class='bold italic yel georgia' href='" + post['url'] + "' target='_blank'>Read More...</a>");
                            break;
                        case "photo":
                            $('#' + iden).html("<img id='featureImg' src='" + post['photo-url-250'] + "' alt=''><br><div>" + post['photo-caption'].substr(0, 300) + "...</div><br><a class='bold italic yel georgia' href='" + post['url'] + "' target='_blank'>Read More...</a>");
                            break;
                        case "answer":
                            $('#' + iden).html("<h1 class='georgia bold italic black'><span class='med'>Question:<br> </span> " + post['question'] + "</h1><br><p><span class='med bold black italic georgia'>Answer:<br> </span> " + post['answer'].substr(0, 200) + "...</p><br><a class='bold italic yel georgia' href='" + post['url'] + "' target='_blank'>Read More...</a>");
                            break;
                        default:
                            console.log("No instructions for this post type");
                        }
                    }());
                }
                t += 1;
            }
            p += 1;
        }
    }

    featureThis('invite', 'eventFeature');
    featureThis('text', 'textFeature');
    featureThis('photo', 'photoFeature');
    featureThis('QandA', 'QAFeature');

}());

