$(document).ready(function(){

	// Sneak Preview - Slideshow
	$('#inspiration-slideshow .slide').css('position', 'absolute');
	$('#inspiration-slideshow .slide:first').show().addClass('current');

	slideshow_interval = setInterval('next_image()', 5000);

    $('#inspiration-slideshow-wrapper .previous').click(function(e) {
    	e.preventDefault();
    	clearInterval(slideshow_interval);
    	previous_image();
    });
    
    $('#inspiration-slideshow-wrapper .next').click(function(e) {
    	e.preventDefault();
    	clearInterval(slideshow_interval);
    	next_image();
    });
	
}); // END DOC READY

function next_image() {
	var current = $('#inspiration-slideshow .slide.current');
	var next_index = $(current).index('#inspiration-slideshow .slide') + 1;
	var next = $('#inspiration-slideshow .slide:eq('+next_index+')');	

	if (next.length) {
		$(current).stop(true, true).fadeOut('slow').removeClass('current');
		$(next).stop(true, true).fadeIn('slow').addClass('current');
	}
	else {
		$(current).stop(true, true).fadeOut('slow').removeClass('current');
		$('#inspiration-slideshow .slide:eq(0)').stop(true, true).fadeIn('slow').addClass('current');
	}

}

function previous_image() {
	var current = $('#inspiration-slideshow .slide.current');
	var previous = $(current).prev('#inspiration-slideshow .slide');
	
	if (previous.length) {
		$(current).stop(true, true).fadeOut('slow').removeClass('current');
		$(previous).stop(true, true).fadeIn('slow').addClass('current');
	}
	else {
		$(current).stop(true, true).fadeOut('slow').removeClass('current');
		$('#inspiration-slideshow .slide:last').stop(true, true).fadeIn('slow').addClass('current');
	}

}
