var AlbumPage = new Class({
	
	bkg_path: "./assets/images/visus/",
	
	Implements: [Options, Events],
	options:{
		imagename: "simple.jpg",
		other_imagename: "homme.jpg"
	},
	
	initialize:function(options) {
		this.setOptions(options);
		debug('AlbumPage:initialize');
		
//		$('content').setStyle('overflow', 'visible');
//		$$('.type_page')[0].setStyle('overflow-x', 'hidden');
		this.nav_albums = $$('.nav_albums')[0];
		
		this.nav_album_fx = new Fx.Morph(this.nav_albums, {
			transition: Fx.Transitions.Quad.easeOut,
			link:'cancel'
		});
		
		this.nav_album_fx_src = {
			'top':this.nav_albums.getCoordinates(this.nav_albums.getParent()).top,
			'opacity': 1
		};
		
		this.nav_album_fx_dest = {
			'top':this.nav_album_fx_src.top + 30,
			'opacity': 0
		};
		
		this.addEvent('goto', this.goto.bind(this));
		
		this.boutons = new Array();
		this.bouton = null;
		this.nav_albums.getElements('a').each(function(el) {
			var url = ""
			url = el.href;
			var gets = getGets(url);
			el.addEvent('click', function(e) {
				e.stop();
				if(gets) this.fireEvent('goto', {alb: gets.alb});
			}.bind(this));
			this.boutons[gets.alb] = el;
		}, this);
		
	},
	
	goto:function(e) {
		if(this.bouton) this.bouton.removeClass('select');
		if(this.album) {
			this.album.addEvent('destroy', function() {
				debug('goto:destroy');
				this.initAlbum(e);
			}.bind(this));
			this.album.close();
		}	
		else {
			this.initAlbum(e);
		}
	},
	
	initAlbum:function(e) {
		this.album = new Album({
			alb: e.alb
		});
		this.album.addEvents({
			'deploy':function() {
				this.navAlbumClose();
			}.bind(this),
			'closeBig':function() {
				this.navAlbumOpen();
			}.bind(this) 
		});
		this.bouton = this.boutons[e.alb];
		this.bouton.addClass('select');
		loader.open();
	},
	
	navAlbumClose:function() {
		this.nav_album_fx.start(this.nav_album_fx_dest);
	},
	
	navAlbumOpen:function() {
		this.nav_album_fx.start(this.nav_album_fx_src);
	},
	
	close:function() {
		this.album.close();
	}
});
