jQuery(document).ready(function() {

  var htmlStatus = $('#ticker .content ul li:nth(0)').html();
  var textStatus = $('#ticker .content ul li:nth(0)').text();
  var done = false;

  // showing stars
  $('#ticker .content ul.ticker_content').bxSlider({
    auto:         true,
    nextImage:    '/images/theme/ticker/next.png',
    prevImage:    '/images/theme/ticker/prev.png',
    randomStart:  false,
    infiniteLoop: true,
    autoHover:    true,
    speed:        1000,
    pause:        5000,

    onNextSlide: function(currentSlide, totalSlides) {
      if($('#ticker .content ul li:nth(' + (currentSlide + 1) + ')').text().length > 0) {
        htmlStatus = $('#ticker .content ul li:nth(' + (currentSlide + 1) + ')').html();
        textStatus = $('#ticker .content ul li:nth(' + (currentSlide + 1) + ')').text();
      }
    },

    onPrevSlide: function(currentSlide, totalSlides) {
      if($('#ticker .content ul li:nth(' + (currentSlide + 1) + ')').text().length > 0) {
        htmlStatus = $('#ticker .content ul li:nth(' + (currentSlide + 1) + ')').html();
        textStatus = $('#ticker .content ul li:nth(' + (currentSlide + 1) + ')').text();
      }
    }
  });

  $('#ticker .bx-prev, #ticker .bx-next').appendTo("#ticker .controls");
  
  $('#ticker .facebook_share').click(function(item){
    FB.init({ appId:'110631315690268', cookie:true, status:true, xfbml:true });
    FB.ui({
      method:       'feed',
      name:         'Fourmilia - la communauté grouillante',
      link:         'http://www.fourmilia.net',
      caption:      'Les nouvelles de Fourmilia !',
      description:  textStatus
    });

    return false;
  });


  $('#ticker .twitter_share').click(function(item){
    var width  = 575,
        height = 400,
        left   = ($(window).width()  - width)  / 2,
        top    = ($(window).height() - height) / 2,
        url    = (this.href.replace('____status____', textStatus) + '\n\r'),
        opts   = 'status=1' +
                 ',width='  + width   +
                 ',height=' + height  +
                 ',top='    + top     +
                 ',left='   + left;
    
    window.open(url, 'twitter', opts);
 
    return false;
  });
});

