var isIE = (document.all && navigator.platform == 'Win32')? true : false;
var isOpera = (navigator.userAgent.indexOf('Opera') == 55 || navigator.userAgent.indexOf('Opera') == 36 || navigator.userAgent.indexOf('Opera') == 0)? true : false ;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false;

function showMedia(title,url,w,h,viewBandeau){
	var tempCh = '';
	// Extension
	var mediaExt = url.substr(url.lastIndexOf('.'), url.length);
	// Ecrit le player en fonction du media
	if(url.lastIndexOf('.') == -1) {
		version = navigator.appVersion;
		if (version.toLowerCase().indexOf("mac")!=-1) {
			mediaExt = ".mov"
		}
		else {
			mediaExt = ".wmv";
		}
	}
	switch(mediaExt){
		// Compressed AVI
		case '.avi':
			/* > Controller height > */ h = h+40;
			tempCh = '\<object width="'+w+'" height="'+h+'" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">\n';
			tempCh += '\t<param name="filename" value="/upload/videosconf/'+url+'" />\n';
			tempCh += '\t<param name="Showcontrols" value="True" />\n';
			tempCh += '\t<param name="autoStart" value="True" />\n';
			tempCh += '\t<embed type="application/x-mplayer2" src="/upload/videosconf/'+url+'" name="MediaPlayer" width="'+w+'" height="'+h+'"></embed>\n';
			tempCh += '</object>\n';
			break;
		// Flash Vidéo
		case '.flv':
			var playerWidth = 480;
			var playerHeight = 360;
			tempCh = '\n<object type="application/x-shockwave-flash" data="playflv.swf?filmName=/upload/videosconf/'+url+'&w='+w+'&h='+h+'&viewBandeau='+viewBandeau+'" width="'+playerWidth+'" height="'+playerHeight+'" >\n';
			tempCh += '\t<param name="movie" value="playflv.swf?filmName=/upload/videosconf/'+url+'&w='+w+'&h='+h+'&viewBandeau='+viewBandeau+'">';
			tempCh += '\t<param name="wmode" value="transparent" />\n';
			tempCh += '\t<param name="quality" value="high" />\n';
			tempCh += '</object>\n';
			break;
		// Quicktime
		case '.mov':
			/* > Controller height > */ h = h+20;
			tempCh = '\n<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+w+'" height="'+h+'">\n';
			tempCh += '\t<param name="src" value="rtsp://stream2.ipercast.net/memorial-cdjc.org/videosconf/'+url+mediaExt+'" />\n';
			tempCh += '\t<param name="controller" value="true" />\n';
			tempCh += '\t<param name="autoplay" value="true" />\n';
			tempCh += '\t<!--[if !IE]> <-->\n';
			tempCh += '\t<object type="video/quicktime" data="rtsp://stream2.ipercast.net/memorial-cdjc.org/videosconf/'+url+mediaExt+'" width="'+w+'" height="'+h+'">\n';
			tempCh += '\t\t<param name="controller" value="true" />\n';
			tempCh += '\t\t<param name="autoplay" value="true" />\n';
			tempCh += '\t</object>\n';
			tempCh += '\t<!--> <![endif]-->\n';
			tempCh += '</object>\n';
			break;
		// Shockwave Flash
		case '.swf':
			tempCh = '\n<object type="application/x-shockwave-flash" data="/upload/videosconf/'+url+'" width="'+w+'" height="'+h+'">\n';
			tempCh += '\t<param name="movie" value="/upload/videosconf/'+url+'" />\n';
			tempCh += '</object>\n';
			break;
		// Widnows Media Video
		case '.wmv':
			/* > Controller height > */ h = h+40;
			tempCh = '\<object width="'+w+'" height="'+h+'" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">\n';
			tempCh += '\t<param name="filename" value="mms://stream2.ipercast.net/memorial-cdjc.org/videosconf/'+url+mediaExt+'" />\n';
			tempCh += '\t<param name="Showcontrols" value="True" />\n';
			tempCh += '\t<param name="autoStart" value="True" />\n';
			tempCh += '\t<embed type="application/x-mplayer2" src="mms://stream2.ipercast.net/memorial-cdjc.org/videosconf/'+url+mediaExt+'" name="MediaPlayer" width="'+w+'" height="'+h+'"></embed>\n';
			tempCh += '</object>\n';
			//player = new ActiveXObject("WMPlayer.OCX");
			break;
		case '.mpeg':
			/* > Controller height > */ h = h+40;
			tempCh = '\<object width="'+w+'" height="'+h+'" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">\n';
			tempCh += '\t<param name="filename" value="/upload/videosconf/'+url+'" />\n';
			tempCh += '\t<param name="Showcontrols" value="True" />\n';
			tempCh += '\t<param name="autoStart" value="True" />\n';
			tempCh += '\t<embed type="application/x-mplayer2" src="/upload/videosconf/'+url+'" name="MediaPlayer" width="'+w+'" height="'+h+'"></embed>\n';
			tempCh += '</object>\n';
			break;
		default:
		// Rien
		break;
	}
	// Chargement du nouveau média
	if(isIE && !isIE7){
		// Nettoyage de l'iframe
		mediaFrame.document.getElementsByTagName('body')[0].innerHTML = '';
		// Ecriture du media
		mediaFrame.document.write('<html><body id="mediaBody" style="margin:0;padding:0;background:#EEF6FC;">'+tempCh+'</body></html>');
		// Redimensionne l'iframe
		if(mediaExt != ".flv") {
			document.getElementById('mediaFrame').style.width = w;
			document.getElementById('mediaFrame').style.height = h;
		}
		else {
			document.getElementById('mediaFrame').style.width = playerWidth;
			document.getElementById('mediaFrame').style.height = playerHeight;
		}
	} else {
		var mediaZone = document.getElementById('media');
		mediaZone.innerHTML = tempCh;
	}
	//Change le titre du media en cours
	//document.getElementById('mediaTitle').innerHTML = title.innerHTML;
	//Désactive tous les liens class="none"
	clearList();
	//Active le media en cours
	title.className = 'on';
}

