jQuery.fn.dynamicSlideshow = function(attr) {
	attr = attr || {};
	attr.duration = attr.duration || 3000;
	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}, 1000, function() {
						$(container).find('img:first').remove();
					});
			}).attr('src', img[curr++]).css({position:'absolute',top:0,left:0,'z-index':8, width:"100%"});
		}, attr.duration );
	};

	var img = [];
	var container; 
	var j;
	
	$(this).each(function(){
		$(this).find("a").each(function(){
			img.push($(this).attr("href"));		
		});
		j = new Image();
		container = this;
		$(this).empty();
		
		$(j).attr('src', img[0]);
		$(j).css({position:'absolute',top:0,left:0,'z-index':0, width:"100%"});
				
		//If IE 7+
		if($.browser.msie && $.browser.version > 6)
			testLoad();
		else
		{
			$(j).load(
					function() {
						$(container).append(this);
						initSlider(container, img);
					}
			);
		}
	});
	
	function testLoad()
	{
		if(j.complete != null && j.complete == true)
		{
			$(container).append(j);
			initSlider(container, img);
		}
		else
			setTimeout(testLoad, 100);
	}
}
