$(document).ready(function(){

if ($('#homepage-headline').length > 0){
  $('#slideshow #image').cycle({
    timeout: 8000,
    speed: 1000,
    delay: 2000,
    pause: true,
    next: '#controls-forward',
    prev: '#controls-back'
  });
}

var $jobListing = $('#job-listing .jobs');
if ($jobListing.length > 0){
  $jobListing.find('article').css('width', 250);
  $jobListing.isotope({
    sortBy: 'date',
    getSortData : {
      name : function($elem){
        return $elem.find('h2 a').text();
      },
      date : function($elem){
        return parseFloat($elem.find('.date').attr('data-date'));
      },
      order : function ($elem){
        return parseFloat($elem.find('.date').attr('data-order'));
      }
    }
  });

  var $jobListingContainer = $('#job-listing');
  var isotopeSorter = function(id, sortObj, width){
    $(id, $jobListingContainer).click(function(){
      var $this = $(this);
      if ($this.not('.active')){
        $this.parent().find('span').removeClass('active');
        $this.addClass('active');
        if (width != undefined){
          $jobListing.find('article').css('width', width);
        }
        $jobListing.isotope(sortObj);        
      }
      return false;    
    });
  };
  
  isotopeSorter('#sort-date', { sortBy: 'date'});
  isotopeSorter('#sort-alpha', { sortBy: 'name'});
  isotopeSorter('#sort-order', { sortBy: 'order'});

  isotopeSorter('#display-collapsed', { layoutMode: 'masonry'}, 250);
  isotopeSorter('#display-list', { layoutMode: 'straightDown'}, '100%');

  isotopeSorter('#filter-all', { filter: '.fulltime, .parttime'});
  isotopeSorter('#filter-fulltime', { filter: '.fulltime'});
  isotopeSorter('#filter-parttime', { filter: '.parttime'});
}


var $faq = $('#faq');
if ($faq.length > 0){
  $('.faq-answer').hide();
  $('#faq .faq-item').click(function(){
    $(this).find('.faq-answer').slideToggle(200).end().find('.faq-question').toggleClass('opened');
  });
}

});


