var MiniGallery2 = new Class({
	
	initialize: function() {
		var galleries = $$('div.minigal');
		galleries.each(function(gallery) {
			var btn = gallery.getFirst();
			var gal = btn.getNext();
			var more = new Element('img', {
					src: 'assets/templates/mfhs3/images/fler.png',
					styles: {
						'position': 'absolute',
						'right': 0,
						'top': btn.getCoordinates($('wrap')).bottom - 20,
						'border': 'none',
						'cursor': 'pointer'
					}
			});
			more.addEvent('click', function() {
				if (gal.getStyle('display') == 'block') {
					gal.setStyle('display', 'none');
				} else {
					gal.setStyles({
						'display': 'block',
						'top': btn.getTop()
					});
				}
			});
			more.injectAfter(btn);
	
			btn.addEvents({
				click: function(ev){
					if (gal.getStyle('display') == 'block') {
						gal.setStyle('display', 'none');
					} else {
						gal.setStyles({
							'display': 'block',
							'top': btn.getTop() - 100
						});
					}
					ev.stopPropagation();
				},
				mouseover: function() {
					btn.setStyle('cursor', 'pointer');
				}
			});
			
			gal.setStyles({
				'position': 'absolute',
				'display': 'none',
				'right': btn.getWidth() + 25,
				'float': 'right'
			});
			
			$$('body').addEvent('click', function() {
				gal.setStyle('display', 'none');
			});
			
			gal.getChildren().each(function(el){
				if (el.get('tag') == 'a') {
					el.addEvent('click', function(ev) {
						ev.stopPropagation();
					});
				}
			});			
			
		});
		
	}
});

window.addEvent('domready', function () {
	var mg2 = new MiniGallery2();
});
