$(function() {
  $('.slider').each(function() {
    $(this).cycle({
      speed: 800,
      timeout: 6000,
      next: $(this), 
      pause: 1,
      after: onAfter
     });
     
   });
  
  function onAfter( curr, next, opts, fwd ) {
    var $ht = $(this).height();
   $(this).parent().css({height: $ht});
  }
    
  function expandIntro(){
    $('#intro').css({
      "height": $(window).height() - $('#top').outerHeight() - 100
    });
  }
  
  function hideBrowse() {
    if ( $(window).height() < 800 ) {
      $('#browse').hide();
    } else {
      $('#browse').show();
    }
  }
  
  function slideHeader() {
    var headerHeightMax = 200;
  	var headerHeightMin = 85;
  	
    if( $(window).scrollTop() < headerHeightMin ){
  		$('#top').css( "top", -$(window).scrollTop() );
  		$('.twt').fadeOut();
  	} else {
  	  $('#top').css( "top", -headerHeightMin );
  	  $('.twt').fadeIn();
  	}
  }
  
  $('a#back-top, a.logo').click(function( e ){
    if( $(window).scrollTop() > 0 ) {
      $.scrollTo( 0, 800 );
    }
    e.preventDefault();
  });

  expandIntro();
  hideBrowse();
  $(window).resize(function() { expandIntro(); hideBrowse(); });
  $(window).scroll(function() { slideHeader(); });
  $.localScroll({ offset: -200 });

});
