var check = 0;
var feature = 0;

$(document).ready(function () {
    if (featuredFeed) {
        loadFeed(featuredFeed);
    }
    else {
        check = 1;
        loadFeed(entryFeed);
    }
});



function loadFeed(url) {
    var DataFiles = [url]
    $(DataFiles).each(function (index) {
        var fileref = document.createElement('script');
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", this.toString());
        document.getElementsByTagName("head")[0].appendChild(fileref);
    })
}


function psRenderBlogs(obj) {
    if (check == 0) {
        var container = $('#latestPosts');
        var elcount = 0;
        var elstart = 0;
        $(obj.blogs).each(function (el) {
            if (this.post == "") {
                if (el == elstart) {
                    elstart += 1;
                    elcount += 1;
                    return;
                } else {
                    elcount += 1;
                    return;
                }
            }
            if (this.hasOwnProperty('post') && (el <= elcount)) {
                var newsBox = ('<div class="newsFeature">');
                var post = this.post;
                var limit = 200;
                var limitedPost = (post.substr(0, limit - 1) + '\
				...\
				<br />');
                var str = '	' + newsBox + '\
				<h3><a href="/news/">' + this.title + '</a></h3>\
		        ' + limitedPost + '\
				</div>';
                container.append(str);
                check = 1;
                feature = 1;
                loadFeed(entryFeed);
            }
        });
    } else if (check == 1) {
        var container = $('#latestPosts');
        var elcount = 3;
        var elstart = 0;
        $(obj.blogs).each(function (el) {
            if (this.post == "") {
                if (el == elstart) {
                    elstart += 1;
                    elcount += 1;
                    return;
                } else {
                    elcount += 1;
                    return;
                }
            }
            if (this.hasOwnProperty('post') && (el <= elcount)) {
                if (feature == 0) {
                    var newsBox = ('<div class="newsFeature">');
                    feature = 1;
                }
                else {
                    var newsBox = ('<div class="newsItm">');
                }
                var post = this.post;
                var limit = 200;
                var limitedPost = (post.substr(0, limit - 1) + '\
				...\
				<br /><a href="' + this.link + '" target="_blank">' + readMore + '</a>');
                var str = '	' + newsBox + '\
				<h3><a href="' + this.link + '" target="_blank">' + this.title + '</a></h3>\
		        <p>' + limitedPost + '</p>\
				</div>';
                container.append(str);
            }
        });
    }
}
