function slideshow() {
	var els = [];
	var duration =  5; //seconds
	var focus = true;

	function init() {
		$('.slideshow_wrapper').each(function() {
			var tmp = $(this).find('.slideshow');
			if(
				typeof(tmp) != 'undefined' &&
				tmp.length > 1
			) els.push({'cur':0,'els':tmp});
		});
		if(els.length > 0) {
			window.setInterval(function() {
				if(focus) {
					$.each(els,function() {
						if(this.cur > this.els.length-1) this.cur = 0;
						var nxt = this.cur+1;
						if(nxt > this.els.length-1) nxt = 0;
						$(this.els[this.cur]).animate({'opacity':0},500);
						$(this.els[nxt]).animate({'opacity':1},500);
						this.cur++;
					});
				};
			},duration*1000);
		};
	};

	$(window).bind({
		'focus': function() { focus = true; },
		'blur': function() { focus = false; }
	});

	init();
};

$(document).ready(function() { new slideshow(); });
