(function($) {
	$.fn.changeContent = function(opts) {
		
		/*$.each(this, function(index, value){
			console.log(index, value);	
		})
		//if debug property coming true
		if (options.debug === true) {
			debug(options);
		};
		
		
		
		
		// to right...
		$(options.toRight).live('click', function(event){
			var duration = options.effect.duration;
			$(options.items + ':first')
				.fadeOut(duration, function(){
					$(this)
						.next()
						.fadeIn(duration);
				});
		});
		
		
		// to left...
		$(options.toLeft).live('click', function(event){
			var duration = options.effect.duration;
			$(options.items + ':visible')
				.fadeOut(duration, function(){
					$(this)
						.prev()
						.fadeIn(duration);
				});
		});
		
		
		
		
		if ($(this) === $(options.toRight)) {
			that = $(this).next();
		}
		else{
			that = $(this).prev();
		}
		
		*/
		
		// options and defaults merging
		
		return this.each(function(index, value){
			var options = $.extend({}, $.fn.changeContent.defaults, opts);
			$(options.toLeft + ', ' + options.toRight).live('click', function(event){
				var button = $(this);
				var show;
				var items = $(options.items);
				var first = $(options.items + ':first');
				var last = $(options.items + ':last');
				var visible = items.not(':hidden');
				var next = visible.next();
				var prev = visible.prev();
				var duration = options.effect.duration;
				
				visible.fadeOut(duration, function(){
					if (button.hasClass('toRight')) {
						show = next;
						if (!next.length > 0) {
							show = first;
						}
					}
					else{
						show = prev;
						if (!prev.length > 0) {
							show = last;
						}
					}
					show.fadeIn(duration);
				});
			});
		})
	};
	
	
	// 2 level debug method
	function debug(options) {
		$.each(options, function(index, value){
			
			if (typeof(value) === 'object') {
				
				window.console.log('  ' + typeof(value) + ':');
				
				$.each(value, function(i, v){
					window.console.log('    ' + i + ': ' + v);
				});
			}
			else {
				window.console.log(index + ': ' + value);
			};
		});
	};
	
	
	// default options
	$.fn.changeContent.defaults = {
		debug: false,
		items: '.sliderItem',
		toLeft: '.toLeft',
		toRight: '.toRight',
		effect: {
			active:true,
			type:'slide',
			duration:700
		}
	};
	
})(jQuery);