var PicFader = function (cont) {
	var counter = 0, total = 0, slideshowClass = 'slideshow';
	var container = $(cont).addClass(slideshowClass);
	return {
		init: function (f, w, l) {
			if (container.length) {
				this.images = container.find("img").hide();
				this.hideImages = this.images.not(":first").not(":last");
				if (this.images.length > 1) {
					total = this.images.length;
					this.fadeTime = this.returnMil(f);
					this.interval = this.fadeTime + this.returnMil(w);
					this.images.first().fadeIn(this.fadeTime);
					this.start();
				}
			}
		},
		start: function () {
			var that = this;
			this.timer = setInterval(function () {
				that.fadeEm();
			}, this.interval);
		},
		stop: function () {
			clearInterval(this.timer);
		},
		returnMil: function (inp) {
			var input = Number(inp);
			if (input < 10) {
				input *= 1000;
			}
			return input;
		},
		fadeEm: function () {
			if (counter < total) {
				this.images.eq(counter++).fadeIn(this.fadeTime);
			} else {
				this.hideImages.hide();
				this.images.last().fadeOut(this.fadeTime);
				counter = 1;
			}
		}
	};
};
$(function () {
	var pF = new PicFader("#picFader").init(1, 3);
});
