$( document ).ready(function() {
	
	// READ MORE BUTTON
	$('.read-more').click(function( event ) {		
		var extra = $(this).closest('.article').find('.extra-article');
		
		if ( extra.length ) {
			event.preventDefault()
			extra.slideToggle();
			
			$(this).toggleClass('read-less');
			
			if ( $(this).text() == 'read more' ) {
				$(this).text('read less');
			} else {
				$(this).text('read more');
			}
		}
	});
	
	// SLIDESHOW STUFF
	var slideWidth = $(document).width();
	var $slides = $('#slideshow .slide-holder ul li');
	
	$slides.width( slideWidth );
	$('#slideshow .slide-holder').width( slideWidth * $slides.length );
	
	var animating = false;
	
	$('#slideshow .slide-switcher ul li').click(function( event ) {
		event.preventDefault();
		
		if ( animating ) {
			return;
		}
		
		var index = $(this).prevAll('li').length;
		
		if ( $(this).hasClass('active') ) {
			return;
		}
		
		animating = true;
		
		var $current = $(this).siblings('.active:first');
		
		$(this).addClass('active').siblings('li').removeClass('active');
		
		var $caption;
		
		$('#slideshow .slide-holder ul li:eq(' + $current.prevAll('li').length + ') .slide-text').animate({'left': '-' + 1200, opacity: 0}, 800, 'linear', function () {
			$caption = $(this).hide();
		});
		
		$('#slideshow .slide-holder').animate({"left": '-' + slideWidth * index }, 1400, 'easeInOutExpo', function() {
			$caption.show().css({'left': 0, 'opacity': 1});
			animating = false;
		});
	});
	
	window.setTimeout(function nextSlide() {
		var curSlide = $('.slide-switcher li.active');
		
		if ( curSlide.next('li').length ) {
			curSlide.next('li').click();
		} else {
			$('.slide-switcher li:first').click();
		}
		
		window.setTimeout(nextSlide, 15000);
		
	}, 15000);
});
