var regThumbnail = new RegExp("tn-", "g");
var regDiese = new RegExp("#", "g");
var regVideoInfo = "^(.*)###(.*)#([0-9]*)#([0-9]*)$";
function moreText(whichdiv)
{
	$('moreText1').style.display = whichdiv=='moreText2' ? 'none' : '';
	$('moreText2').style.display = whichdiv=='moreText2' ? '' : 'none';
}
function closeVideo()
{
	$('graphTable').setOpacity(1);
	$('graphTableImg').setOpacity(1);
	$('videoViewer').style.display='none';
	$('videoViewer').innerHTML = '';
}
// Galerie Video
function loadGalerie(which)
{
	switch(which)
	{
		case 'graph-2d-3d':
			imgGallery = $$('#videoContent .imgLittle');
			imgGallery.each(function(img, iimg)
			{
				ufvideoClick = function(ev)
				{
					if(ev) new Event(ev).stop();
					// chargement video
					var regvideo = new RegExp(regVideoInfo);
					var m = regvideo.exec(this.getProperty('data'));
					var regextfvl = new RegExp("\.flv$", "g");
					
					$('videoViewer').style.left = ($('videoContent').getLeft().toInt()+70) + 'px';
					$('videoViewer').style.top = ($('videoContent').getTop().toInt()-m[4]-70) + 'px';
					$('graphTable').setOpacity(0.2);
					$('graphTableImg').setOpacity(0.2);
					$('videoViewer').setOpacity(0);
					
					var str = '';
					str = '';
					str += '<table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="2">';
					str += '<object id="videoViewerObj" class="" type="application/x-shockwave-flash" data="/flvplayer.swf" width="'+m[3]+'" height="'+m[4]+'">';
					str += '<param name="movie" value="/flvplayer.swf" />';
					str += '<param name="allowFullScreen" value="false" />';
					str += '<param name="FlashVars" value="flv='+m[2]+'&amp;width='+m[3]+'&amp;height='+m[4]+'&amp;margin=0&amp;showplayer=always&amp;autoplay=1&amp;loop=1" />';
					str += '</object></td></tr>';
					str += '<tr><td class="f fs11"><a href="#" onClick="closeVideo();">Fermer</a></td>';
					str += '<td align="right" class="f fs11"><a href="'+m[2].replace(regextfvl, '.avi')+'">Télécharger la vidéo</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(codec <a href="/data/video/xvid.exe">Xvid</a>)</td>';
					str += '</tr></table>';
					$('videoViewer').innerHTML = str;
					$('videoViewer').style.display = '';
					
					$('videoViewer').effect('opacity', {wait: true, duration: 400}).start(0, 1);
				}
				img.addEvent("click", ufvideoClick);
				//--------------------------------------
				ufvideoLogIn = function(ev)
				{
					if(ev) new Event(ev).stop();
					if(this.getProperty('data')!='')
					{
						var regvideo = new RegExp(regVideoInfo, "g");
						var m = regvideo.exec(this.getProperty('data'));
						$('videoLog').innerHTML = m[1];
					}
				}
				img.addEvent("mouseenter", ufvideoLogIn);
				//--------------------------------------
				ufvideoLogOut = function(event)
				{
					$('videoLog').innerHTML = '';
				}
				img.addEvent("mouseleave", ufvideoLogOut);
			})
			// initialisation - image de chargement
			imgGallery = $$('#graphContent .imgLittle');
			imgGallery.each(function(img, iimg)
			{
				ufgraphClick = function(ev)
				{
					// stop default event
					if(ev)	new Event(ev).stop();
					// arret video avant
					if($('videoViewer').style.display == '' && $('videoViewerObj'))
						$('videoViewerObj').SetVariable("player:jsStop", "");
					$('videoViewer').style.display = 'none';
					$('graphTable').setOpacity(1);
					$('graphTableImg').setOpacity(1);
					$('graphViewer').setOpacity(0);
					$('graphViewer').style.display = '';
					
					// chargement de l'image
					$('graphViewer').src = img.src.replace(regThumbnail, '');
					
					selimg = $$('#graphContent .imgSelected');
					selimg.each(function(other, iother)
					{
						other.removeClass('imgSelected');
					})
					img.addClass('imgSelected');
					// on arrete affichage image
					$('graphViewer').setOpacity(1);
				}
				img.addEvent("click", ufgraphClick);
			})
			// chargement de la premiere ligne
			if(imgGallery.length>0)
				imgGallery[0].fireEvent('click');
			break;
		//------------------------------------------------------------------
		case 'multimedia':
			// initialisation - image de chargement
			imgGallery = $$('#multimediaContent .imgLittle');
			imgGallery.each(function(img, iimg)
			{
				ufgraphClick = function(ev)
				{
					if(ev)
						new Event(ev).stop();
					$('multimediaViewer').setOpacity(0);
					
					// chargement de l'image
					$('multimediaViewer').src = img.src.replace(regThumbnail, '');
					
					selimg = $$('#multimediaContent .imgSelected');
					selimg.each(function(other, iother)
					{
						other.removeClass('imgSelected');
					})
					img.addClass('imgSelected');
					
					// on arrete affichage image
					$('multimediaViewer').setOpacity(1);
					$('multimediaLog').innerHTML = img.getProperty('data').replace(regDiese, '<br>');
				}
				img.addEvent("click", ufgraphClick);
			})
			// chargement de la premiere ligne
			if(imgGallery.length>0)
				imgGallery[0].fireEvent('click');
			break;
	}
}