/* facebook.js */
var Facebook = {
  /*
  initialize: function() {
    this.userid = '67930989920';
    this.pageSize = 2;
  },
  */
  
  like:function() {
   //http://www.facebook.com/RockyMountaineerTrain/posts/192096830822370
   //sharethis?
  },
  
  createWidget:function() {
    var fbUrl = SiteVars.path_to_top + '/resources/feeds/facebook.json';
    //var self = this;
    var html = '';
    var i = 0;
    
    $j.getJSON(fbUrl, function(data) {
      facebookJSON = data;


      if (facebookJSON) {
        
      
        
        var i = 0;
        $j.each(facebookJSON.data, function(key, post) {

          if (i >= 2) {
              return;
          }
              
          
          if (post.from.id == '67930989920') {
            
            var link = '';
            
            var date = post.updated_time;
            var date_arr = date.split(/[T\-:\+]/);
            
            var year = date_arr[0];
            var month = parseFloat(date_arr[1]) - 1;
            var day   = date_arr[2];
            var hour  = date_arr[3];
            var min   = date_arr[4];
            var sec   = date_arr[5];
            
            var ampm = hour > 12 ? 'am' : 'pm';
            
            //console.log(pdate);
            // Jan 05 at 9:52pm
            
            var strdate =  SiteVars.modules.phrasePack.months[month] + ' ' + day + ' at ' + hour + ':' + min + ampm;
            var nodesclink = "";
                    
            if (post.link != '') {
              link = '<a href="' + post.link + '" target="_blank">More &raquo;</a>';
              nodesclink = '<a href="' + post.link + '" target="_blank">' + post.link + '</a>';
            }
            
            var msg = typeof post.message != 'undefined' ? post.message : post.description;
            
            if (typeof msg == 'undefined') {
              msg = nodesclink;
            }
            
   
            
            html += '<div class="article"><h4><a href="http://www.facebook.com/RockyMountaineerTrain/" target="_blank">' + post.from.name + '</a>:</h4><p class="message">' + msg.substring(0, 180) + '...' + link +  '</p><p class="time">' + strdate + '</p></div>';
            i++;
          }              
        });
        
  
      }
              
      $j('#facebook-title').html(SiteVars.modules.phrasePack.facebook_title);
      $j('#facebook-widget').html(html);
      $j('#facebook-more').html(SiteVars.modules.phrasePack.facebook_more);
      
      equalFooterHeights();            

        
        
        
    }); 
    
        


    
    
  }
};



