//config
JSGALERY = {};
JSGALERY.MODE_GALERY = 'GALERY';
JSGALERY.MODE_PHOTO = 'PHOTO';

JSGALERY.PHOTO_FRAME_SELECTOR = '.photo_frame';
JSGALERY.PHOTO_FRAME_BG_COLOR = '#F5F5F5';
JSGALERY.PHOTO_FRAME_BG_COLOR_OVER = '#333';
JSGALERY.PHOTO_FRAME_COLOR = '#444';
JSGALERY.PHOTO_FRAME_COLOR_OVER = '#fff';
JSGALERY.GALERIE_PHOTOS_FRAME_ID = 'galerie_photos_window';
JSGALERY.GALERIE_PHOTOS_CONTAINER_FRAME_ID = 'galerie_photos_window_content';
JSGALERY.GALERIE_PHOTOS_GALERIE_VIEW_FRAME_ID = 'galerie_photos_window_galerie_view';
JSGALERY.GALERIE_PHOTOS_PHOTO_VIEW_FRAME_ID = 'galerie_photos_window_photo_view';
JSGALERY.MASKLAYER_BG_COLOR = 'black';
JSGALERY.MASKLAYER_OPACITY = 0.7;
JSGALERY.MASKLAYER_ZINDEX = 500;


var maskLayer;

function initGalery(mode)
{
	JSGALERY.MODE = mode;
	maskLayer = new Element('DIV', {'id': 'jsGaleryMask', 'class': 'hidden'});
	maskLayer.injectTop(document.body);
	maskLayer.setStyles({'z-index': JSGALERY.MASKLAYER_ZINDEX, 'opacity': JSGALERY.MASKLAYER_OPACITY, 'background-color': JSGALERY.MASKLAYER_BG_COLOR, 'position': 'absolute'});
	maskLayer.addEvent('click', fermerGalerie);
	
	$(JSGALERY.GALERIE_PHOTOS_FRAME_ID).getParent().setStyle('z-index', JSGALERY.MASKLAYER_ZINDEX + 1);
}

function makePhotoFramesInteractive(selector) 
{
	$$(selector).each(function(element) {
	 	element.setStyles({'cursor': 'pointer', 'background-color': JSGALERY.PHOTO_FRAME_BG_COLOR, 'color': JSGALERY.PHOTO_FRAME_COLOR });
	 	
		var fx = new Fx.Styles(element, {duration:400, wait:false});
	 
		element.addEvent('mouseenter', function(){
			fx.start({
				'background-color': JSGALERY.PHOTO_FRAME_BG_COLOR_OVER,
				'color': JSGALERY.PHOTO_FRAME_COLOR_OVER
			});
		});
	 
		element.addEvent('mouseleave', function(){
			fx.start({
				'background-color': JSGALERY.PHOTO_FRAME_BG_COLOR,
				'color': JSGALERY.PHOTO_FRAME_COLOR
			});
		});
	 
	});
}

function montrerGalerie()
{
	maskLayer.setStyles({'width': window.getSize().scrollSize.x, 'height': window.getSize().scrollSize.y});
	maskLayer.removeClass('hidden');
	$(JSGALERY.GALERIE_PHOTOS_FRAME_ID).removeClass('hidden');
}

function ouvrirGalerie(id_galerie)
{
	new Ajax(base_url + '/galerie_photos/id_galerie=' + id_galerie, {
		method: 'get',
		update: $(JSGALERY.GALERIE_PHOTOS_CONTAINER_FRAME_ID),
		onSuccess: function() {
			window.scrollTo(0, 0);
			montrerGalerie();
			makePhotoFramesInteractive('#' + JSGALERY.GALERIE_PHOTOS_FRAME_ID + ' ' + JSGALERY.PHOTO_FRAME_SELECTOR)		
		}
	}).request();
}

function fermerGalerie()
{
	fermerPhoto();
	maskLayer.addClass('hidden');
	$(JSGALERY.GALERIE_PHOTOS_FRAME_ID).addClass('hidden');
}

function ouvrirPhoto(id_photo)
{
	new Ajax(base_url + '/galerie_photo/id_photo=' + id_photo + '&mode=' + JSGALERY.MODE, {
		method: 'get',
		update: $(JSGALERY.GALERIE_PHOTOS_PHOTO_VIEW_FRAME_ID),
		evalScripts: true,
		onSuccess: function() {
			window.scrollTo(0, 0);
			if (JSGALERY.MODE == JSGALERY.MODE_GALERY)
				$(JSGALERY.GALERIE_PHOTOS_GALERIE_VIEW_FRAME_ID).addClass('hidden');
			$(JSGALERY.GALERIE_PHOTOS_PHOTO_VIEW_FRAME_ID).removeClass('hidden');
			if (JSGALERY.MODE == JSGALERY.MODE_PHOTO)
				montrerGalerie();
		}
	}).request();
}

function fermerPhoto()
{
	if (JSGALERY.MODE == JSGALERY.MODE_GALERY)
		$(JSGALERY.GALERIE_PHOTOS_GALERIE_VIEW_FRAME_ID).removeClass('hidden');
	$(JSGALERY.GALERIE_PHOTOS_PHOTO_VIEW_FRAME_ID).addClass('hidden');
}


