/**
 * Copyright (C) 2007 Ramiro G�mez - www.seo-expert-blog.com
 */

/* global variables */
var descList = new Array();
var itemList = "";
$(document).ready(function() { 
 var content = "";
  $.getJSON("pipes.php",
   function(json){
     if(json.count > 0) {
       content = output_feed_items(json);
	   } else {
       content = "The request did not return results.";
     }
     $("#pipes-feed-content").html(content);

   }
  );
});

function output_feed_items(json) {
  document.title = json.value.title;
  var heading = '<h3>' + json.value.title + '</h3>';
  var total_count=json.count;
   if(total_count>10){
  total_count=8;
  }else{
  total_count=json.count;
  }
  for(j=0;j<total_count;j++){
  for (i=0;i<total_count;i++) {
    itemList += make_feed_item(json.value.items[i], i);
    descList.push(make_feed_desc(json.value.items[i], i));
	  }  
	  }
	// return heading + itemList;
	  return itemList;

}

function make_feed_item(item, item_id) {
  return  '<div><a style="font:14px Trebuchet MS; color: #51656E; text-decoration=underline; cursor:pointer;" "href="#heading-' + item_id +
      '" onclick="toggle_feed_desc(' + item_id + ');">' +
      item.title + '</a><br/>'+item.description+'</div><br/>';
}

function make_feed_desc(item, item_id) {
   var desc_info = '<span="item-submitted">Published: ' +
    item.pubDate + '</span>';
  desc_info += ' - <a href="' + item.link + '">Link to Article</a>';
  var desc_info = '<div class="item-info">' + desc_info + '</div>';
  return  item.link ;
}

function toggle_feed_desc(item_id) {
 var heading = '#heading-' + item_id;
 var item_div = 'div#desc-' + item_id;
 if ($(item_div).html()) {
    $(item_div).remove();
  } else {
window.open(descList[item_id], "myWindow", "status = 1, height = 300, width = 300, resizable = 1,scrollbars=yes" );
  }
}
