﻿//<![CDATA[
// tests, if an element exists in given array

// make a post visible - show post url and title
function showPosts(root)
{
    for (var i = 0; i < recentPostsCnt; i++)
    {
        var feed = root.feed;
        var entries = feed.entry || [];
        var entry = feed.entry[i];
        
        for(var j=0; j<entry.link.length; j++) 
        {
            if (entry.link[j].rel == 'alternate') 
            {
                // get url of a post
                url = entry.link[j].href;

                temp_pos = url.indexOf("/", 8);
                block_name = url.substr(0, temp_pos);
                
                if (document.getElementById(block_name) == null)
                {
                    str_tag_ul = '<ul id="' + block_name + '"></ul>';                
                    if (donate) str_tag_ul = str_tag_ul + '<p style="margin-left:14;font-size:10px"><a href="http://ametov.net">Ametov.net</a></p>';
                    document.write(str_tag_ul);
                }

                // get title of a post
                title = entry.link[j].title;
                
                // if there is no title replace it with url
                if (title == '') title = url;
                
                titleData = document.createTextNode(title);
                tag_a = document.createElement('a');
                tag_a.href = url;
                tag_li = document.createElement('li');
                tag_a.appendChild(titleData);
                tag_li.appendChild(tag_a);
                document.getElementById(block_name).appendChild(tag_li);
            }
        }
    }
}

// get info as json string for given post
function getPosts()
{
    script = document.createElement('script');
    script.src = blog_url + '/feeds/posts/summary?&max-results='+recentPostsCnt+'&alt=json-in-script&callback=showPosts';
    script.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(script);
}

function showRecentPosts()
{    
    length_blog_url = blog_url.length;
    if (blog_url.lastIndexOf('/') == length_blog_url-1) blog_url = blog_url.substr(0,length_blog_url-1);
    if (blog_url.indexOf('http://') == -1) blog_url = 'http://' + blog_url;
    
    str_tag_ul = '<ul id="' + blog_url + '"></ul>';                
    if (donate) str_tag_ul = str_tag_ul + '<p style="margin-left:14;font-size:10px"><a href="http://ametov.net">Ametov.net</a></p>';
    document.write(str_tag_ul);
    
    getPosts();    
}
//]]>