Event.observe(window, 'load',

      function() {
		var currentSlidedRightBlocEl = null;
		

	  	
		if ($('rb_el_lastvideo_content')) {
			Effect.toggle('rb_el_lastvideo_content', 'blind', { duration: 1 });
			currentSlidedRightBlocEl = 'rb_el_lastvideo';	
			$('rb_el_lastvideo_content').style.cursor='default';
		}

			
	  	$$('.videotheque_rb_el .title').each(function(s, index){
			if ($(s.id + '_content')) {
				Event.observe($(s.id), 'click', function(e){
					if (currentSlidedRightBlocEl != s.id) {
						if (currentSlidedRightBlocEl != null) {
							Effect.toggle(currentSlidedRightBlocEl + '_content', 'blind', {
								duration: 1
							});
							$(currentSlidedRightBlocEl + '_ploy').src = '/images/ploy.gif';
						}
						Effect.toggle(s.id + '_content', 'blind', {
							duration: 1
						});
						$(s.id + '_ploy').src = '/images/dploy.gif';
						$(currentSlidedRightBlocEl + '_content').style.cursor = 'pointer';
						currentSlidedRightBlocEl = s.id;
						$(currentSlidedRightBlocEl + '_content').style.cursor = 'default';
					}
				});
			}
		});
		
		init_videotheque();
	}
);

function init_videotheque() {
	init_videolist_tag_relocator();
	init_videolist_chaine_relocator();
	init_video_relocator();
	init_chaine_relocator();
	init_videolist_memetheme_relocator();
	init_videolist_lastvideo_relocator();
	init_videolist_search_relocator();
	init_lastvideo_relocator();
	init_videobloc_tag_relocator();
	init_listvideo_page_relocator();
	init_videolist_memearticle_relocator();
}


function init_listvideo_page_relocator() {
	$$('.link_listvideo_nav').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				listvideo_page_relocate(s.rel);
		});
	});
}

function listvideo_page_relocate(id) {
	$('videotheque_videolist_waiter').style.display='block';
	$('listmovie').style.display='none';
	new Ajax.Request($('listmovie_url').value+'/page/'+id,{
					onComplete: function(transport)
					{
							$('videolistbloc').innerHTML=transport.responseText;
							$('videolistbloc').innerHTML.evalScripts();
							 init_video_relocator();
					}
				});
}


function init_lastvideo_relocator()
{
	$$('.link_lastvideo_nav').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				lastvideo_relocate(s.rel);
		});
	});
}

function lastvideo_relocate(id)
{
	$('videotheque_lastvideolist_waiter').style.display='block';
	$('listlastvideo').style.display='none';
	new Ajax.Request('/videotheque/rightbloc/lastvideo/mode/ajax/lastvideopage/'+id,{
					onComplete: function(transport)
					{
							$('lastvideobloc').innerHTML=transport.responseText;
							$('lastvideobloc').innerHTML.evalScripts();
							 init_lastvideo_relocator();
							 init_videolist_lastvideo_relocator();
					}
				});
}

function init_videolist_search_relocator()
{
	if($('video_search_btn'))
	{
		$('video_search_btn').observe('click',
		function(event)
			{
				Event.stop(event);
				videolist_search_relocate($('video_search_input').value);
				window.location='#videolistbloc';
			});
	}
}

function videolist_search_relocate(id)
{
	$('videotheque_videolist_waiter').style.display='block';
	$('listmovie').style.display='none';
	new Ajax.Request('/videotheque/index/searchresult/mode/ajax/key/'+id,{
					onComplete: function(transport)
					{
							$('videolistbloc').innerHTML=transport.responseText;
							$('videolistbloc').innerHTML.evalScripts();
							 init_video_relocator();
					}
				});
}


function init_videolist_tag_relocator()
{
	$$('.tagcloud .tag').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				videolist_tag_relocate(s.rel);
				window.location='#videolistbloc';
		});
	});
}

function init_videobloc_tag_relocator()
{
	$$('#videobloc .tag').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				videolist_tag_relocate(s.rel);
				window.location='#videolistbloc';
		});
	});
}

function videolist_tag_relocate(id)
{
	$('videotheque_videolist_waiter').style.display='block';
	$('listmovie').style.display='none';
	new Ajax.Request('/videotheque/index/tagresult/mode/ajax/tag/'+id,{
					onComplete: function(transport)
					{
							$('videolistbloc').innerHTML=transport.responseText;
							$('videolistbloc').innerHTML.evalScripts();
							 init_video_relocator();
					}
				});
}

