/*
Script: ImageCaption.js
	For MooTools 1.2+
	Automatically captions img elements with their alt or title property
	
	License:
		MIT-style license.
	
	Authors:
		Jacob Gube - http://sixrevisions.com/
*/
var ImageCaption = new Class({
	Implements: [Options],
	options: {
		wrapperClass: 'imageCaption',
		wrapperType: 'span',
		captionType: 'span',
		captionPosition: 'after'
	},
	initialize: function(images, options){
		//this.setOptions(options);
		ImageCaption.implement(new Options, new Events);
		images.each(function(image){
			this.addCaption(image);
		}, this);
	},
	addCaption: function(image){
		var captionText = image.getProperty('alt') || image.getProperty('title') || '';
		var width = image.getProperty('width').toInt() || 'auto';
		var wrapper = new Element(this.options.wrapperType, {
			'class': this.options.wrapperClass,
			'styles': {
				'display': 'block',
				'width': width
			}
		});
		var caption = new Element(this.options.captionType, {
			'html': captionText,
			'styles': {
				'display': 'block',
				'width': width
			}
		});
		wrapper.wraps(image);
		caption.inject(image, this.options.captionPosition);
	}
});
