jQuery(function($){

$('.entry-content a').lightBox();

/* add last class to third boxes */

$('.thumb span').find('div.box:nth-child(3n)').addClass('last');

/* box hover */

$('.thumb .box').css({'cursor':'pointer'});
$('.thumb .box').click(function() {
   			window.location.href = $('a:first', this).attr('href');
		});
		
$('.thumb .box img').animate({'opacity':'0.8'});

$('.thumb .box img').hover(function(){
        $(this).stop().animate({'opacity':'1'},200);
    },function(){
        $(this).stop().animate({'opacity':'0.8'},200);
    });


/* image switch */
	
	$('.slide-wrapper').append('<ul class="slide-nav"></ul>');
	$('.slide').each(function(index) {
		$('.slide-nav').append('<li>' + (index+1) + '</li>');
	});

	$('.slide-nav li:first').addClass('active');

	var slideLength = $('.slide-nav').find('li').length;
	var currentSlide = 0;

	$('.slide-nav li').live('click', function(){
		$('.slide-nav li').removeClass('active');
		$(this).addClass('active');
		currentSlide = $(this).index();
		$('.slideshow').animate({left: -(700*currentSlide)}, {queue:false});
		return false;
	});

	$('.next').live('click', function(e){
		e.preventDefault();
		nextSlide();
	});

	$('.prev').live('click', function(e){
		e.preventDefault();
		prevSlide();
	});

	function nextSlide(){
		if(currentSlide+1 == slideLength){
			$('.slide-nav li:eq(0)').trigger('click');
		}else{
			$('.slide-nav li:eq('+(currentSlide+1)+')').trigger('click');
		}
	}

	function prevSlide(){
		if(currentSlide === 0){
			$('.slide-nav li:eq('+(slideLength-1)+')').trigger('click');      
		}else{
			$('.slide-nav li:eq('+(currentSlide-1)+')').trigger('click');
		}
	}

	function autoPlay(){
		rotate = setInterval(function() { nextSlide(); }, 4500);
	}

	$('.slide-wrapper').hover(function() {
		clearInterval(rotate);
	},function() {
		autoPlay();
	});

	autoPlay();


	$('.slide-nav li:first').addClass('active');
	
		
	$('.slideshow .slide').click(function() {
   	    window.location.href = $('a:first', this).attr('href');
	});
	
	$('.slideshow .slide').css({'cursor':'pointer'});

});
