jQuery.fn.dynamicSlideshow = function(attr) {
	attr = attr || {};
	attr.duration = attr.duration || 8000;
        img = attr.pictures;

        function initSlider(container, img) {
		var curr = 1;
		setInterval( function(){
			if (curr == img.length) {
				curr = 0;
			}
			var i = new Image();
			$(i).load(function(){
				$(container).append(this);
				$(container).find('img:first').css({'z-index': 1});
				$(this).css({opacity: 0.0, 'z-index': 2}).animate({opacity: 1.0}, 2000, function() {
                                    $(container).find('img:first').remove();
				})
			}).attr({'src': img[curr++],'class':'slidepic'}).css({'z-index':8});
		}, attr.duration );
	}

        var container = this;
        $(this).empty();

        $(img).each(function(){
		var j = new Image();
                $(j).load(function () {
                    $('#slideshow').append(this);
                    $(container).append(this);
                    initSlider(container, img);
                }).attr({'src': img[0],'class':'slidepic'}).css({'z-index': 0});
            });
}

