/**
 * @author Artod
 * http://MoiaVizitka.ru/Artod, http://artod.ru
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
 
jQuery.fn.dynamicSlideshow = function(attr) {
	attr = attr || {};
	attr.duration = attr.duration || 6000;
	attr.speed = attr.speed || 3000;
	
	var container = this;
	$(container).css({position: 'relative'});
	$(container).find('img').css({position: 'absolute', top: 0, left: 0, 'z-index': 0});
	$(container).find('img:first').css({'z-index': 1});
	
	function initSlider(container) {
		var count = $(container).find('img').length;
		var i = 1;

		setInterval(function(){
			if (i == count) {
				i = 0;
				$(container).find('img').css({'z-index': 0});
			}
			$(container).find('img:eq('+i+')').css({opacity: 0.0, 'z-index': 1}).animate({opacity: 1.0}, attr.speed);
			i++;

		}, attr.duration);
	};

	$(window).load(function() {
		$(container).each(function(){
			initSlider(container);
		});
	});

}
