(function ($ ) {
    var timeout,settings,methods,obj;
    //Default settings, can be overridden
    settings = {
	'direction'	: 1,
	'pauseTime'	: 3,
	'animationTime'	: .2,
	'autostart'	: true,
	'autoforward': true,
	'autocontinue': true, //Ga verder na één klik
	'calcWidth'	: false, //Berekend automatisch hoe breed de ul moet zijn. Is langzaam, beter uit laten
	"width"		: $(window).width(),
	"css"		: '<style type="text/css">'+
				'.jGallery_fade { margin: 0; }'+
			    '.jGallery_fade li { position:absolute; list-style: none; left:0px;} img { border: 0px; }'+
			    '#inf_scroll_links, #inf_scroll_rechts { width: 20px; background: #FFF; height: 100%; }'+
			    '</style>'
    }
    methods = {
      init : function( options ) { },
      show : function( ) { },
      hide : function( ) { },
      update : function( content ) { },
      start : function(){},
      stop: function() {}
    };
    $.fn.fadinggallery = 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.tooltip' );
		}
    }
    
    //INITIALISE
    methods.init = function(options) {
		return this.each(function() {
			//Update de options met custom options
			if(options) {
				$.extend(settings, options);
			}
			$(this).addClass("jGallery_fade");
			$(this).before(settings.css);
			
			obj = this;
			methods.start();
		});
	}
	methods.start = function() {
		startAnim();
	}
	function startAnim() {
		clearTimeout(timeout);
		$("li",obj).last().fadeOut(settings.animationTime*1000, 
			function(event) {
				//verplaatst de laatste naar de eerste
				$(this).prependTo($(this).parent().first()).show();
				timeout = setTimeout(function(scope) {
					startAnim();
				}, settings.pauseTime*1000);
			}
		);
	}
}) ( jQuery );
