/*$(document).ready(function () {
  var clickHandler = function (link) {
    $('.vedette').hide();
    $('#vedette' + link.data.id).show();
    $('.selectedTab').removeClass('selectedTab');
    $(this).parent().attr('class','selectedTab');
  }

  $('#link1').bind('click', {id:'1'}, clickHandler);
  $('#link2').bind('click', {id:'2'}, clickHandler);
  $('#link3').bind('click', {id:'3'}, clickHandler);
})*/
  
  
/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate: 2007-05-29 11:31:36 +0100 (Tue, 29 May 2007) $
 * $Rev: 2005 $
 *
 */
 
(function($) {
/*
 * A basic news ticker.
 *
 * @name     newsticker (or newsTicker)
 * @param    delay      Delay (in milliseconds) between iterations. Default 4 seconds (4000ms)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("#news").newsticker(); // or $("#news").newsTicker(5000);
 *
 */
$.fn.newsTicker = $.fn.newsticker = function(delay)
{
  delay = delay || 8000;
  initTicker = function(el)
  {
    stopTicker(el);
    el.items = $("div.headline", el);
    // hide all items (except first one)
    el.items.not(":eq(0)").hide().end();
    // current item
    el.currentitem = 0;

    /*$('#link1').bind('click', {goTo(el, 1)});
    $('#link2').bind('click', {goTo(el, 2)});
    $('#link3').bind('click', {goTo(el, 3)});*/
    $('#link1').bind('click', function() {
      goTo(el, '0');
    });
    $('#link2').bind('click', function() {
      goTo(el, '1');
    });
    $('#link3').bind('click', function() {
      goTo(el, '2');
    });

    
    startTicker(el);
  };
  startTicker = function(el)
  {
    el.tickfn = setInterval(function() { doTick(el) }, delay)
  };
  stopTicker = function(el)
  {
    clearInterval(el.tickfn);
  };
  pauseTicker = function(el)
  {
    el.pause = true;
  };
  resumeTicker = function(el)
  {
    el.pause = false;
  };
  doTick = function(el)
  {
    // don't run if paused
    if(el.pause) return;
    // pause until animation has finished
    el.pause = true;
    // hide current item
    $('.selected').removeClass('selected');
    $(el.items[el.currentitem]).fadeOut("slow",
      function()
      {
        $(this).hide();
        // move to next item and show
        el.currentitem = ++el.currentitem % (el.items.size());
        var linkList = $("#headlinePager li");
        $(linkList[el.currentitem]).attr('class','selected');
        $(el.items[el.currentitem]).fadeIn("slow",
          function()
          {
            el.pause = false;
          }
        );
      }
    );
  };
  this.each(
    function()
    {
      if(this.nodeName.toLowerCase()!= "div") return;
      initTicker(this);
    }
  )
  //ab- .addClass("newsticker")
  .hover(
    function()
    {
      // pause if hovered over
      pauseTicker(this);
    },
    function()
    {
      // resume when not hovered over
      resumeTicker(this);
    }
  );
  //ab- Go directly to an item
  goTo = function(el, item)
  {
    // pause until animation has finished
    el.pause = true;
    stopTicker(el);
    // hide current item
    $('.selected').removeClass('selected');
    $(el.items[el.currentitem]).fadeOut("slow",
      function()
      {
        $(this).hide();
        // move to next item and show
        el.currentitem = item;
        var linkList = $("#headlinePager li");
        $(linkList[el.currentitem]).attr('class','selected');
        $(el.items[el.currentitem]).fadeIn("slow",
          function()
          {
            el.pause = false;
            startTicker(el);
          }
        );
      }
    );
  };
                                         
  return this;
};

})(jQuery);
