window.addEvent('domready', function() {
	$$('.pg-sb').each(function(wrapper) {
		if(!wrapper.hasClass('pg-init')) new pgSlideshowBlinds(wrapper);
		wrapper.addClass('pg-init');
	});
});

var pgSlideshowBlinds = new Class({

	Implements: [Options],

	options: {
		showCaption: true,
		showProgressBar: true,
		showChrome: true,
		delay: 12000, //ms
		axis: 'vertical', //vertical,horizontal
		blindSections: 28 //how many stripes
	},

	initialize: function(el, options) {
		//options
		this.setOptions(options);
		
		//main element references
		this.wrapper = document.id(el);
		this.outerWrapper = document.id('pgOuterWrapper');
		this.blinds = this.wrapper.getElement('.blinds');
		this.images = this.blinds.getElements('img');
		
		//-----
		
		this.maxImageWidth = 0;
		this.maxImageHeight = 0;
		
		//determine max image size to make sure all fit ok
		this.images.each(function(image) {
			var w = image.get('width').toInt();
			if(w > this.maxImageWidth) {
				this.maxImageWidth = w;
			}
			var h = image.get('height').toInt();
			if(h > this.maxImageHeight) {
				this.maxImageHeight = h;
			}
		}.bind(this));
		
		//adjust dimensions
		this.wrapper.setStyles({
			width: this.maxImageWidth + 'px',
			height: (this.maxImageHeight + (this.options.showChrome && this.options.showCaption ? 80 : 0)) + 'px'
		});
		this.blinds.setStyles({
			width: this.maxImageWidth + 'px',
			height: this.maxImageHeight + 'px'
		});
		if(this.outerWrapper) {
			this.outerWrapper.setStyle('width', this.wrapper.getSize().x + 'px');
		}
		
		//remove chrome (this also disables the progress bar and caption)
		if(!this.options.showChrome) {
			this.options.showProgressBar = false;
			this.options.showCaption = false;
			this.wrapper.setStyle('padding', '0');
		}
		
		//-----
		
		//floom
		this.blinds.floom(this.images, {
			axis: this.options.axis,
			interval: this.options.delay,
			amount: this.options.blindSections,
			captions: this.options.showCaption,
			progressbar: this.options.showProgressBar,
			slidesBase: '',
			animation: 80
		});
	}

});
