$(function(){
  
  
    $("a[rel^='prettyPhoto']").prettyPhoto();
    
    $about = $('#about')
    $carousel = $('#carousel ul');
    $headline = $('#headline')
    $caption = $('#caption');
    $controls = $('.controls li');
    active_idx = 0;
  
    $carousel.cycle({
      fx: 'shuffle',
      speed: 500,
      before: cycleBefore,
      timeout: 5000
    });
    
    function cycleBefore(e){
      //alert('a');
      idx = $(this).index();

      $controls.find('a').removeClass('active');
      $controls.eq(idx).find('a').addClass('active');
    }
    
    $controls.find('a').click(function(e) { e.preventDefault(); })
    $controls.click(function(e){
      e.preventDefault();
      idx = $(this).index();
      if (active_idx != idx) {
        $carousel.cycle(idx);
        active_idx = idx;
      }
    });
  
  
    $('.readmore').click(function(e){
        
        e.preventDefault();
        
        rel = $(this).attr('rel');
        $(this).hide();
        $(rel).slideDown(1000);
        $("a.readless[rel=" + rel + "]").fadeIn();
        
    });

    $('.readless').click(function(z){
        
        z.preventDefault();
        
        rel = $(this).attr('rel');
        $(this).hide();
        $(rel).slideUp(1000, function(){
           $("a.readmore[rel=" + rel + "]").show(); 
            });
        });


      $('.clickable').click(function(){
          // Creates a big click target by making an entire div.clickable
          // link to a link inside with class target
          target_href = $(this).find('.target').attr('href');
          location.href = target_href;
      });
    
      /****************************
      ******    Gallery     *****
      *****************************/

});
