var MAG = Object.extend({}, MAG || {});
MAG.Preview = Class.create();
MAG.Preview.prototype = {
	initialize: function(options)
	{
		MAG.MagPreview = this;

		this.options = {
			preview_element: $('preview_image_container') ? $('preview_image_container').select('img').first() : null,
			objects: $$('#image_preview a')
		};
		Object.extend(this.options, options || {});

		if(this.options.objects.length) this.attach_event();

		return true;
	},

	attach_event: function()
	{
		this.options.objects.each(function(el){
			el.observe('click', this.click_object.bind(this));
		}.bind(this));
	},

	click_object: function(e)
	{
		var el = Event.element(e);
		this.options.preview_element.src = el.src.toString().replace('thumb84x76_', 'thumb292x173_');
		this.options.preview_element.parentNode.href = el.src.toString().replace('thumb84x76_', '');
		Event.stop(e);
	}
};

document.observe('dom:loaded', function(){new MAG.Preview;});
