(function( $ ){
	$.fn.basicrotator = function(options) {
		
		var conf = {
				itemSelector: 'a',
				cycleSpeed: 6000,
				fadeSpeed: 1000,
				imageHeight: '520px'
		};
		if(options) { $.extend(conf, options); }
		
		return this.each(function() {
			
			var rotationItem = this;
			$(rotationItem).css({height: conf.imageHeight});

			$(conf.itemSelector, rotationItem).css({opacity: 0});
			$(conf.itemSelector + '.show', rotationItem).css({opacity: 1});
			
			setInterval(function gallery(){			
				//if no images with the class show exist then set current to the first image.
				
				if($(conf.itemSelector + '.show', rotationItem).length > 0){
				    var current = $(conf.itemSelector + '.show', rotationItem);
				} else {
				    var current = $(conf.itemSelector + ':first', rotationItem);
				    current.addClass('show');
				}
				
				//get the next image, if there is no next image set next to first image.
				if(current.next().length > 0){
				    var next = current.next();
				} else {
				    var next = $(conf.itemSelector + ':first', rotationItem);
				}

				current.animate({opacity: 0}, conf.fadeSpeed)  
			    .removeClass('show');  

				next.css({opacity: 0})
				.addClass('show')
				.animate({opacity: 1}, conf.fadeSpeed);
				
			}, conf.cycleSpeed);

		});
	};	
})( jQuery );
