$(document).ready(function() {
    
    $('.profilecontent').width($('.profile').length * 308);
    $('#arrows .prev').parent('li').addClass('inactive');
    
    $('.profile').hover(function() {
        var $this = $(this);

        clearTimeout($this.data('timeout'));
        $this.data('timeout', setTimeout(function() {
            $this.stop().animate({ top: '-308px' }, 1000, 'easeInOutQuart');
        }, 150));
    }, function() {
        var $this = $(this);

        clearTimeout($this.data('timeout'));
        $this.data('timeout', setTimeout(function() {
            $this.stop().animate({ top: '0' }, 1000, 'easeInOutQuart');
        }, 250));
    });
    
    $('#arrows .next').click(function(event) {
        event.preventDefault();
        var $this = $(this);
        
        $('#arrows .prev').parent('li').removeClass('inactive');
        
        $('.profileslider').animate({ scrollLeft: '+=308px' }, 1000, 'easeInOutQuart', function() {
            if($('.profileslider').scrollLeft() >= $('#profiles').width()) {
                $this.parent('li').addClass('inactive');
            } else {
                $this.parent('li').removeClass('inactive');
            }
        });
    });

    $('#arrows .prev').click(function(event) {
        event.preventDefault();
        var $this = $(this);
        
        $('#arrows .next').parent('li').removeClass('inactive');
     
        $('.profileslider').animate({ scrollLeft: '-=308px' }, 1000, 'easeInOutQuart', function() {
            if($('.profileslider').scrollLeft() <= 0) {
                $this.parent('li').addClass('inactive');
            } else {
                $this.parent('li').removeClass('inactive');
            }
        });
    });

});