function toggleDiv (y, number) {
  var car = $('.activeSlider').data('jcarousel');
  car.scroll(1);
  car.stopAuto();
  car.lock();
  $('.activeSlider').removeClass('activeSlider');

  initCar(y);

  for (x = 1; x <= number; x++) { document.getElementById("thumbDiv" + x).className = 'portfolio_senario_unactive'; }  
  document.getElementById("thumbDiv" + y).className = 'portfolio_senario_active';  
  
  Cufon.refresh();

  $('.portfolio_senario_unactive').find('img').stop(true, false).animate( { 'opacity' : 0.4 } );

  $('div.slideContainer.active').fadeOut(function(){ 
    $('.portfolio_senario_active').find('img').stop(true, false).css( { 'opacity' : 1 } ); 
    $('#div' + y).fadeIn(function(){
      $('.portfolio_senario_active').find('img').stop(true, false).css( { 'opacity' : 1 } );
      $('.portfolio_senario_active').unbind();
      $('.portfolio_senario_unactive').hover( 
        function(){ 
          $(this).find('img').stop(true, false).animate( { 'opacity' : 1 } );
        }, function() { 
          $(this).find('img').stop(true, false).animate( { 'opacity' : 0.4 } );     
        } 
      );  
    
      $('div.slideContainer').removeClass('active');
      $('#div' + y).addClass('active');  
      $('div.slideContainer').not('.active').hide();
      $('div.slideContainer.active').show();

      $('div#player div.previous').click(function(e){
        e.preventDefault();
        $('div#player div.start').hide();
        $('div#player div.stop').show();      
        $('.activeSlider').data('jcarousel').unlock();
        $('.activeSlider').data('jcarousel').stopAuto();
        $('.activeSlider').data('jcarousel').prev();
        $('.activeSlider').data('jcarousel').startAuto();
      });

      $('div#player div.next').click(function(e){
        e.preventDefault();
        $('div#player div.start').hide();
        $('div#player div.stop').show();      
        $('.activeSlider').data('jcarousel').unlock();
        $('.activeSlider').data('jcarousel').stopAuto();
        $('.activeSlider').data('jcarousel').next();
        $('.activeSlider').data('jcarousel').startAuto();
      });

      $('div#player div.stop').click(function(e){
        e.preventDefault();
        $('div#player div.stop').hide();
        $('div#player div.start').show();      
        $('.activeSlider').data('jcarousel').stopAuto();
        $('.activeSlider').data('jcarousel').lock();
      });

      $('div#player div.start').click(function(e){
        e.preventDefault();
        $('div#player div.start').hide();
        $('div#player div.stop').show();
        $('.activeSlider').data('jcarousel').unlock();      
        $('.activeSlider').data('jcarousel').startAuto();
      });

      $('div.right').click(function(e){
        e.preventDefault();
        $('div#player div.start').hide();
        $('div#player div.stop').show();
        $('.activeSlider').data('jcarousel').unlock();      
        $('.activeSlider').data('jcarousel').startAuto();
      });
    
      $('div.start').hide();
      $('div.stop').show();
      
    }); 
  });  

};

function initCar (y) {
  $('div.infonav div.nextPrev div#player div.number span.current').html('1');
  $('#project_'+y+'-slideshow ul.jSlide').jcarousel({
    auto: 2,
    scroll: 1,
    wrap: 'both',
    itemFallbackDimension: 637,
    buttonNextHTML: null,
    buttonPrevHTML: null,
    itemVisibleInCallback: { onAfterAnimation: function(carousel, item, idx, state){ $('div.infonav div.nextPrev div#player div.number span.current').html(idx); } },
    initCallback: function mycarousel_initCallback(carousel) {
      // Disable autoscrolling if the user clicks the prev or next button.
      carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
      });

      carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
      });

      // Pause autoscrolling if the user moves with the cursor over the clip.
      carousel.clip.hover(function() {
        carousel.stopAuto();
      }, function() {
        carousel.startAuto();
      });
    }
  }).addClass('activeSlider');
  
  $('div.infonav div.nextPrev div#player div.number span.total').html($('.activeSlider').data('jcarousel').size());
}
