(function($){
  
  Application = {
    
    tabCitation:[],
    currentCitation:0,
    intervalCitation:7000,
    
    init : function(){
      this.initEvtCalendar();
      this.initFbButtons();
      this.initCitationAnimation();
    },
    
    
    
    /*
     * 
     * citation du slider
     * 
     */
    initCitationAnimation: function(){
      this.tabCitation = [];
      var self = this;
      $('.citation').each(function(index, elt){
        self.tabCitation.push(elt);
      });
      
      if(this.tabCitation.length){
        this.startCitationAnimation();
      }
    },
    
    
    startCitationAnimation: function(){
      var self = this;
      var oldCitation = self.currentCitation;
      
      this.timeoutId = setTimeout(function(){
        self.currentCitation++;
        if(self.tabCitation.length <= self.currentCitation){
          self.currentCitation = 0;
        }
        $(self.tabCitation[oldCitation]).fadeOut(750, function(){
          $(self.tabCitation[self.currentCitation]).fadeIn(750, function(){
            self.startCitationAnimation.call(self);
          });
        });
      }, this.intervalCitation);
      
    },
    
    
    
    /*
     * 
     * les boutons fb (20/10/2011 plus utilisé)
     * 
     */
    initFbButtons : function(){
      
      $('a.fb').each(function(index, elt){ 
        $(this).click(function(evt){
          evt.preventDefault();
          FB.ui(
            {
              method: 'feed',
              name: 'Facebook Dialogs',
              link: 'http://www.charlesdelaverpilliere.com/',
              picture: 'http://fbrell.com/f8.jpg',
              caption: 'Charles de la Verpilliere',
              description: 'Je partage.'
            },
            function(response) {
              if (response && response.post_id) {
//
              } else {
  //
              }
            }
          );

          
        });
      });
    },
    
    
    /*
     * 
     * gestion du calendrier
     * 
     */
    initEvtCalendar : function(){
      if($('#content_agenda').length){
        var gCalendar = new EventCalendar();
      }
    }
    
    
  };
  
})(jQuery);

jQuery(document).ready(function(){
  Application.init();
});
