(function($){
		  
	var timerObj;
	var current;
	var interval;
	var total;
	var obj;

	$.fn.slideshowImageFader = function(options) {
		
		// build main options before element iteration
		var options = $.extend({}, $.fn.slideshowImageFader.defaults, options);
		
		// iterate and reformat each matched element
		return this.each(function() {
								  
			$this = $(this);
			
			obj = $this;
			
			current = options.current;
			interval = options.interval;
			total = options.total;
			
			for(var i=total-1;i>=0;i--){
				
				$('<img/>')
					.attr('src', options.images[i])
					.attr('id', 'image' + i)
					.attr('class', 'loadedImg')
					.css('z-index',500 + (total - i) )
					.appendTo($this).fadeIn('slow');
					
			}
			
			timerObj = $.timer(interval,function(timer){onTimerEvent(timer,current,total,interval)});
			
		});
	};
	
	//
	// private function for timer event
	//
	function onTimerEvent(timer,current,total,interval){

		timer.stop();
		
		$("#image"+current).fadeOut('slow',function(){

			var z = parseInt($("#image"+current).css('z-index'));
			
			$("#image"+current).css('z-index', z - total);
			
			$("#image"+current).show();

			current = current + 1;
			
			if(current==total) current = 0;
				
			timerObj = $.timer(interval,function(timer){onTimerEvent(timer,current,total,interval)});

		});
	}
	
	//
	// define and expose slideshow stop function
	//
	$.fn.slideshowImageFader.stopSlideShow = function(){
		timerObj.stop();
		$('#imagefader_loader').hide(function(){
			$(".loadedImg").hide(function(){
				obj.css('background-color','#000000').append('<span class="imagefader_edit_title" id="fader_edit_title">EDIT MODE</span>');
			});
		});
	};
	
	//
	// define and expose slideshow start function
	//
	$.fn.slideshowImageFader.startSlideShow = function() {
		$(".loadedImg").show();
		timerObj.reset(interval);
		$('#fader_edit_title').remove();
	};
	
	//
	// plugin defaults
	//
	$.fn.slideshowImageFader.defaults = {
		images:null,
		interval:2000,
		total:null,
		current:0
	};
	
	//
	// end of closure
	//
	
})(jQuery);