$(function() {
  
  $('.answers article h2').click(function() {
    
    if($(this).parent().find('.answer').hasClass('active')) {
      $('.answers .answer').removeClass('active');        
    } else {
      $('.answers .answer').removeClass('active');    
      $(this).parent().find('.answer').addClass('active');
    }

  });

  var slideshow = {
    
    init : function() {
        
      var $this = this;
      this.elem = $('#slideshow');
      if(!this.elem.length) return;
      
      var next = $('<a class="slideshow next" href="#">next</a>').click(function() {
        $this.next();      
        return false;
      });

      var prev = $('<a class="slideshow prev" href="#">prev</a>').click(function() {
        $this.prev();      
        return false;
      });
      
      this.elem.after(prev).after(next);
            
    },
    
    next : function() {

      var active = this.elem.find('.slide.active');
      var next   = active.next('.slide');
      
      if(!next.length) next = this.elem.find('.slide').first();
      
      this.show(active, next);  
    
    },
    
    prev : function() {

      var active = this.elem.find('.slide.active');
      var prev   = active.prev('.slide');
      
      if(!prev.length) prev = this.elem.find('.slide').last();

      this.show(active, prev);  
          
    },
    
    show : function(active, next) {
      active.removeClass('active');    
      next.addClass('active');    

      var index = this.elem.find('.slide').index(next);
      this.elem.find('.sledge').animate({'left' : -(index*920)}, 300);
      
    }
      
  };

  slideshow.init();
  
});
