function slideSwitch() {
	var $active = $('#gallery li.active');
	if ( $active.length == 0 ) $active = $('#gallery li:last');
	// use this to pull the images in the order they appear in the markup
	var $next =  $active.next().length ? $active.next() : $('#gallery li:first');
	// uncomment the 3 lines below to pull the images in random order
	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $( $sibs[ rndNum ] );
	//debugger;
	console.log($active,$next);
	
	FadeinFadeout($active,$next);
	
	var $activeC = $(".countlist").children('li.active');
	if ( $activeC.length == 0 ) $activeC = $('.countlist li:last');
	// use this to pull the images in the order they appear in the markup
	var $nextC =  $activeC.next().length ? $activeC.next() : $('.countlist li:first')
	
	if($active.hasClass('two') || !$active.hasClass('one')){
		$activeC.removeClass('active');
		$nextC.addClass('active');
	}
}
function FadeinFadeout($active,$next){
	if(!$active.hasClass('one') || $active.hasClass('two') && $active.prev().hasClass('one')){ 
		$active.animate({opacity: 0.0}, 2000).addClass('last-active');
		if($active.prev().hasClass('one') && !$active.hasClass('two')) $active.prev().animate({opacity: 0.0}, 2000).addClass('last-active');
	}
	$next.animate({opacity: 1.0}, 2000, function() {
			if(!$active.hasClass('one') || $active.hasClass('two') && $active.prev().hasClass('one')) $active.removeClass('active last-active');
	}).addClass('active');
}
$(function(){
	var countlist = $(".countlist");
	
	$("#gallery li").each(function (i) {
		i = i+1;
		$(this).attr("id", i);
    });
	
	var count = $("#gallery").children('li').clone().appendTo(".countlist").html("");
	countlist.children('li.two').remove();
	/*countlist.children('li').bind('click', function(){
		
		countlist.children('li').removeClass('active');
		$(this).addClass('active');
		FadeinFadeout($('#gallery li#' + $(this).attr('id')));
	});*/
	setInterval( "slideSwitch()", 10000 );
});
