/*
//----------------------------------------------------------------------------------------------------
var agt = navigator.userAgent.toLowerCase(); 
var appVer = navigator.appVersion.toLowerCase();
if ((appVer.indexOf('msie') != -1) && (agt.indexOf('mac')!=-1)) { 
	alert('Sorry, this application requires Netscape on the Macintosh Platform.'); top.close();
}
var is_nav = ((agt.indexOf('mozilla')!=-1) && 
              (agt.indexOf('spoofer')==-1) && 
              (agt.indexOf('compatible') == -1) && 
              (agt.indexOf('opera')==-1) && 
              (agt.indexOf('webtv')==-1)); 
var is_ie   = (agt.indexOf('msie') != -1); 
//----------------------------------------------------------------------------------------------------
*/
var sector =-1 
var curtime =-1;
var lastime =-1;
var lastsector =-1;
var synchro = true;

//----------------------------------------------------------------------------------------------------
// 
//----------------------------------------------------------------------------------------------------
function video_init () {

	// lance le preload au bout de 3 secondes
	if (slide_path != '') 
		setTimeout("slide_preload()",3000);
	else
		hide('div_slide');

	// controle s'il faut se déplacer ( chapitre passé en paramètre )
	if (video_index != -1) {
		if (video_chapters[video_index]==undefined) 
			alert('Chapitre invalide');
		else {
			where = video_chapters[video_index].split('|');
			move(eval(where[0]/1000));
		}
	}
	
	if (synchro) {
		// active la synchronisation toutes les 1/2 secondes
		setInterval('video_synchro()',500);
	}
}
//----------------------------------------------------------------------------------------------------
// synchronisation "mécanique" de la vidéo et des chapitres
//----------------------------------------------------------------------------------------------------
function video_synchro () { 

	// récupère la position courante de la vidéo
	var curtime = video_position();

	// si la position a changé
	if (curtime != lastime) { 

		// trouve dans quel index on se trouve 
		video_index = 0;
		for (var i = 0; i < video_chapters.length ; i++){ 
			timecode = video_chapters[i].split('|'); 
			if ( curtime >= eval(timecode[0]) ) {
				video_index = i;
			}
		}
		lastime = curtime;
		
		// ok, trouvé
		timecode = video_chapters[video_index].split('|');
		sector = timecode[0];
		slide = timecode[1];
		
		// affiche le slide correspondant
		if ( lastsector != sector ) {
			
			// déplace les chapitres
			// affiche Slide s'il y en a

			chapter_scroll();
			//video_index++;
		}
	} // if (curtime != sector)
	//document.title = lastsector +' / '+ sector ;
}
//----------------------------------------------------------------------------------------------------
// 
//----------------------------------------------------------------------------------------------------
function chapter_scroll () {


	// check 
	
	lastsector = sector;
	
	// déplace les chapitres
	
	var c = getid('chap_'+sector);
	if (c != undefined) {
		
		var nPos = c.offsetTop;
		if (nPos > 0) getid("div_chapt").scrollTop = nPos;
		
	}

	// affiche slide
	
	if (slide_path != '' && slide.length > 0 && getid('div_slide')!= null ) {
		
		var fil = slide;
		var ext = slide.substr(slide.length-3,3);

		switch(ext) {
		
		case 'gif' :
		case 'jpg' :
		case 'peg' :
		
			slide_width = '100%';
			slide_height = '100%';
			
			getid('div_slide').innerHTML = '<img src="'+ slide_path + fil +'" width="100%" height="100%">';
			//getid('div_slides').innerHTML = '<table class="slide"><tr><td><img src="../'+ session_path + slide_path + fil +'" width="'+ slide_width +'" height="'+ slide_height +'"></td></tr></table>';
			break;
			
		case 'swf' :

			swf_file = slide_path + fil;
			
			x = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" class="swf" ';
			x+= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">';
			x+= '<param name="movie" value="'+ swf_file +'" /><param name="wmode" value="transparent">';
			x+= '<param name="quality" value="high" /><param name="LOOP" value="false">';
			x+= '<embed src="'+ swf_file +'" width="100%" height="100%" loop="false" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">';
			x+= '</embed></object>';

			getid('div_slide').innerHTML = x;
			break;
		}
	}
}
//----------------------------------------------------------------------------------------------------
// affiche ou cache les sous-chapitres
//----------------------------------------------------------------------------------------------------
function chapter_open( chap ) {

	var t;
	var v;
	var img = document.getElementById('img_'+chap);
	
	// le +/- existe
	if (img != undefined) {
		
		// il est fermé ou c'est la premiere fois
		if (img.etat == 'c' || img.etat == undefined) {
				t = 'o'; // open
				if (navigator.userAgent.toLowerCase().indexOf("msie") + 1 > 0) v = 'block'; else v = 'table-row';
		} else {
				t = 'c'; // close
				v = 'none';
		}
		// change l'image
		img.etat = t;
		img.src = '/CORE/images/folder/'+ img.etat +'.gif';
		
		// le tableau de chapitre
		var tb = document.getElementById("chapters");
		// les TR
		var tr = tb.getElementsByTagName("tr");
		// si c'est le bon TR, affiche ou cache
		for (var i=0; i<tr.length; i++) {
			if (tr[i].id == 'schap_'+chap ) {
				tr[i].style.display = v;
			}
		}
	}
}
//----------------------------------------------------------------------------------------------------
// déplacement au chapiter précendet
//----------------------------------------------------------------------------------------------------
function chapter_prev() {
	
	if (video_index > 0) {
		
		video_index--;
		
		var timecode = video_chapters[ video_index ].split('|');
		sector = timecode[0];
		slide = timecode[1];

		//showw() // si caché
		video_move(sector);
		//chapter_scroll();
	}
}
//----------------------------------------------------------------------------------------------------
// déplacement au chapitre suivant
//----------------------------------------------------------------------------------------------------
function chapter_next() {

	if (video_index < video_chapters.length) {
	
		video_index++;
		var timecode = video_chapters[ video_index ].split('|');
		sector = timecode[0];
		slide = timecode[1];

		//showw();
		video_move(sector);
		//chapter_scroll();
	}
}
//----------------------------------------------------------------------------------------------------
// préchargement des slides qui seront affichés
//----------------------------------------------------------------------------------------------------
function slide_preload () {

	if (slide_path != '') {
		var j = 0;
		var pl = new Array();
		for (var i = 0; i < video_chapters.length ; i++) { 
		
			// trouve le nom du slide à afficher
			var tco = video_chapters[i].split('|');
			// s'il y a qq chose
			if (tco[1].length > 0) {
				// prends l'extension
				var ext = tco[1].substr(tco[1].length-3,3);
				// si image
				if (ext=='jpg' || ext=='peg' || ext=='gif' || ext=='png') {
					pl[j]=new Image;
					pl[j++].src= slide_path + tco[1];
				}
			}
		}
	}
}
//----------------------------------------------------------------------------------------------------
