YUI().use('anim', 'node-event-simulate', 'io-base', 'event-key', function(Y){
	Y.on('io:complete', function (id, e) {
		Y.one('#photogallery-container').insert('<div id="photogallery-button-close"></div>'); 
		Y.one('#photogallery-container').insert('<div id="photogallery-shadow-top-left"></div>'); 
		Y.one('#photogallery-container').insert('<div id="photogallery-shadow-top-right"></div>');  
		Y.one('#photogallery-container').insert('<div id="photogallery-shadow-bottom-left"></div>'); 
		Y.one('#photogallery-container').insert('<div id="photogallery-shadow-bottom-right"></div>');
		Y.one('#photogallery-container').insert(e.responseText);
		Y.one('#photogallery-container').setX(Y.one('body').get('winWidth') / 2 - Y.one('#photogallery-container object').get('width') / 2);
		Y.one('#photogallery-container').setY(Y.one('body').get('docScrollY') + Y.one('body').get('winHeight') / 2 - Y.one('#photogallery-container object').get('height') / 2);
		Y.one('#photogallery-container').setStyle('width', Number(Y.one('#photogallery-container object').get('width')) + 16);
		Y.one('#photogallery-container').setStyle('height', Number(Y.one('#photogallery-container object').get('height')) + 16);
		Y.one('#photogallery-container').setStyle('visibility', 'visible');
		
		Y.one('#photogallery-button-close').on('click', function(e) {
			Y.one('#photogallery-overlay').simulate('click');
		});

	}, Y);

	Y.all('a.videogallery').on('click', function(e) {
		Y.one('#photogallery-overlay').setStyle('opacity', 0);
		Y.one('#photogallery-overlay').setStyle('width', Y.one('body').get('docWidth'));
		Y.one('#photogallery-overlay').setStyle('height', Y.one('body').get('docHeight'));
		Y.one('#photogallery-overlay').setStyle('display', 'block');
		Y.one('#photogallery-container').setStyle('visibility', 'hidden');
		Y.one('#photogallery-container').setStyle('display', 'block');
		
		var anim = new Y.Anim({
			node: '#photogallery-overlay',
			to: {opacity: .5},
			duration: .25,
			easing: Y.Easing.easeIn
		});
		anim.run();
		
		Y.io(e.currentTarget.get('href'));
		
		e.preventDefault();
	});

	Y.one('#photogallery-overlay').on('click', function(e) {
		var anim = new Y.Anim({
			node: '#photogallery-overlay',
			to: {opacity: 0},
			duration: .25,
			easing: Y.Easing.easeOut
		});
		anim.run();
		
		Y.one('#photogallery-container').set('innerHTML', '');
		Y.one('#photogallery-container').setStyle('display', 'none');
		
		anim.on('end', function(e) {
			Y.one('#photogallery-overlay').setStyle('display', 'none');
		});
	});
	
	Y.on('key', function(e) {
        Y.one('#photogallery-overlay').simulate('click');
    }, window, 'down:27', Y);	

});

