jQuery.fn.dynamicSlideshow = function(args) {
	args = args || {};
	args.duration = args.duration || 3000;
	args.img = args.img || 'href';
	args.url = args.url || 'alt';
	
	var isLinkable = false;
	var img = args.data || [];
	var container = null;
	var curr = 1;
	function initSlider() {
		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}, 1000, function() {
						$(container).find('img:first').remove();
						if (isLinkable && img[curr-1][2]) $(container).attr('href',img[curr-1][2] + '');
						else $(container).removeAttr('href');
						if (args.title) $(args.title).html(img[curr-1][1] + '');
				});
			}).attr('src', img[curr++][0]).css({position:'absolute',top:0,left:0,'z-index':8});
		}, args.duration );
	};

	$(this).each(function(){
		$(this).find("img").each(function(){
			if ($(this).attr(args.url)) isLinkable = true;
			img.push([$(this).attr('src'), $(this).attr('alt'), $(this).attr(args.url)]);		
		});
		$(this).find("a").each(function(){
			if ($(this).attr(args.url)) isLinkable = true;
			img.push([$(this).attr(args.img), $(this).html(), $(this).attr(args.url)]);		
		});
		
		$(this).empty();
		if (isLinkable) {
			$(this).html('<a></a>');
			container = $(this).find('a');
		} else container = this;

		var j = new Image();
		$(j).load(function(){
			$(container).append(this);
			if (isLinkable) $(container).attr('href',img[0][2]);
			if (args.title) $(args.title).html(img[0][1] + '');
			initSlider();
		}).attr('src', img[0][0]).css({position:'absolute',top:0,left:0,'z-index':0});
	});
}
