(function($) {	$.fn.slideshow = function(o) {
		o=$.extend({
			path:'',
			images:[],
			imagesBig:[],
			width:600,
			height:300,
			pmtb:5,
			pmlr:3,
			speed:3000
		},o||{});
		return this.each(function() {			if (o.images.length <= 0 && o.imagesBig.length <= 0) return;
			var index = 0, next = 0;
			if (o.images.length == 0) o.images = o.imagesBig;
			if (o.imagesBig.length == 0) {
				for (var i=0;i<o.images.length;i++) o.imagesBig[i] = o.images[i]+'.jpg';
			}

			var arrows=[26,24]; // Width and height of arrows
			var bigImageAnimating = false;

			var element = $(this);
			element.parent().css({width:o.width+'px',height:o.height+'px'});
			element.css({width:o.width+'px',height:o.height,position:'absolute'});

			// Image on front
			var bigImage1 = $(document.createElement('div'));
			bigImage1.css({height:o.height+'px',position:'absolute',zIndex:2,backgroundPosition:'center',backgroundRepeat:'no-repeat'});
			element.append(bigImage1);

			// Image on back
			var bigImage2 = bigImage1.clone();
			bigImage2.css({zIndex:1});
			element.append(bigImage2);

			// Set first image
			bigImage1.css('backgroundImage','url('+o.path+o.imagesBig[index]+')');

			function go()
			{				if (bigImageAnimating) return;
				var _img = new Image;
				_img.src = o.path+o.imagesBig[next];
				var _ir2 = setInterval(function(){
					if (_img.complete == true) {
						clearInterval(_ir2);
						bigImageAnimating = true;
						var _bg = 'url('+o.path+o.imagesBig[next]+')';
						bigImage2.css('backgroundImage', _bg);
						bigImage1.fadeOut(1200, function(){
							bigImage1.css('backgroundImage', _bg);
							bigImage1.show(0);
							if (++next >= o.images.length) next = 0;
							bigImageAnimating = false;						});					}
				}, 100);
			}

			$(window).resize(function(){
				var _w = element.parent().width();

				element.css({width:_w+'px'});
				bigImage1.css({width:_w+'px'});
				bigImage2.css({width:_w+'px'});
			});

			$(window).resize();
			var _ir = setInterval(go, o.speed);
		});
	};
})(jQuery);
