(function($) {
		  
	$.fn.slideshow = function(rotateSpeed, fadeSpeed){
		// loop thru each matched element
		return this.each(function(index, list) {
			
			var element = this;
			
			$(element).hide();
			var myID = $(element).parent().parent().attr("id").replace("module-content-", "");
			var myContainer = "#rotate-container-" + myID;
			//BUILDS CONTAINING STRUCTURE
			var structure = "<div id='" + myContainer.replace("#", "") + "'>"+
							"	<div class='pictures'></div>"+
							"	<div class='overlay'></div>"+
							"</div>";	
			$(element).parent().parent().append(structure);
			//BUILDS DATA
			$(element).find("div.ui-article").each(function(){
				var imgURL = $(this).find(".ui-article-controls a:eq(0)").attr("href");
				$(myContainer).find("div.pictures").append("<img src='" + imgURL + "'/>");
			});
			//ROTATE
			if($("div.pictures img").size() > 1){
				rotateTimer = setInterval(function(){
					$(myContainer).find("div.pictures img:last").fadeOut(fadeSpeed*1000, function(){
						$(this).parent().prepend(this);
						$(this).show();
					});
					
				}, rotateSpeed*1000);
			}
			//STYLES
			$(myContainer).find("div.pictures").css("position", "relative");
			$(myContainer).find("div.pictures img").css("position", "absolute");
		});
	};

})(jQuery); 