// Nettoyage de la liste
function clearList(){
	for(i=0; i<linkTab.length; i++){
		linkTab[i].className = '';
	}
}

// Pose les simili lien hover
window.onload = function(){
	linkTab = document.getElementsByTagName('li');
	if(linkTab[0]) {
		for(i=0; i<linkTab.length; i++){
			linkTab[i].style.cursor = 'pointer';
			linkTab[i].onmouseover = function(){ this.style.backgroundColor = '#FFFFFF'; }
			linkTab[i].onmouseout = function(){ this.style.backgroundColor = 'transparent'; }
		}
		var tempCh = linkTab[0].onclick+'';
		tempCh = tempCh.substring(tempCh.indexOf('this')+5,tempCh.lastIndexOf(');'));
		var tempTab = tempCh.split(',');
		test = (isIE || isOpera)? 1 : 2;
		tempM = tempTab[0].substring(test,tempTab[0].length-1);
		tempW = parseInt(tempTab[1]);
		tempH = parseInt(tempTab[2]);
		//alert(tempM+' : '+tempW+' : '+tempH);
		if(tempTab[3].lastIndexOf("N") != -1) tempB = 'N';
		else tempB = 'O';
		showMedia(linkTab[0],tempM,tempW,tempH,tempB);
	}
}
function iniHover(){
	var linkTab = document.getElementsByTagName('li');
	for(i=0; i<linkTab.length; i++){
		linkTab[i].style.cursor = 'pointer';
		linkTab[i].onmouseover = function(){ this.style.backgroundColor = '#FFFFFF'; }
		linkTab[i].onmouseout = function(){ this.style.backgroundColor = 'transparent'; }
	}
}

