﻿function recentpostscalendar(json) 
{
    for (var i = 0; i < json.feed.entry.length; i++)
    {
        for (var j = 0; j < json.feed.entry[i].link.length; j++) 
        {
            if (json.feed.entry[i].link[j].rel == 'alternate') 
            {
                break;
           }
      
        }

        var entry = json.feed.entry[i];

        var thumburl;
        try 
        {
            thumburl=entry.media$thumbnail.url;
        }
        catch (error)
        {
            if ("content" in entry) {
                s = entry.content.$t;
            }
            else if ("summary" in entry) {
                s = entry.summary.$t;
            }
            else {
                s = "";
            }
            a = s.indexOf("<img");
            b = s.indexOf("src=\"", a);
            c = s.indexOf("\"", b + 5);
            d = s.substr(b + 5, c - b - 5);
            if ((a != -1) && (b != -1) && (c != -1) && (d != "")) { thumburl = d; } else thumburl = 'http://lh3.ggpht.com/_sS1Q7guTuCw/TO-xB-FcO_I/AAAAAAAAAh0/6y_91wP4vbU/blank.png';
        }


        var entryUrl = "'" + json.feed.entry[i].link[j].href + "'";
        var entryTitle = json.feed.entry[i].title.$t;


        if (entryTitle.length >= 37) {
            entryTitle = entryTitle.substring(0, 37)+"...";
            //var quoteEnd = entryTitle.lastIndexOf(" ");
            //entryTitle = entryTitle.substring(0, quoteEnd) + "...";
        }

        var item = entryTitle;
        var image = "<a href=" + entryUrl + "><img src=\"" + thumburl + "\" width=\"46\"/></a>";

        if ("content" in entry) {
            var postcontent = entry.content.$t;
        }
        else if ("summary" in entry) {
            var postcontent = entry.summary.$t;
        }
        else {
            var postcontent = "";
        }
        
        if (postcontent.length >= 70) {
            postcontent = postcontent.substring(0, 70);
            var quoteEnd = postcontent.lastIndexOf(" ");
            postcontent = postcontent.substring(0, quoteEnd) + "...";
        }

        postcontent = json.feed.entry[i]['gd$when'][0].startTime + " - " + json.feed.entry[i]['gd$where'][0].valueString;

        var link = "<a href=" + entryUrl + "><small>tovább...</small></a>";

        document.write("<div style=\"border-bottom-width:1px; border-bottom-style:solid; border-color:#CCCCCC; overflow:hidden; margin-bottom:6px;\">");

        document.write("<div style=\"float:left;width:254px;font-family:Verdana;font-size:11px;font-weight:normal;\">" + item + "<br/><span style=\"font-family:sans-serif;font-size:11px;font-weight:normal;\">" + postcontent + "</span></div>");

        //document.write("<div style=\"float:right;width:46px\">" + image + "</div>");
        document.write("</div>");

    }
}