function init_videolist_lastvideo_relocator()
{
	$$('.listlastvideo .lastvideo').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				video_relocate(s.rel);
				videolist_chaine_relocate(s.name,false,s.rel);
				window.location='#videobloc';
		});
	});
}

function init_video_relocator()
{
	$$('.videolist .video').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				video_relocate(s.rel);
				window.location='#videobloc';
		});
	});
	init_listvideo_page_relocator();
}


function video_relocate(id)
{
	$('videotheque_video_waiter').style.display='block';
	$('videotheque_video').style.display='none';
	new Ajax.Request('/videotheque/index/video/mode/ajax/video/'+id,{
					onComplete: function(transport)
					{
							$('videobloc').innerHTML=transport.responseText;
							$('videobloc').innerHTML.evalScripts();
							 init_videolist_memetheme_relocator();
							 init_videobloc_tag_relocator();
							 init_videolist_memearticle_relocator();
					}
				});
}

function init_chaine_relocator()
{
	$$('.link_chaine_nav').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				chaine_relocate(s.rel);
		});
	});
	if($('chaine_relocate'))//init du select de navigation dans les vidéos
	{
		Event.observe($('chaine_relocate'),'change',
		function(event)
			{
				Event.stop(event);
				chaine_relocate(1,$('chaine_relocate').value);
			});
	}
}

function chaine_relocate(id)
{
	if(arguments.length>1) site=arguments[1]; 
	else site=$('chaine_relocate').name;
	
	$('videotheque_chainelist_waiter').style.display='block';
	$('listchaine').style.display='none';
	new Ajax.Request('/videotheque/rightbloc/bychaine/mode/ajax/chaine/'+site+'/chainepage/'+id,{
					onComplete: function(transport)
					{
							$('bychainebloc').innerHTML=transport.responseText;
							$('bychainebloc').innerHTML.evalScripts();
							 init_chaine_relocator();
							 init_videolist_chaine_relocator();
					}
				});
}

function init_videolist_chaine_relocator()
{
	$$('.listchaine .chaine').each(function(s, index)
	{
		s.observe('click',function(event)
		{
				Event.stop(event);
				videolist_chaine_relocate(s.rel);
				window.location='#videolistbloc';
		});
	});
}

function videolist_chaine_relocate(id) //deuxieme argument, true ou false, pour recharger la video ou pas, troisieme argument enleve la vidéo de cet id de la liste.
{
	var reloadVideo='';
	var dontShowVideo='';
	if(arguments.length>1)
		reloadVideo='/reloadVideo/'+arguments[1];
	if(arguments.length>2)
		dontShowVideo='/dontShowVideo/'+arguments[2];
	
	$('videotheque_videolist_waiter').style.display='block';
	$('listmovie').style.display='none';
	new Ajax.Request('/videotheque/index/chaineresult/mode/ajax/article/'+id+reloadVideo+dontShowVideo,{
					onComplete: function(transport)
					{
							$('videolistbloc').innerHTML=transport.responseText;
							$('videolistbloc').innerHTML.evalScripts();
							 init_video_relocator();
					}
				});
}

function init_videolist_memetheme_relocator()
{
	if ($('allThemeShowLink')) {
		$('allThemeShowLink').observe('click', function(event){
			Event.stop(event);
			videolist_memetheme_relocate($('allThemeShowLink').rel);
			window.location = '#videolistbloc';
		});
	}
}

function init_videolist_memearticle_relocator()
{
	if ($('sameArticleShowLink')) {
		$('sameArticleShowLink').observe('click', function(event){
			Event.stop(event);
			videolist_chaine_relocate($('sameArticleShowLink').rel,false,$('sameArticleShowLink').name);
			window.location = '#videolistbloc';
		});
	}
}

function videolist_memetheme_relocate(id)
{
	$('videotheque_videolist_waiter').style.display='block';
	$('listmovie').style.display='none';
	new Ajax.Request('/videotheque/index/memethemeresult/mode/ajax/video/'+id,{
					onComplete: function(transport)
					{
							$('videolistbloc').innerHTML=transport.responseText;
							$('videolistbloc').innerHTML.evalScripts();
							 init_video_relocator();
					}
				});
}
