(function($) {

$.fn.vo_slideshow = function(options) {
	var currentZindex = 0;
	
	for (var i = 0; i<options.items.length; i++) {
		$('<em></em>').attr('id', 'vo_slideshow_item_' + Number(Number(i) + 1)).css('display', (i == 0 ? 'block' : 'none')).css('z-index', --currentZindex).css('background-image', 'url('+options.items[i]+')').appendTo(this);
	}
	
	var active = 1;
	var currentItem = 0;
	var interval = window.setInterval(function() {
		currentItem++;
		if(currentItem == options.items.length + 1) {
			currentItem = 1;
		}
		
		// Check which container we need to use
		var currect = active;
		if(active == options.items.length)
			active = 1;
		else
			active++;
		
		show_image(currect, active);
	}, options.speed);
	
	var show_image = function(currect, active) {
		currentZindex--;
		
		$('#vo_slideshow_item_' + active).css("display", "block").css("z-index", currentZindex);
		$('#vo_slideshow_item_' + currect).fadeOut(500);
	}
};

})(jQuery)
