(function() {

  //document ready
  $().ready(function(){
    $("#load-feed").loadFeed(); 
  });

  $.fn.loadFeed = function(cfg) {

    cfg = jQuery.extend({
      url  : "common/include/loadFeed.php"
    },cfg);

    function ajaxGetContent(){
      $.ajax({
        type: "GET",
        url  : cfg.url,
        cache: true,
        dataType: "xml",
        timeout : 3000,
        error   : function() {
          $("#load-feed").append("<p>ERROR - RSS feed を取得できません -</p>");
          return true;
        },
        success : function(data) {
          $("#load-feed").html("<table></table>");
          $("#load-feed").find("table").addClass("feed-tbl");
          displayContent(data);
          return true;
        }
      });
    }

    function displayContent(data){
      var _node = new Object();
      _node["title"]   = new Array();
      _node["link"]    = new Array();
      _node["subject"] = new Array();
      _node["date"]    = new Array();
      setTimeout(function(){
        $("item",data).each(function(i){
          _node["title"][i]   = $("item",data).eq(i).children("title").text();
          _node["link"][i]    = $("item",data).eq(i).children("link").text();
          _node["subject"][i] = $("item",data).eq(i).children("subject").text();
          if(_node["subject"][i] != ""){_node["subject"][i] = "【" + _node["subject"][i] + "】&nbsp;";}
          _node["date"][i]    = $("item",data).eq(i).children("date").text();
          $("table.feed-tbl").append("<tr><th>"+_node["date"][i]+"</th><td><a href=\""+ _node["link"][i] +"\">"+ _node["subject"][i] + _node["title"][i] +"</a></td></tr>");
          $("th,td").css("opacity","0");
          setTimeout(function(){
            $("th").eq(i).fadeTo(500, 1);
            $("td").eq(i).fadeTo(500, 1);
          },750 * (i));
        });
      },1250);
    }

    return ajaxGetContent();

  };
})(jQuery);
