function slideFeedbacks() {
  var current = $('#feedback .active');
  var next = current.next('.afeedback').length ? current.next() : $('#feedback .afeedback:first');
  current.removeClass('active').fadeOut();
  next.addClass('active').fadeIn();
}

$(document).ready(function(){

  $('.popup').click(function(){
    window.open($(this).attr("href"));
    return false;
  });
  
  $('#tabs a').click(function(){
    $('#tabs .active').removeClass('active');
    $(this).parent().addClass('active');
  });
  
  $('#last').anythingSlider({
    easing: "easeInOutCirc",
    autoPlay: true,
    startStopped: false,
    delay: 5000,
    animationTime: 600,
    hashTags: false,
    buildNavigation: true,
    pauseOnHover: true,
    startText: "Start",
    stopText: "Stop",
    navigationFormatter: null
  });
  
  var t = setInterval("slideFeedbacks()", 20000);
  
  $('#feedback .next').click(function(){
    slideFeedbacks();
    clearTimeout(t);
    t = setInterval("slideFeedbacks()", 20000);
    return false;
  });
  
  $('a[rel="modal"]').each(function(){
  
    var dsc = $(this).attr('id');
    var ctn_title = $('#dsc-'+dsc+' h3').html();
    var ctn_text = $('#dsc-'+dsc+' .ctnt').html();
    
    $(this).click(function(){return false;});
    
    $(this).qtip(
    {
    	
      content: {
         title: {
            text: ctn_title,
            button: 'Fermer'
         },
         text: ctn_text
      },
      position: {
         target: $(document.body), // Position it via the document body...
         corner: 'center' // ...at the center of the viewport
      },
      show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      },
      hide: false,
      style: {
         width: { min:500, max: 500 },
         padding: '14px',
         border: {
            width: 9,
            radius: 9,
            color: '#666666'
         },
         name: 'light'
      },
      api: {
         beforeShow: function()
         {
            // Fade in the modal "blanket" using the defined show speed
            $('#qtip-blanket').fadeIn(this.options.show.effect.length);
         },
         beforeHide: function()
         {
            // Fade out the modal "blanket" using the defined hide speed
            $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
         }
      }
    });
  
    // Create the modal backdrop on document load so all modal tooltips can use it
    $('<div id="qtip-blanket">').css({
       position: 'absolute',
       top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
       left: 0,
       height: $(document).height(), // Span the full document height...
       width: '100%', // ...and full width
  
       opacity: 0.7, // Make it slightly transparent
       backgroundColor: 'black',
       zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
    })
    .appendTo(document.body) // Append to the document body
    .hide(); // Hide it initially
    
  });
  
  $('.popup').live("click", function(){
    window.open($(this).attr("href"));
    return false;
  });



});
