(function( $ ){
	var settings = {'speed':5000,'interval':0,'index':0};
	
		
	
	var methods = {
		init:function(options){
			var IR = this;
			
			return this.each(function(){
				IR.children('li').hide();
				IR.children('li').css({'list-style':'none','margin':0,'padding':0});
				
				
				var $this = $(this), 
					data = $this.data(IR.attr('id')),
					myData = {};
				
				$.extend(myData, settings, options);       		
				// If the plugin hasn't been initialized yet
				if ( ! data ) {
					$(this).data(IR.attr('id'), {
						target 	: $this,
						speed 	: myData.speed,
						interval: myData.interval,
						index	: myData.index
					});
				}
				
				IR.simpleImageRotator('startRotating');
			});
			
		},
		nextImage:function(){
			var IR = this;
			
			IR.children('li:eq('+$(this).data(IR.attr('id')).index+')').fadeOut();
			var myIndex = $(this).data(IR.attr('id')).index;
			myIndex += 1;
			if( myIndex == this.children().length )
			{
				$(this).data(IR.attr('id')).index = 0;
			}
			else
			{
				$(this).data(IR.attr('id')).index = myIndex;
			}
			
			setTimeout(function(){IR.children('li:eq('+$(IR).data(IR.attr('id')).index+')').fadeIn()},500) ;
			
			return this;
		},
		startRotating:function(){
			var IR = this;
			IR.children('li:eq('+$(IR).data(IR.attr('id')).index+')').fadeIn();
			var intrvl = setInterval(function(){IR.simpleImageRotator('nextImage')}, $(IR).data(IR.attr('id')).speed);
			$(this).data(IR.attr('id')).interval = intrvl;
			return this;
		},
		stopRotating:function(){
			clearInterval($(this).data(IR.attr('id')).interval);
			return this;
		}
	};
	
	$.fn.simpleImageRotator = function(method) {
		// Method calling logic
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jquery.simpleImageRotator' );
		}
	};
})( jQuery );
