var global = [];

var manager = {
	
	start:function(){	
		
		global.wpurl = $$('link[rel=index]')[0].href;
		
		if($('video')) manager.modules.video.init();
		if($('music')) manager.modules.music.init();
		if($('newsletter')) manager.modules.newsletter.init();
		if($$('body.photographies')[0]) manager.modules.gallery.init();
		
	},
	
	modules:{
	
		video:{
		
			init:function(){
				
				if(document.body.className == 'biographie'){
					manager.modules.video.biography.init();
					return;
				}
				
				manager.modules.video.homepage.init();
				
			},
				
			play:function(vimeo_id){
					
				var flashvars = {
					clip_id: vimeo_id,
					show_portrait: 0,
					show_byline: 0,
					show_title: 0,
					autoplay: 1,
					color:'92EF00',
					fullscreen:1,
					hd_off:0,
					js_api: 1,
					js_onLoad: 'vimeo_player_loaded'
				};
				var attributes = {class:vimeo_id};
				var params = {allowfullscreen:'true',allowscriptaccess:'always',wmode:'opaque'};
				swfobject.embedSWF('http://vimeo.com/moogaloop.swf', 'video', '970', '370', '9.0.0', global.wpurl+'/wp-content/themes/ericb/expressInstall.swf', flashvars, params, attributes);
									
			},
			
			homepage:{
			
				init:function(){
								
					with($('video').style){cursor='pointer';background='url('+global.wpurl+'/wp-content/themes/ericb/img/eric-belanger-play.jpg) top left no-repeat #FFFFFF';}
					$('video').onclick = function(vimeo_id){manager.modules.video.play($$('h1#video')[0].className);}
				
				},
				
				finish:function(){
				
					var vimeo_id = $('video').className;
					$('video').destroy();
					
					var h1 = document.createElement('h1');
					h1.id = 'video';
					h1.className = vimeo_id;
					var txt = document.createTextNode('Eric Bélanger');
					h1.appendChild(txt);					
					$$('.video-container')[0].appendChild(h1);
					
					manager.modules.video.homepage.init();
					
				}
			
			},
			
			biography:{
				
				init:function(){
								
					with($('video').style){cursor='pointer';background='url('+global.wpurl+'/wp-content/themes/ericb/img/biographie-play.jpg) top left no-repeat #FFFFFF';}
					$('video').onclick = function(vimeo_id){manager.modules.video.play($$('h1#video')[0].className);}
				
				},
				
				finish:function(){
				
					var vimeo_id = $('video').className;
					$('video').destroy();
					
					var h1 = document.createElement('h1');
					h1.id = 'video';
					h1.className = vimeo_id;
					var txt = document.createTextNode('Biographie d\'Eric Bélanger');
					h1.appendChild(txt);					
					$$('.video-container')[0].appendChild(h1);
					
					manager.modules.video.biography.init();
					
				}
			
			}
		
		},
		
		gallery:{
		
			init:function(){
			
				var flashvars = {};
				flashvars.galleryURL = global.wpurl+'/wp-content/themes/ericb/gallery/gallery.xml';
				var params = {};			
				params.allowfullscreen = true;
				params.allowscriptaccess = 'always';
				params.bgcolor = 'FFFFFF';
				swfobject.embedSWF(global.wpurl+'/wp-content/themes/ericb/gallery/simpleviewer.swf', 'gallery', '100%', '500', '9.0.124', global.wpurl+'/wp-content/themes/ericb/expressInstall.swf', flashvars, params);
				
			}
		
		},
		
		music:{
		
			init:function(){
				
				AudioPlayer.setup(global.wpurl+'/wp-content/themes/ericb/mp3/player.swf',{width:142,initialvolume:50,loader:'9EBE03'});
				AudioPlayer.embed('player-001',{soundFile:global.wpurl+'/wp-content/themes/ericb/mp3/nous.mp3',titles:'Nous',artists:'Eric Belanger'});
				AudioPlayer.embed('player-002',{soundFile:global.wpurl+'/wp-content/themes/ericb/mp3/tu_es.mp3',titles:'Tu es',artists:'Eric Belanger'});
				AudioPlayer.embed('player-003',{soundFile:global.wpurl+'/wp-content/themes/ericb/mp3/en_equilibre.mp3',titles:'En équilibre',artists:'Eric Belanger'});
				
			}
		
		},
		
		newsletter:{
		
			init:function(){
				$('mail').text =  $('mail').value;
				$('mail').onfocus = function(){if(this.value == this.text) this.value = '';}
				$('mail').onblur = function(){if(this.value == '') this.value = this.text;}
			}
		
		}
	
	}
	
};

function vimeo_player_loaded(){$('video').api_addEventListener('onFinish', 'vimeo_on_finish');}

function vimeo_on_finish(){
	if(document.body.className == 'biographie') manager.modules.video.biography.finish();
	else manager.modules.video.homepage.finish();
}

window.addEvent('domready', manager.start);
