
var ambience_imageClass = new Class
(
{
	initialize: function()
	{
		$$('div.LightBox').fade('hide');
		$$('div.LightBoxOverlay').fade('hide');
		this.setEvents();
		$$('a.LightBoxClose').addEvent('click', this.hideLightbox.bind(this));
	},

	setEvents: function()
	{
		var self = this;

		$$('a.LightBox').removeEvents('click');
		$$('a.LightBox').addEvent('click', this.showAjaxLightbox.bind(this));

		$$('div.LightBox img').fade('hide');
		$$('div.LightBox img').each(
		function(oElement)
		{
			oElement.onload = self.showImage;
		}
		);
		
		if(typeof setPrettyPhoto == 'function') {
			setPrettyPhoto();
		}

	},

	showAjaxLightbox: function(oEvent)
	{
		var oImageButton 	= new Element( new Event( oEvent ).target);
		var oSaveButton 	= oImageButton.getParent();

		sUrl = oSaveButton.href;
		sRel = oSaveButton.rel;
		if(typeof(sUrl) === 'undefined')
		{
			sUrl = oEvent.target.get('href');
			sRel = oEvent.target.get('rel');
		}

		oLightBox = $(sRel);
		oLightBoxContent = $(sRel + 'Content');
		oLightBoxOverlay = $(sRel + 'Overlay');

		new Request.HTML(
		{
			url: sUrl,
			update: oLightBoxContent,
			method: 'post',
			data: {'ajax': 1},
			onSuccess: this.setEvents.bind(this),
			async: false
		}).send();

		oLightBoxOverlay.setStyle('display', 'block');
		oLightBox.setStyle('display', 'block');
		oLightBoxOverlay.fade(0.8);
		oLightBox.fade('in');


		return false;
	},

	hideLightbox: function(oEvent)
	{

		sRel = oEvent.target.get('rel');
		oLightBox = $(sRel);
		oLightBoxOverlay = $(sRel + 'Overlay');


		oLightBoxOverlay.fade('out');
		oLightBox.fade('out');
		oLightBoxOverlay.setStyle('display', 'none')
		oLightBox.setStyle('display', 'none')

		return false;
	},

	showImage: function(oEvent)
	{
		this.fade('in');
	}
}
);

ambience_imageInit = function()
{
	ambience_imageObj = new ambience_imageClass();
}

var ambience_imageObj;

window.addEvent('domready', ambience_imageInit);
