jQuery.fn.slideshow = function(attr) {
	attr = attr || {};
	attr.duration = attr.duration || 3000;
	
	var curr = 1;
	var prev = 0;
	var auto = true;
	var data = [];
	var title;
	var container;
	
	function initSlider() {		
		if(auto) setInterval(function() { autoNext(); 
    }, attr.duration);
		
		$(data).each(function(p) {
		  $(this).click(function() {
		    curr = p;
		    next(p);
		    return false;
      });
    });
	}
	
	function autoNext() {
		if(curr == data.length) curr = 0;
		next(curr);
		curr++;
  }
	
	function next(pos) {
		var i = new Image();
		var img = $(data[curr]).attr("href");
		var link = $(data[curr]).attr("rel");
		var txt = $(data[curr]).attr("title");	
		
		$(i).load(function() {
			$(container).find("a:first").attr("href", link).append(this);
			$(container).find('img:first').css({ 'z-index': 1 });
			$(data).each(function() { $(this).removeClass("active"); });
      $(data[pos]).addClass("active");
      
			$(title).animate({ opacity: 0.0 }, 500, function() {
        $(this).text(txt).animate({ opacity: 1.0 }, 500);
			});
      
			$(this).css({ opacity: 0.0, 'z-index': 2 }).animate({ opacity: 1.0 }, 1000, function() {
				$(container).find('img:first').remove();
			});
		}).attr('src', img).css({ position: 'absolute', top: 0, left: 0, 'z-index': 8 });
  }

	$(this).each(function() {		
		$(this).find("ul li a").each(function() {
			data.push(this);
		});
		
		var j = new Image();
		container = $(this).find(".main");
		title = $(this).find(".h");
		$(container).empty();
		
    $(j).attr('src', $(data[0]).attr("href")).css({ position: 'absolute', top: 0, left: 0, 'z-index': 0 });
		$(container).append('<a href="'+ $(data[0]).attr("rel") +'"></a>');
		$(container).find("a:first").append(j);
		initSlider();
		/*$(j).attr('src', $(data[0]).attr("href")).css({ position: 'absolute', top: 0, left: 0, 'z-index': 0 }).load(function() {
			$(container).append('<a href="'+ $(data[0]).attr("rel") +'"></a>');
			$(container).find("a:first").append(this);
			initSlider();
		});*/
	});
}