// JavaScript Document

jQuery(function($){

$.getJSON("http://australianetworkblogs.com/pacificpulse/?json=get_recent_posts?&count=100&custom_fields=video_hi_url&callback=?", function(data){

$("#loading").css({"display":"none"});

$.each(data.posts, function(i,item){

function yourStories() {
var this_story = '<div class="yourstory">';
var this_image = item.attachments[0].images.thumbnail.url;
var this_video = item.custom_fields.video_hi_url;
this_story += '<h2><img src="http://australianetwork.com/pacificpulse/img/user_user-generated.jpg" alt="User Generated" title="User Generated" /> <a href="'+item.url+'" title="'+item.title+'">'+item.title+'</a></h2>';
if (this_image != '') {

//if(this_video != '') {
//this_story += '<p class="thumbnail"><div style="position:relative; width:140px; height:79px;"><a href="'+item.url+'" rel="bookmark" title="Permanent Link to '+item.title+'"><img title="'+item.title+'" src="'+this_image+'" alt="'+item.title+'" class="size-thumbnail" /></a><div style="position:absolute; top:24px; left:49px; width:42px; height:31px;"><a href="'+item.url+'" rel="bookmark" title="Permanent Link to '+item.title+'"><img src="http://australianetwork.com/img/icons/icon_video_play_small.png" alt="'+item.title+'" title="'+item.title+'" /></a></div></div></p>';
//}
//else {
this_story += '<p class="thumbnail"><img title="'+item.title+'" src="'+this_image+'" alt="'+item.title+'" class="size-thumbnail" /></p>';
//}
}
this_story += '<p class="date">Posted by '+item.excerpt+'</p>';
this_story += item.content;
this_story += '<p><a href="'+item.url+'" rel="bookmark" title="Permanent Link to '+item.title+'">Read more &gt;</a></p>';
this_story += '</div>';
$(this_story).appendTo("#write-yourstory");
}

function yourStoriesMore() {
$("<p/>").html('<a href="'+item.url+'">'+item.title+'</a>').appendTo("#write-yourstory-more");
}

if (i < 2) {yourStories(); $(".more-link").remove();}
if (i < 5 && i > 1) {yourStoriesMore();}

$.each(item.comments, function(i,item_comment){
if(item.comment_status == "open") {
$("<p/>").html('Comment by: <a href="'+item.url+'#comments">'+item_comment.name+'</a>'+item_comment.content).appendTo("#write-yourstory-comments");
}
});

});								
});
});
