(function($) {
	$.extend({
		imgscroll: new function() {

			this.defaults = {
				interval: 40,
				stepWidth: 4,
				totalWidth: 0
			};

			/* public methods */
			this.construct = function(settings) {
				return this.each(function() {
					this.config = {};
					this.config = $.extend(this.config, $.imgscroll.defaults, settings);
					if (this.config.totalWidth == 0) {
						/* warning: might be buggy in IE, so better provide totalWidth! */
						var w = 0;
						$(this).children().each(function() {
							w += $(this).width();
						});
						this.config.totalWidth = w;
					}
					$(this).everyTime(this.config.interval, function() {
						var cont = this;
						$(this).children().each(function() {
							var img = $(this);
							var pos = parseInt(img.css('left'));
							pos -= cont.config.stepWidth;
							if (pos < -img.width()) {
								pos += cont.config.totalWidth;
							}
							img.css('left', pos+"px");
						});
					});
				});
			};
		}
	});
	
	// extend plugin scope
	$.fn.extend({
		imgscroll: $.imgscroll.construct
	});
})(jQuery);

