function Slideshow( container, options ) {
	this.options = options = jQuery.extend( {
		slideClass: "slide",
		fade: 1,
		delay: 5,
		carousel: true,
		carouselDelay: 0.5,
		pause: 10,
		debug: false
	}, options || {} );
	
	if( options.debug )
		alert( "Finding container" );
	this.container = $( "#" + ( container ? container : "slideshow" ) );
	
	if( options.debug )
		alert( "Finding slides" );
	this.slides = this.container.children( "div." + options.slideClass );
	
	if( options.debug )
		alert( "Setting fade" );
	this.fade = options.fade * 1000;
	
	if( options.debug )
		alert( "Setting delay" );
	this.delay = options.delay * 1000;
	
	if( options.debug )
		alert( "Setting pause" );
	this.clickPause = options.pause * 1000;
	
	if( options.debug )
	  alert( "Setting carousel delay" );
	this.carouselDelay = options.carouselDelay * 1000;
	
	if( options.debug )
		alert( "Initializing variables" );
	this.index = -1;
	this.timeout = null;
	this.carouselTimeout = null;
	
	if( options.carousel ) {
		if( options.debug )
			alert( "Creating carousel div" );
		this.carousel = $( "<div id=\"carousel\"></div>" ).insertAfter( this.slides.filter( ":last" ) );
		
		if( options.debug )
			alert( "Creating carousel previews" );
		for( var i = 0; i < this.slides.length; i++ ) {
		  var offset = 0;
		  if( $.browser.msie )
		    if( getIEVersion < 7 )
		      offset -= 1;
		    else
		      offset += 1;
			this.carousel.append( $( "<a href=\"#\" onclick=\"slideshow.jumpTo(" + i + ", true); return false;\"><img class=\"thumbnail\" src=\"" + this.slides.eq( i ).find( "img" ).attr( "src" ) + "\" height=\"" + ( this.carousel.height() - 4 - offset ) + "px\"/></a>" ) );
		}
		
		if( options.debug )
			alert( "Binding carousel hover" );
		this.container.hover( this.showCarousel.bind( this ), this.hideCarousel.bind( this ) );
	}
	else
		this.carousel = null;
		
	this.slides.each( function() {
	  this.alt = null;
  } );
}

jQuery.extend( Slideshow.prototype, {
	next: function() {
		with( this ) {
			if( options.debug )
				alert( "next" );
			
			jumpTo( ( index + 1 ) % slides.length );
			timeout = this.next.delay( delay, this );
		}
	},
	
	pause: function() {
		clearTimeout( this.timeout );
	},
	
	jumpTo: function( i, pause ) {
		with( this ) {
			if( index != i ) {
				var old = index;
				index = i;
				fadeIn( index );
				fadeOut( old );
			}
		}
		
		if( pause )
		{
		  this.pause();
			this.timeout = this.next.delay( this.clickPause, this );
		}
	},
	
	fadeOut: function( i ) {
		with( this ) {
			if( i > -1 ) {
				slides.eq( i ).fadeOut( fade );
				
				if( carousel )
					carousel.find( "img" ).eq( i ).removeClass( "active" );
			}
		}
	},
	
	fadeIn: function( i ) {
		with( this ) {
			slides.eq( index ).fadeIn( fade );
			
			if( carousel )
				carousel.find( "img" ).eq( index ).addClass( "active" );
		}
	},
	
	showCarousel: function() {
		with( this ) {
		  clearTimeout( carouselTimeout );
		    
			//carousel.fadeTo( 500, 0.5 );
			carousel.animate( { height: container.height() * 0.1 }, 500 );
		}
	},
	
	hideCarousel: function() {
		with( this ) {
			//carousel.fadeTo( 500, 0 );
			carouselTimeout = carousel.animate.delay( carouselDelay, carousel, [ { height: "hide" }, 500 ] );
		}
	}
});