(function() {
	$.fn.slideshow = function(settings) {
		settings = $.extend({
			width: 	982,
			height: 157,
			animation: 1000,
			timeForOne: 7000,
			imagesContainer: $('body')
		}, settings);
		var imgs = settings.imagesContainer.find('img');
		return this.each(function() {
			var d1 = $(this).html('<div class="slideshow-wrap1"><div class="slideshow-wrap2"></div></div>')
			.find('div')
			.css({
				width: settings.width,
				height: settings.height
			}), d2 = d1.eq(1), d1 = d1.eq(0);
			var n = 0, m = 1;
			function next() {
				n++; m++;
				if (n > imgs.length - 1) n = 0;
				if (m > imgs.length - 1) m = 0;
				d1.css('background', 'url(' + imgs.eq(m).attr('src') + ') center center no-repeat');
				d2.css('background', 'url(' + imgs.eq(n).attr('src') + ') center center no-repeat').fadeOut(settings.animation, function() {
					d2.css('background', 'url(' +  imgs.eq(m).attr('src') + ') center center no-repeat').show();
				});
			}
			next();
			window.setInterval(next, settings.timeForOne);		
		});
	}
})(jQuery);

$(function() {
	$('#container').slideshow({
		imagesContainer: $('#data')
	});	
});
