$(document).ready(function() {
	$('#slideshow div').css('opacity', 0);
	$('#slideshow div.active').css('opacity', 1.0);
});

function img_switch() {
	if ( $('#slideshow div').length > 1 ) 
	{
	    var active = $('#slideshow div.active');
	
	    if ( active.length == 0 ) active = $('#slideshow div:last');
	
	    //if exist div after active
	    //console.log($active.next().length);
	 
		if ( active.next().length ) 
		{ 
			var next_element = active.next();
		}
		else
		{
			var next_element = $('#slideshow div:first');
		}
	
	    active.addClass('last');
	
	    next_element.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 2000, function() {
	            active.removeClass('active last');
	        });
	}
}

$(function() {
    setInterval( "img_switch()", 4000 );
});