	var currentImage;
	var timer;
	var currentIndex = -1;
	var interval = 6000;
	function showImage(index){
		if(index < jQuery('#postcards li').length)
		{
			var indexImage = jQuery('#postcards li').eq(index);
			if(currentImage)
			{   
				if ( currentIndex != index )
				{
					jQuery(currentImage).css('z-index',2);
					jQuery(currentImage).fadeOut(250, function() {
						jQuery(this).css({'display':'none','z-index':1})
					});
				}
			}
			jQuery(indexImage).css({'display':'block', 'opacity':1});
			currentImage = indexImage;
			currentIndex = index;
			jQuery('#thumbs li').removeClass('active');
			jQuery(jQuery('#thumbs li').eq(index)).addClass('active');
		}
	}

	function showNext(){
		var len = jQuery('#postcards li').length;
		var next = currentIndex < (len-1) ? currentIndex + 1 : 0;
		showImage(next);
	}

	function resetSlideshow(){
		clearInterval(timer);
		timer = setInterval("showNext()", interval);
	}

	jQuery(document).ready(function() {
		resetSlideshow();
		showNext();
		jQuery('#thumbs a').click(function(e){
			var count = jQuery(this).attr('rel');
			showImage(parseInt(count));
			resetSlideshow();
		});

		jQuery('#postcards_pause').toggle(
			function(){
				clearInterval(timer);
				jQuery(this).css('background-position', 'right top');
			},
			function(){
				resetSlideshow();
				jQuery(this).css('background-position', 'left top');
			}
		);

		jQuery('#thumbs_hide').click(function(){
			jQuery('#thumb_controls').animate({'width':'toggle'});

			if(jQuery(this).css('background-position')=='100% 0%')
			{
				jQuery(this).css('background-position', '0% 0%');
			}
			else
			{
				jQuery(this).css('background-position', '100% 0%');
			}
		});

		jQuery('#thumbs').show();
	});