/*JSGALERY = {};

JSGALERY.Picture = new Class(
{
	initialize: function(thumb, zoom, title, description)
	{
		this.thumb = thumb;
		this.zoom = zoom;
		this.title = title;
		this.description = description;
	}
});

JSGALERY.Galery = new Class(
{
	/**
	 * Default options
	 * /
	options:
	{
		thumbnailElement: null,
		zoomElement: null,
		zoomImageElement: null,
		zoomTitleElement: null,
		zoomDescElement: null,
		zoomButton: null,
		zoomCloseButton: null,
		previousPictureElement: null,
		nextPictureElement: null,
		thumbnailClass: 'interactiveImage',
		thumbnailOverClass: 'interactiveImageOver',
		maskLayer: true,
		maskLayerOpacity: 0.6,
		maskLayerBackgroundColor: 'black',
		effectDuration: 400,
		hideSelectFields: true
	},
		
	initialize: function(options)
	{
		this.setOptions(options);
		
		this.pictures = $A([]);
		
		this.thumbnailElement = $(this.options.thumbnailElement);
		this.thumbnailElement.addEvent('click', this.showZoom.bind(this));
		if ($defined(this.options.zoomButton))
			this.options.zoomButton.addEvent('click', this.showZoom.bind(this));

		this.zoomElement = $(this.options.zoomElement);
		this.zoomImageElement = $(this.options.zoomImageElement);
		this.zoomImageElement.addEvent('click', this.hideZoom.bind(this));
		this.zoomTitleElement = $(this.options.zoomTitleElement);
		this.zoomDescElement = $(this.options.zoomDescElement);
		
		this.zoomFx = new Fx.Styles(this.zoomElement, {duration: this.options.effectDuration});

		if ($defined(this.options.previousPictureElement))
			this.options.previousPictureElement.addEvent('click', this.previousPicture.bind(this));
		if ($defined(this.options.nextPictureElement))
			this.options.nextPictureElement.addEvent('click', this.nextPicture.bind(this));
		if ($defined(this.options.zoomCloseButton))
			this.options.zoomCloseButton.addEvent('click', this.hideZoom.bind(this));


		this.hideZoom();
		
		if (this.options.maskLayer)
		{
			this.maskLayer = new Element('DIV', {'id': 'jsGaleryMask'});
			this.maskLayer.injectTop(document.body);
			this.maskLayer.setStyles({'opacity': this.options.maskLayerOpacity, 'background-color': this.options.maskLayerBackgroundColor, 'position': 'absolute'});
			this.maskLayer.addEvent('click', this.hideZoom.bind(this));
		}
	},
	
	addPicture: function(picture)
	{
		this.pictures.include(picture);
	},
	
	drawThumbnail: function()
	{
		if ($defined(this.thumbnailElement))
		{
			this.pictures.each(function(picture) 
			{
				// add image to thumbnail
				var imgElement = new Element('img', {'src': picture.thumb, 'class': 'clickable ' + this.options.thumbnailClass, 'title': picture.title});
				imgElement.injectInside(this.thumbnailElement);
				
				imgElement.addEvent('click', function() { this.selectPicture(picture); }.bind(this));
				imgElement.addEvent('mouseenter', function () { imgElement.addClass(this.options.thumbnailOverClass); }.bind(this) );
				imgElement.addEvent('mouseleave', function () { imgElement.removeClass(this.options.thumbnailOverClass); }.bind(this) );
			}, this);
		}
		this.selectPicture(this.pictures[0]);
	},
	
	selectPicture: function (picture)
	{
		this.currentPicture = picture;
		
		this.zoomImageElement.src = picture.zoom;

		if ($defined(this.options.zoomTitleElement))
			this.options.zoomTitleElement.setText(picture.title);

		if ($defined(this.options.zoomDescElement))
			this.options.zoomDescElement.setText(picture.description);
	},

	getCurrentPicturePosition: function()
	{
		var currentPicturePos = null;
		this.pictures.each(function(pic, index) { if (pic == this.currentPicture) currentPicturePos = index;}, this);
		return currentPicturePos;
	},
	
	previousPicture: function ()
	{
		var currentPicturePos = this.getCurrentPicturePosition();
		if (currentPicturePos == 0) 
			this.selectPicture(this.pictures[this.pictures.length - 1]);
		else
			this.selectPicture(this.pictures[currentPicturePos - 1]);
	},

	nextPicture: function ()
	{
		var currentPicturePos = this.getCurrentPicturePosition();
		if (currentPicturePos + 1 == this.pictures.length) 
			this.selectPicture(this.pictures[0]);
		else
			this.selectPicture(this.pictures[currentPicturePos + 1]);
	},

	showZoom: function()
	{
		if (!this.zoomElement.hasClass('hidden'))
		{
			this.hideZoom();
		}
		else
		{
			if (this.options.hideSelectFields)
				$$('select').addClass('hidden'); // IE6 fix

			if ($defined(this.maskLayer))
			{
				this.maskLayer.setStyles({'width': window.getSize().scrollSize.x, 'height': window.getSize().scrollSize.y});
				this.maskLayer.removeClass('hidden');
			}
			this.zoomElement.setOpacity(0);
			this.zoomElement.removeClass('hidden');
			this.zoomFx.start({'opacity': 1});
		}
	},
	
	hideZoom: function(picture)
	{
		if (this.options.hideSelectFields)
			$$('select').removeClass('hidden'); // IE6 fix
		
		if ($defined(this.maskLayer))
			this.maskLayer.addClass('hidden');
		this.zoomElement.addClass('hidden');
	}
});
JSGALERY.Galery.implement(new Options);

*/