(function(){

var isDomReady = false;

$(function(){isDomReady = true;})

$.ajax({
    url : '/renewal/data/recentposts.xml',
    dataType : 'xml',
    success : function(data, status, xhr)
    {
        var $posts = $('post',data),
            postLength = $posts.length,
            $postObj = $('post:eq(' + Math.floor(postLength * Math.random()) + ')', data),
            setPost = function()
            {
                $('#PostImage').attr({'src' : $postObj.children('image').text()});
                $('#PostAuthor').text($postObj.children('author').text());
                $('#PostCat').text($postObj.children('cat').text());
                $('#PostTitle').text($postObj.children('title').text());
                $('#PostBody').html($postObj.children('body').text());
                $('#PostUrl').attr({'href' : $postObj.children('url').text()});
            };
        if(isDomReady){
            setPost();
        }
        else
        {
            $(setPost);
        }
    },
    error : function(xhr, status, error)
    {
        
    },
    complete : function(xhr, status)
    {
    }
});

})();