var player_stream = ''; /*octoshape*/
var player_streamType = 'live'; /*octoshape*/
var player_dvrMinutes = 30; /*octoshape*/
function handleStrobeEvent(playerId, code, message, detail){ document.getElementById('video_strobe').seek(0); }
var maxtv = {
	pid : '',
	mode : '',
	toolbar : true,
	playlist : new Array(),
	playlistOptionAudio : new Array(),
	playlistOptionFormat : new Array(),
	playlistOptionMC : new Array(),
	playlistReset : function(){ this.playlist = new Array(); this.playlistOptionAudio = new Array(); this.playlistOptionMC = new Array(); },
	playlistIndex : 0,
	embed : {
		initialize : function(){
			maxtv.toolbar = false;
			maxtv.player._ads = false;
			$('#video').html('<div id="frame_ads" class="hidden"></div><div id="frame_loading" class="hidden"><img class="center" src="/embed/loading.gif" alt="loading..." style="margin-top:-10px;margin-left:-80px;"/></div>');
			if (maxtv.ads.enabled){
				maxtv.player._ads = true;
				maxtv.ads.enable();
				this.setUI('ads');
				setTimeout('maxtv.embed.start();', maxtv.ads.duration); 
			}else{
				maxtv.embed.start();
			}
		},
		start : function(){
			this.setUI('load');
			if (query.value('channel') != ''){
				this.title = query.value('channel').replaceAll('_', ' ');
				maxtv.debug.add('load xml playlist for ' + this.title + '...');
				$.ajax({
					url: '/embed/xml.php?what=playlist&channel=' + this.title.replaceAll(' ', '_'),
					error : function(msg){ maxtv.embed.doStop(); },
					complete  : function(xhr, textStatus){
						maxtv.playlistIndex = 0;
						maxtv.playlist = new Array();
						$(xhr.responseXML).find('entry').find('uri').each(function(){ maxtv.playlist.push(base64_decode($(this).text())); });
						$(xhr.responseXML).find('entry').find('audio').each(function(){ maxtv.playlistOptionAudio.push( $(this).text() ); });
						$(xhr.responseXML).find('entry').find('format').each(function(){ maxtv.playlistOptionFormat.push( $(this).text() ); });
						$(xhr.responseXML).find('entry').find('mediacenter').each(function(){  maxtv.playlistOptionMC.push( base64_decode($(this).text()) ); });
						if (maxtv.playlist.length > 0){
							maxtv.embed.doNext();
						}else{
							maxtv.embed.doStop();
						}
					}
				})
			}else if (query.value('uri') != ''){
				maxtv.playlist.push( query.value('uri') );
				if (maxtv.playlist.length > 0){
					maxtv.embed.doNext();
				}else{
					maxtv.embed.doStop();
				}
			}else{ maxtv.embed.doStop(); }
		},
		setUI: function(mode){
			function screenMode(){if (maxtv.toolbar){ return 'fullwindowtoolbar'; }else{ return 'fullwindow'; } }
			switch(mode){
				case 'video':
					$('#video').removeClass('fullwindowtoolbar').removeClass('fullwindow').removeClass('hidden').removeClass('hiddenvideo').addClass(screenMode());
					$('#frame_loading').removeClass( screenMode() ).addClass('hidden');
					$('#frame_ads').removeClass('fullwindow').addClass('hidden');
					if (maxtv.toolbar){
						$('#commands').removeClass('hidden').addClass('visible');
						$('#toolbar').removeClass('hidden').addClass('visible');
						$('#embed').removeClass('visible').addClass('hidden')
						$('#reload').removeClass('visible').addClass('hidden');
					}else{
						$('#commands').removeClass('visible').addClass('hidden');
					}
					$('#mediacenter').removeClass('hidden').addClass('visible');
					if ($('#mediacenter').attr('src') == ''){ $('#mediacenter').attr('src', maxtv.player._mediacenter ); }
					break;
				case 'ads':
					$('#video').removeClass('fullwindowtoolbar').removeClass('fullwindow').removeClass('hidden').removeClass('hiddenvideo').addClass(screenMode());
					$('#frame_loading').removeClass('fullwindow').addClass('hidden');
					$('#frame_ads').removeClass('hidden').addClass('fullwindow');
					$('#commands').removeClass('visible').addClass('hidden');
					$('#mediacenter').removeClass('visible').addClass('hidden');	
					break;
				case 'load':
					$('#frame_loading').removeClass('hidden').addClass('fullwindow');
					$('#frame_ads').removeClass('fullwindow').addClass('hidden');
					$('#commands').removeClass('visible').addClass('hidden');
					$('#mediacenter').removeClass('visible').addClass('hidden');
					break;
				case 'stop':
					maxtv.debug.add('stop');
					$('#debug').removeClass('visible').addClass('hidden');
					$('#frame_loading').removeClass( screenMode() ).addClass('hidden');
					$('#frame_ads').removeClass('fullwindow').addClass('hidden');
					$('#commands').removeClass('hidden').addClass('visible');
					$('#toolbar').removeClass('visible').addClass('hidden');
					$('#reload').removeClass('hidden').addClass('visible');
					$('#mediacenter').removeClass('visible').addClass('hidden');
					$('#embed').removeClass('visible').addClass('hidden')
					$('#reload').removeClass('hidden').addClass('visible');
					$('#video').html('<img style="position:absolute;top:0px;left:50%;width:auto;height:100%;z-index:999;" src="/embed/error_offline.jpg" onload="this.style.marginLeft=(0-(this.width/2))+\'px\';" onresize="this.style.marginLeft=(0-(this.width/2))+\'px\';"/>');
					break;
				case 'notoolbar':
					$('#commands').removeClass('visible').addClass('hidden');
					break;
			}
		},
		doNext : function(){
			maxtv.pid = Math.floor( Math.random() * 1000000001 );
			maxtv.embed.setUI('load');
			if (maxtv.playlistIndex < maxtv.playlist.length){
				var uri = maxtv.playlist[maxtv.playlistIndex];
				maxtv.playlistIndex++;
				maxtv.player.nextURI = '';
				maxtv.player.tries = 0;
				maxtv.player.play( uri );
			}else{
				maxtv.embed.doStop();
			}
		},
		doStop : function(){ maxtv.ads.loop = ''; maxtv.embed.setUI("stop"); },
		doCode : function(){
			$('#toolbar').removeClass('visible').addClass('hidden');
			$('#embed').removeClass('hidden').addClass('visible');
		},
		doToolbar : function(){
			$('#toolbar').removeClass('hidden').addClass('visible');
			$('#embed').removeClass('visible').addClass('hidden');
		},
		setVolume : function(volume){
			if (! maxtv.ads.enabled){
				document.getElementById('btn_sound').src = '/embed/btn_sound.png';
				for(i = 0; i < 15; i++){ document.getElementById('volume_' + i).style.display = 'none'; }
				for(i = 0; i < 15; i++){ document.getElementById('volume_off_' + i).style.display = 'none'; }
				for(i = 0; i < volume; i++){ document.getElementById('volume_' + i).style.display = ''; }
				for(i = volume; i < 15; i++){ document.getElementById('volume_off_' + i).style.display = ''; }
				maxtv.player.setVolume(volume);
			}
		},
		mute : function(){
			if (! maxtv.ads.enabled){
				if (maxtv.player._volume > 0){
					maxtv.player._volume_mute = maxtv.player._volume;
					this.setVolume(0);
					document.getElementById('btn_sound').src = '/embed/btn_sound_mute.png';
				}else{
					this.setVolume(maxtv.player._volume_mute);
				}
			}
		},
		transformURI : function(uri){
			var p = uri.split('/');
			if (p[2].indexOf('.dailymotion.') > 0){
				if (uri.indexOf('?') > 0){ uri = uri.substring(0, uri.indexOf('?')); }
				uri = uri.replace('/swf/video/', '/video/');
				uri = uri.replace('/video/', '/swf/video/');
				uri = uri.replace('http://', 'swf://');
				uri += '?autoPlay=1&expandVideo=1&enableApi';
				//uri += '#?param={xsw=' + (parseInt(window.innerWidth) + 0) + ',xsh=' + (parseInt(window.innerHeight) + 0) + '}';
			}else if(p[2].indexOf('.youtube.') > 0){
				if (uri.indexOf('/v/') > 0){
					uri = uri.replaceAll('?', '&');
					uri = uri.replaceAll('/v/', '/?v=');
				}
				var q = new query_parser(); q.initialize(uri);
				if (q.value('v') != ''){
					uri = 'swf://www.youtube.com/v/' + q.value('v') + '?&enablejsapi=1&autohide=1&autoplay=1&fs=1&disablekb=1&egm=0&controls=0&iv_load_policy=3&border=0&modestbranding=1&showinfo=0&showsearch=0';
				}
			}
			return uri;
		},
	},
	player : {
		_init_mode : false,
		_playstate_loop : '',
		_zoom_loop : '',
		_pluginLoaded : new Array(),
		_controller : '',
		_controller_container : '',
		_volume : 15,
		_volume_mute : 15,
		_need_plugin : false,
		_current_uri : '',
		_playstate : '',
		_ads : false,
		_mode : 'video',
		_mediacenter : '',
		timeout : 0,
		timeoutmax : 30,
		handler : '',
		nextURI : function(){},
		is_timeout : function(){ var result = false; if (this.timeout >= this.timeoutmax) { result = true; } return result; },
		setVolume : function(volume){
			this._volume = volume;
			try{ this._controller.audio.volume = (this._volume * 10); }catch(e){} //vlc
			try{ this._controller.settings.volume = (this._volume * 10); }catch(e){} //wmp
			try{ this._controller.volume = (this._volume * 10); }catch(e){}  //rayv
			try{ this._controller.changeVolume(parseInt(parseInt(this._volume) + 1) * 1.1); }catch(e){} //maxtv flash
			try{ this._controller.Content.MaxTV.setVolume(this._volume / 10); }catch(e){} //maxtv silverlight }catch(e){}
			try{ this._controller.jwSetVolume(this._volume * 10); }catch(e){} //jwplayer
			try{ this._controller.setVolume(this._volume / 15); }catch(e){} //strobe
			try{ this._controller.setGlobalVolume( ((this._volume * 100) / 15) ); }catch(e){} //maxtv.radio
		},
		detectPlayer : function(name){
			var object;
			if (window.document[name]){ object = window.document[name]; }
			if (navigator.appName.indexOf("Microsoft Internet")==-1){
				if (document.embeds && document.embeds[name]){
					object = document.embeds[name]; 
				}else{
					if (document.getElementById(name)){ object = document.getElementById(name); }
				}
			}
			return object;
		},
		getPlugin : function(uri){
			var result = 'unknown';
			if (result == 'unknown' && uri.indexOf('swf://') >= 0){ result = 'swf'; }
			if (result == 'unknown' && uri.indexOf('iframe://') >= 0){ result = 'iframe'; }
			if (result == 'unknown' && uri.indexOf('rtmp://') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('rtmp://') >= 0 && uri.indexOf('.live.edgefcs.net') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('rtmpt://') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('rtmpt://') >= 0 && uri.indexOf('.live.edgefcs.net') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('rtmps://') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('rtmpts://') >= 0 && uri.indexOf('.live.edgefcs.net') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('rtmpe://') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('rtmpte://') >= 0 && uri.indexOf('.live.edgefcs.net') >= 0){ result = 'strobe'; }
			if (result == 'unknown' && uri.indexOf('mms://') >= 0){ result = 'silverlight'; }
			if (result == 'unknown' && uri.indexOf('mmsh://') >= 0){ result = 'silverlight'; }
			if (result == 'unknown' && uri.indexOf('rtsp://') >= 0){ result = 'vlc'; }
			if (uri.indexOf('.flv') >= 0){ result = 'strobe'; }
			if (uri.indexOf('.f4m') >= 0){ result = 'strobe'; }
			if (uri.indexOf('.wmv') >= 0){ result = 'silverlight'; }
			if (uri.indexOf('.ism') >= 0){ result = 'silverlight'; }
			if (uri.toLowerCase().indexOf('/manifest') >= 0){ result = 'silverlight'; }
			if (uri.indexOf('impek.com/') >= 0){ result = 'silverlight'; }
			if (uri.indexOf('.infomaniak.ch/') >= 0){ result = 'wowza'; }
			if (uri.indexOf('video.max-tv.be') >= 0){ result = 'vlc'; }
			if (uri.indexOf('video.max-tv.org') >= 0){ result = 'vlc'; }
			if (uri.indexOf('video.maxtv.fr') >= 0){ result = 'vlc'; }
			if (uri.indexOf('.impek.com/go') >= 0){ result = 'asx'; }
			if (uri.indexOf('.mon-ludo.fr/appftv/akamai/token') >= 0){ result = 'get-content-silverlight'; }
			if (uri.indexOf('hdfauth.francetv.fr/esi/tokenlive.html') >= 0){ result = 'get-content-strobe'; }
			if (uri.indexOf('?player=vlc') >= 0){ result = 'vlc'; }
			if (uri.indexOf('?player=strobe') >= 0){ result = 'strobe'; }
			if (uri.indexOf('?player=flash') >= 0){ result = 'strobe'; }
			if (uri.indexOf('?player=silverlight') >= 0){ result = 'silverlight'; }
			if (uri.indexOf('http://') >= 0 && uri.indexOf(':8080/pctv_') >= 0){ result = 'vlc'; }
			if (maxtv.playlistOptionAudio[maxtv.playlistIndex - 1] == 'true'){ this._mode = 'audio'; result = 'maxtv.radio'; }
			return result;
		},
		stop : function(){
			for(var player in this._pluginLoaded){
				$('#'.player).css('width', '5px');
				$('#'.player).css('height', '5px');
				$('#'.player).html(' ');
			}
			clearTimeout(this._zoom_loop); this._zoom_loop = '';
		},
		mute : function(){ if (this._volume > 0){ this._volume_mute = this._volume; } this.setVolume(0); },
		play : function(uri){
			if (! maxtv.ads.enabled){ maxtv.embed.setUI('load'); }else{ if (this._volume == 0){ this._volume = this._volume_mute; } }
			this.stop();
			this._mode = 'video';
			this._current_uri = uri;
			this._playstate = '';
			this.tries++;
			this._mediacenter = '';
			//uri = uri.replaceAll('rtmp://', 'rtmpt://');
			uri = uri.replaceAll('rtmpt://', 'rtmp://');
			maxtv.debug.add('play ' + uri);
			clearTimeout(this._playstate_loop);
			this._playstate_loop = '';
			this._controller = '';
			this.timeout = 0;
			this._need_plugin = false;
			uri = maxtv.embed.transformURI(uri);
			this.handler = this.getPlugin(uri);
			if (this.nextURI == ''){ this.nextURI = arguments.callee.caller; }
			this.loadPlugin(uri);
		},
		loadPlugin : function(uri){
			switch(this.handler){
				case 'iframe':
					maxtv.toolbar = false;
					var xPlayerW = parseInt(window.innerWidth);
					var xPlayerH = parseInt(window.innerHeight);
					var xSiteW = '1024px';
					var xSiteH = '768px';
					var xTop = '0px';
					var xLeft = '0px';
					var xWidth = '100%';
					var xHeight = '100%';
					var xScrollTop = '0px';
					var xScrollLeft = '0px';
					var xFactor = 1;
					if (uri.indexOf('#?param=') > 0){
						var param = 'http://load.param/?' + uri.substring(uri.indexOf('#?param=') + 2);
						var q = new query_parser(); q.initialize(param); q = 'http://load.param/?' + q.value('param').replaceAll('{', '').replaceAll('}', '').replaceAll(',', '&');
						var v = new query_parser(); v.initialize(q);
						if (v.value('xz') != ''){ xFactor = v.value('xz'); };
						if (v.value('xsw') != ''){ xSiteW = v.value('xsw')+ 'px'; };
						if (v.value('xsh') != ''){ xSiteH = v.value('xsh')+ 'px'; };
						if (v.value('xw') != ''){ xWidth = (parseInt(v.value('xw')) * xFactor) + 'px'; };
						if (v.value('xh') != ''){ xHeight = (parseInt(v.value('xh') * xFactor)) + 'px'; };
						if (v.value('xst') != ''){ xScrollTop = (parseInt(v.value('xst') * xFactor)) + 'px'; };
						if (v.value('xsl') != ''){ xScrollLeft = (parseInt(v.value('xsl') * xFactor)) + 'px'; };
						if (v.value('xpw') != ''){ xLeft = ((parseInt(xPlayerW) - parseInt(xWidth)) / 2) + 'px'; };
						if (v.value('xph') != ''){ xTop = ((parseInt(xPlayerH) - parseInt(xHeight)) / 2) + 'px'; };
						uri = uri.substring(0, uri.indexOf('#?param='));
					}
					if (uri.indexOf('?') > 0){
						param = uri.substring(uri.indexOf('?') + 1).replaceAll('&', '&amp;');
						uri = uri.substring(0, uri.indexOf('?'));
						uri = uri + '?' + param;
					}
					uri = uri.replace('iframe://', 'http://')
					var zoomer = '';
					if (navigator.appName == 'Microsoft Internet Explorer'){
						zoomer += 'zoom:' + xFactor;
					}else{
						zoomer += '-moz-transform: scale(' + xFactor + '); -moz-transform-origin: 0 0;';
						zoomer += '-webkit-transform: scale(' + xFactor + '); -webkit-transform-origin: 0 0;';
						zoomer += '-o-transform: scale(' + xFactor + '); -o-transform-origin: 0 0;';
						zoomer += 'transform: scale(' + xFactor + '); transform-origin: 0 0;';
					}
					var html = '<div id="iframecontainer" style="position:relative;top:' + xTop + ';left:' + xLeft + ';width:' + xWidth + 'px;height:' + xHeight + 'px;overflow:none;">';
					html += '<iframe id="iframeplayer" scrolling="no" frameborder="no" style="position:absolute;border:0px;top:-' + xScrollTop + ';left:-' + xScrollLeft + ';width:' + xSiteW + ';height:' + xSiteH + ';" src="' + uri + '"></iframe>';
					html += '</div>';
					$('#video').html(html);
					maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 0);
					if (xFactor != 1){
						maxtv.player._zoom_loop = setTimeout("$('#iframeplayer').attr('style', 'position:absolute;border:0px;top:-" + xScrollTop + ";left:-" + xScrollLeft + ";width:" + xSiteW + ";height:" + xSiteH + ";" + zoomer + "');", 5000);
					}
					maxtv.embed.setUI('notoolbar');
					break;
				case 'vlc':
					if (plugins.check('VLC') > 0){
						if (! document.getElementById('video_vlc')){
							maxtv.debug.add('load vlc webplugin...');
							var html = '';
							if (window.attachEvent){
								html += '<object id="video_vlc" events="true" type="application/x-vlc-plugin" classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" style="width:5px;height:5px;">';
								html += '<param value="" name="MRL"/>';
								html += '<param value="true" name="ShowDisplay"/>';
								html += '<param value="false" name="AutoLoop"/>';
								html += '<param value="false" name="AutoPlay"/>';
								html += '<param value="100" name="Volume"/>';
								html += '<param value="0" name="StartTime"/>';
								html += '</object>';
							}else{
								html += '<embed id="video_vlc" style="width:5px;height:5px;" progid="VideoLAN.VLCPlugin.2" type="application/x-vlc-plugin" pluginspage="http://www.max-tv.be/fr/videolan.html">';
							}
							document.getElementById('video').innerHTML += html;
							this._pluginLoaded['video_vlc'] = 'video_vlc';
							setTimeout('maxtv.player.play("' + uri + '");', 1000);
						}
						try{
							this._controller = document.getElementById('video_vlc');		
							this._controller_container = document.getElementById('video_vlc');		
							maxtv.debug.add('play ' + uri + ' with vlc...');
							var options = new Array(':play-and-stop', ':no-video-title-show', ':http-reconnect', ':http-user-agent=vlc/1.1.11', ':http-proxy=http://pac.cegedim.com:3128/');
							options.push(':crop=16:9');
							var itemId = this._controller.playlist.add('' + uri, '', options);
							if (itemId != -1){ this._controller.playlist.playItem(itemId); }
							maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 1000);
						}catch(e){ $('#video_vlc').remove(); if (this.tries < 5){ setTimeout('maxtv.player.play("' + uri + '");', 1000); }else{ this.nextURI(); } }
					}else{
						var pluginCode = plugins.getCode('VLC');
						$('#video').html(pluginCode);
						maxtv.embed.setUI('video');
						maxtv.embed.setUI('notoolbar');
					}
					break;
				case 'silverlight':
					if (plugins.check('Silverlight') > 0){
						if (! document.getElementById('video_silverlight')){
							maxtv.debug.add('load silverlight webplugin...');
							var html = '';
							html += '<object id="video_silverlight" type="application/x-silverlight" width="5px" height="5px">';
							html += '<param name="background" value="#000"/>';
							html += '<param name="source" value="/embed/silverlight.xap"/>';
							html += '<param name="enablehtmlaccess" value="true"/>';
							html += '<param name="windowless" value="true"/>';
							html += '<param name="initParams" value="mode=embed,enableControls=true,aspect=' + maxtv.playlistOptionFormat[maxtv.playlistIndex - 1] + ',aspectDefault=' + maxtv.playlistOptionFormat[maxtv.playlistIndex - 1] + ',file=' + uri + '"/>';
							html += '</object>';
							document.getElementById('video').innerHTML += html;
							this._pluginLoaded['video_silverlight'] = this.detectPlayer('video_silverlight');
							this._controller = document.getElementById('video_silverlight');
							this._controller_container = document.getElementById('video_silverlight');
							maxtv.toolbar = false;
							this._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 2000);
						}else{
							try{
								this._controller = document.getElementById('video_silverlight');
								this._controller_container = document.getElementById('video_silverlight');
								this._pluginLoaded['video_silverlight'].className = 'video';
								maxtv.debug.add('play ' + uri + ' with silverlight...');
								this._controller.Content.MaxTV.setSource('' + uri);
								this._init_mode = true;
								maxtv.toolbar = false;
								this._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 2000);
							}catch(e){ maxtv.debug.add('ERROR : ' + e.message + ' with ' + uri); this.nextURI(); }
						}
					}else{
						var pluginCode = plugins.getCode('Silverlight');
						$('#video').html(pluginCode);
						maxtv.embed.setUI('video');
						maxtv.embed.setUI('notoolbar');
					}
					break;			
				case 'flash':
					if (plugins.check('Flash') > 0){
						var video_format = '16:9';//maxtv.embed.player.formats.current();
						var stream_url = uri.replaceAll('/','$');
						stream_url = stream_url.replaceAll('&','$amp;');
						var flash = '';
						flash += '<object name="video_flash" data="/embed/flash.swf" type="application/x-shockwave-flash" width="100%" height="100%">';
						flash += '<param name="allowFullScreen" value="true"></param>';
						flash += '<param name="flashvars" value="format=16:9&file=' + stream_url + '"></param>';
						flash += '<param name="allowScriptAccess" value="always"></param>';
						flash += '<param name="movie" value="/embed/flash.swf"></param>';
						flash += '<param name="quality" value="high"></param>';
						flash += '<param name="bgcolor" value="#000000"></param>';
						flash += '<param name="wmode" value="transparent"></param>';
						//flash += '<embed id="video_flash" src="/embed/flash.swf?format=' + video_format.replace(':','-').replace(':','-') + '&file=' + stream_url + '" allowFullScreen="true" bgcolor="#000000" width="100%" height="100%" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" flashvars="format=' + video_format.replace(':','-').replace(':','-') + '&file=' + stream_url + '" quality="high" wmode="transparent"/>';
						flash += '</object>';
						if (! document.getElementById('video_flash_container')){
							var html = '<div id="video_flash_container" style="width:5px;height:5px;">' + flash + '</div>';
							document.getElementById('video').innerHTML += html;
							this._pluginLoaded['video_flash_container'] = 'video_flash_container';
							this._controller = document.getElementById('video_flash');
							this._controller_container = document.getElementById('video_flash_container');
						}else{
							document.getElementById('video_flash_container').innerHTML = flash;
							this._controller = document.getElementById('video_flash');
							this._controller_container = document.getElementById('video_flash_container');
						}
						this._init_mode = true;
						maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 1000);
					}else{
						var pluginCode = plugins.getCode('Flash');
						$('#video').html(pluginCode);
						maxtv.embed.setUI('video');
						maxtv.embed.setUI('notoolbar');
					}
					break;
				case 'strobe':
					if (plugins.check('Flash') > 0){
						var video_format = '16:9';//maxtv.embed.player.formats.current();
						var flash = '';
						var pl = '';
						pl += '&plugin_smil=http://player.maxtv.fr/embed/SMILPlugin.swf';
						//pl += '&plugin_akamai=http://player.maxtv.fr/embed/AkamaiBasicStreamingPlugin.swf';
						//pl += '&plugin_akamaihd=http://player.maxtv.fr/embed/AkamaiAdvancedStreamingPlugin.swf';
						pl += '&plugin_mast=http://player.maxtv.fr/embed/MASTPlugin.swf';
						pl += '&plugin_youtube=http://player.maxtv.fr/embed/YouTubePlugin.swf';
						//pl += '&plugin_limelight=http://player.maxtv.fr/embed/LimelightStreamingPlugin.swf';
						flash += '<object id="video_strobe" data="/embed/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" width="100%" height="100%">';
						flash += '<param name="allowFullScreen" value="true"></param>';
						flash += '<param name="flashvars" value="src=' + encodeURIComponent(uri) + '&controlBarMode=floating&scaleMode=letterbox&javascriptCallbackFunction=handleStrobeEvent&streamType=live&autoPlay=true' + pl + '"></param>';
						flash += '<param name="allowScriptAccess" value="always"></param>';
						flash += '<param name="movie" value="/embed/StrobeMediaPlayback.swf"></param>';
						flash += '<param name="quality" value="high"></param>';
						flash += '<param name="bgcolor" value="#000000"></param>';
						flash += '<param name="wmode" value="opaque"></param>';
						flash += '</object>';
						if (! document.getElementById('video_strobe_container')){
							var html = '<div id="video_strobe_container" style="width:5px;height:5px;">' + flash + '</div>';
							document.getElementById('video').innerHTML += html;
							this._pluginLoaded['video_strobe_container'] = 'video_strobe_container';
							this._controller = document.getElementById('video_strobe');
							this._controller_container = document.getElementById('video_strobe_container');		
								
						}else{
							document.getElementById('video_strobe_container').innerHTML = flash;
							this._controller = document.getElementById('video_strobe');
							this._controller_container = document.getElementById('video_strobe_container');
						}
						this._init_mode = true;
						maxtv.toolbar = false;
						maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 1000);
					}else{
						var pluginCode = plugins.getCode('Flash');
						$('#video').html(pluginCode);
						maxtv.embed.setUI('video');
						maxtv.embed.setUI('notoolbar');
					}
					break;
				case 'jwplayer':
					if (plugins.check('Flash') > 0){
						var video_format = '16:9';//maxtv.embed.player.formats.current();
						var uri2 = uri; if (uri.indexOf('?') > 0){ uri2 = uri.substring(0, uri.indexOf('?')); }
						var uri_query = ''; if (uri.indexOf('?') > 0){
							uri_query = uri.substring(uri.indexOf('?') + 1);
							uri_query = uri_query.replaceAll('player=jwplayer', '');
							if (uri_query == '?'){ uri_query = '';}
							uri_query = uri_query.replaceAll('?', '&');
						}
						var uri_file = uri2.split('/')[uri2.split('/').length - 1];
						var uri_streamer = uri2.replace('/' + uri_file, '');
						var flash = '';
						flash += '<object name="video_jwplayer" data="/embed/jwplayer.swf" type="application/x-shockwave-flash" width="100%" height="100%">';
						flash += '<param name="allowFullScreen" value="true"></param>';
						flash += '<param name="flashvars" value="controlbar=none&icons=false&stretching=uniform&smoothing=true&bufferlength=3&autostart=true&file=' + uri_file + '&streamer=' + uri_streamer + '"></param>';
						flash += '<param name="allowScriptAccess" value="always"></param>';
						flash += '<param name="movie" value="/embed/jwplayer.swf"></param>';
						flash += '<param name="quality" value="high"></param>';
						flash += '<param name="bgcolor" value="#000000"></param>';
						flash += '<param name="wmode" value="transparent"></param>';
						//flash += '<embed id="video_flash" src="/embed/flash.swf?format=' + video_format.replace(':','-').replace(':','-') + '&file=' + stream_url + '" allowFullScreen="true" bgcolor="#000000" width="100%" height="100%" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" flashvars="format=' + video_format.replace(':','-').replace(':','-') + '&file=' + stream_url + '" quality="high" wmode="transparent"/>';
						flash += '</object>';
						if (! document.getElementById('video_jwplayer_container')){
							var html = '<div id="video_jwplayer_container" style="width:5px;height:5px;">' + flash + '</div>';
							document.getElementById('video').innerHTML += html;
							this._pluginLoaded['video_jwplayer_container'] = 'video_jwplayer_container';
							this._controller = document.getElementById('video_jwplayer');
							this._controller_container = document.getElementById('video_jwplayer_container');
						}else{
							document.getElementById('video_jwplayer_container').innerHTML = flash;
							this._controller = document.getElementById('video_jwplayer');
							this._controller_container = document.getElementById('video_jwplayer_container');
						}
						this._init_mode = true;
						maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 1000);
					}else{
						var pluginCode = plugins.getCode('Flash');
						$('#video').html(pluginCode);
						maxtv.embed.setUI('video');
						maxtv.embed.setUI('notoolbar');
					}
					break;
				case 'maxtv.radio':
					var mediacenter = maxtv.playlistOptionMC[maxtv.playlistIndex - 1];
					if (base64_encode(mediacenter) == 'AAAA'){ mediacenter = ''; }
					maxtv.playlistReset();
					if (! document.getElementById('video_maxtv.radio')){
						var flash = '<object id="video_maxtv.radio" type="application/x-shockwave-flash" data="/embed/maxtv.radio.swf" width="1px" height="1px">';
							flash += '<param name="movie" value="/embed/maxtv.radio.swf" />';
							flash += '<param name="wmode" value="transparent" />';
							flash += '<param name="allowScriptAccess" value="always" />';
						flash += '</object>';
						if (mediacenter != '' && mediacenter != 'undefined'){
							this._mediacenter = '/embed/mediacenter.php?width=1000&height=500&uri=' + encodeURIComponent(mediacenter);
							mediacenter = '<iframe id="mediacenter" frameborder="no" border="no" src="" class="hidden"></iframe>';
						}else{
							mediacenter = '<div id="mediacenter" width="5px" height="5px"></div>';
						}
						if (! document.getElementById('video_maxtv.radio_container')){
							document.getElementById('video').innerHTML += '<div id="video_maxtv.radio_container" width="5px" height="5px">' + flash + '</div>' + mediacenter;
						}else{
							document.getElementById('video_maxtv.radio_container').innerHTML += flash;
						}
						this._controller = document.getElementById('video_maxtv.radio');
						this._controller_container = document.getElementById('mediacenter');
						var channel = query.value('channel').toLowerCase().replaceAll('_', '-').replaceAll(' ', '-');
						setTimeout('document.getElementById("video_maxtv.radio").setPlaylist("/playlists/' + channel  + '.xspf", "xspf", 1);', 1000);
						maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 2000);
					}
					break;
				case 'wowza':
					uri = uri.replaceAll('rtmp://', 'http://');
					uri += '/Manifest';
					this.handler = 'silverlight';
					setTimeout('maxtv.player.loadPlugin("' + uri + '");', 100);
					break;
				case 'asx':
					$.ajax({
						url: '/embed/getlink.php?m=asx&l=' + encodeURIComponent(uri),
						error : function(msg){ maxtv.embed.doStop(); },
						complete  : function(xhr, textStatus){
							uri = xhr.responseText;
							maxtv.player.handler = 'silverlight';
							setTimeout('maxtv.player.loadPlugin("' + uri + '");', 100);
						}
					})				
					break;
				case 'get-content-strobe':
				case 'get-content-silverlight':
					$.ajax({
						url: '/embed/getlink.php?m=gc&l=' + encodeURIComponent(uri),
						error : function(msg){ maxtv.embed.doStop(); },
						complete  : function(xhr, textStatus){
							uri = xhr.responseText;
							maxtv.player.handler = maxtv.player.handler.replace('get-content-', '');
							setTimeout('maxtv.player.loadPlugin("' + uri + '");', 100);
						}
					})				
					break;
				case 'swf':
					var xWidth = '100%';
					var xHeight = '100%';
					var xFactor = 1;
					if (uri.indexOf('#?param=') > 0){
						var param = 'http://load.param/?' + uri.substring(uri.indexOf('#?param=') + 2);
						var q = new query_parser(); q.initialize(param); q = 'http://load.param/?' + q.value('param').replaceAll('{', '').replaceAll('}', '').replaceAll(',', '&');
						var v = new query_parser(); v.initialize(q);
						if (v.value('xw') != ''){ xWidth = (parseInt(v.value('xw')) * xFactor) + 'px'; };
						if (v.value('xh') != ''){ xHeight = (parseInt(v.value('xh') * xFactor)) + 'px'; };
						uri = uri.substring(0, uri.indexOf('#?param='));
					}
					uri = uri.replace('swf://', 'http://');
					var param = '';
					if (uri.indexOf('?')){
						var u = ''; var p = uri;
						while (p.indexOf('?') > 0){
							u += p.substring(0, p.indexOf('?')) + '?';
							p = p.substring(p.indexOf('?') + 1)
						}
						if (p != uri){
							uri = u; 
							param = p;
						}
						param = param.replaceAll('&', '&amp;');
						param = param.replaceAll('"', "'");
					}
					var swf = '<object id="video_swf" type="application/x-shockwave-flash" data="' + uri + '" width="' + xWidth + '" height="' + xHeight + '">';
					swf += '<param name="wmode" value="transparent" />';
					swf += '<param name="allowFullScreen" value="true" />';
					swf += '<param name="quality" value="high">';
					swf += '<param name="allowScriptAccess" value="always" />';
					if (param != ''){ swf += '<param name="flashvars" value="' + param + '" />'; }
					swf += '</object>';
					$('#video').html(swf);
					maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 0);
					maxtv.embed.setUI('notoolbar');
					break;
				case 'octoshape':
					/*<script type="text/javascript" src="http://cdn.octoshape.net/resources/player/base/swfobject.js"></script>
					var params = {name: 'video', allowFullScreen: true, scale: 'noscale', allowScriptAccess: 'always'};
					swfobject.embedSWF('http://cdn.octoshape.net/resources/player/base/player-100-1011090.swf', 'video', '640', '360', "10.0.0", null, null, params);*/
					break;
				default:
					this.nextURI();
					break;
			}
			
		},
		playstate : function(){
			var playstate = 'load';
			switch(this.handler){
				case 'vlc':
					try{
						if (this._controller && this._controller.input){
							switch(this._controller.input.state){
								case 1: break;
								case 2: break;
								case 3: if (this._controller.input.hasVout){ playstate = 'play'; }; break;
								case 4: break;
								case 0: break;
								case 5: break;
								case 6: break;
								case 7: break;
								case 8: break;
								case 9: playstate = 'stop'; break;
								default: break;
							}
						}else{
							setTimeout('maxtv.player.play("' + this._current_uri + '");', 100);
							return;
						}
						maxtv.debug.add('maxtv.player.playstate[vlc] = ' + this._controller.input.state);
					}catch(e){ maxtv.debug.add('maxtv.player.playstate[vlc] : Error > ' + e.message); }
					maxtv.debug.add('maxtv.player.playstate[vlc] : ' + playstate);
					break;
				case 'silverlight':
					try{ playstate = this._controller.Content.MaxTV.playstate(); }catch(e){ playstate = 'play'; }
					maxtv.debug.add('maxtv.player.playstate[silverlight] : ' + playstate);
					if (this._init_mode) { if (playstate == 'play' || playstate == 'stop'){ this._init_mode = false; playstate = 'load'; } }
					break;
				case 'flash':
					try{ playstate = this._controller.playstate(); }catch(e){ }
					maxtv.debug.add('maxtv.player.playstate[flash] : ' + playstate);
					if (this._init_mode) { if (playstate == 'play'){ this._init_mode = false; playstate = 'load'; } }
					break;
				case 'jwplayer':
					try{
						var state = this._controller.jwGetState();
						if (state == 'PLAYING'){ playstate = 'play'; }
						if (state == 'IDLE'){ playstate = 'stop'; }
					}catch(e){ playstate = 'load'; }
					maxtv.debug.add('maxtv.player.playstate[jwplayer] = ' + playstate);
					if (this._init_mode) { if (playstate == 'play'){ this._init_mode = false; playstate = 'load'; } }
					break;
				case 'strobe':
					try{
						var state = this._controller.getState();
						if (state == 'loading'){ playstate = 'load'; }
						if (this.timeout > 70 && state == 'ready'){ playstate = 'stop'; }
						if (state == 'paused'){ playstate = 'play'; }
						if (state == 'buffering'){ playstate = 'load'; }
						if (state == 'playing'){ playstate = 'play'; }
					}catch(e){ maxtv.debug.add('maxtv.player.playstate[strobe] : Error > ' + e.message); playstate = 'load'; }
					maxtv.debug.add('maxtv.player.playstate[strobe] = ' + playstate);
					break;
				case 'iframe':
					maxtv.toolbar = false;
					maxtv.embed.setUI('notoolbar');
					playstate = 'play';
					break;
				case 'swf':
					maxtv.toolbar = false;
					maxtv.embed.setUI('notoolbar');
					playstate = 'play';
					break;
				case 'maxtv.radio':
					try{
						playstate = this._controller.getStatus();
					}catch(e){ maxtv.debug.add('maxtv.player.playstate[maxtv.radio] : Error > ' + e.message); playstate = 'load'; }
					maxtv.debug.add('maxtv.player.playstate[maxtv.radio] = ' + playstate);
					break;
				default:
					this.nextURI();
					break;
			}
			if (this._need_plugin){ playstate = 'play'; }
			switch (playstate){
				case 'stop': break;
				case 'load':
					if (maxtv.ads.enabled){ playstate = 'ads'; }
					if (this.is_timeout()){ playstate = 'stop'; }
					break;
				case 'play':
					if (maxtv.ads.enabled){ playstate = 'ads'; }
					break;
			}
			return playstate;
		},
		_playstate_handle : function(){
			clearTimeout(maxtv.player._playstate_loop);
			maxtv.player._playstate_loop = '';
			/*try{*/
				var playstate = this.playstate();
				switch(playstate){
					case 'ads':
					case 'load':
						this.timeout++;
						this.mute();
						if (playstate != this._playstate){ maxtv.embed.setUI( playstate ); }
						if (playstate != this._playstate){ this._playstate = playstate; }
						if (this._controller_container != '' && this._controller_container.style.width != '5px'){ this._controller_container.style.width = '5px'; }
						if (this._controller_container != '' && this._controller_container.style.height != '5px'){ this._controller_container.style.height = '5px'; }
						maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 1000);
						break;
					case 'play':
						if (playstate != this._playstate){ maxtv.embed.setUI('video'); }
						if (playstate != this._playstate){ this.setVolume(this._volume_mute); this._playstate = playstate; }
						if (this._controller_container != '' && this._controller_container.style.width != '100%'){ this._controller_container.style.width = '100%'; }
						if (this._controller_container != '' && this._controller_container.style.height != '100%'){ this._controller_container.style.height = '100%'; }
						maxtv.player._playstate_loop = setTimeout('maxtv.player._playstate_handle();', 1000);
						break;
					case 'stop':
						this.timeout = 0;
						this.stop();
						setTimeout('maxtv.embed.doNext();', 100);
						break;
				}
			/*}catch(e){
				//maxtv.debug.add('maxtv.player.playstate_handle : Error > ' + e.message);
				//this.nextURI();
			}*/
		}
	},	
	ads : {
		loop : '',
		started : false,
		enabled : false,
		duration : 15000,
		load : function(){ $('#frame_ads').html('<iframe src="http://ads.max-tv.be/300x250/?channel=" width="100%" height="100%" scrolling="no" frameborder="0"></iframe>'); },
		enable : function(){
			this.started = true;
			maxtv.debug.add('maxtv.ads.enable');
			clearTimeout(this.loop);
			this.loop = '';
			maxtv.player.mute();
			this.enabled = true;
			this.load();
			this.loop = setTimeout('maxtv.ads.disable()' , this.duration);
		},
		disable : function(){
			maxtv.debug.add('maxtv.ads.disable');
			clearTimeout(this.loop);
			this.loop = '';
			$('#frame_ads').html('');
			this.enabled = false;
			maxtv.player.setVolume( maxtv.player._volume_mute );
		}
	},
	debug : {
		log : '',
		add : function(message){
			try{ window.dump(message); }catch(e){}
			maxtv.debug.log += message + String.fromCharCode(10);
			if (document.getElementById('debug')){
				document.getElementById('debug').innerHTML = maxtv.debug.log.replaceAll(String.fromCharCode(10), '<br>');
				document.getElementById('debug').scrollDown = document.getElementById('debug').offsetHeight;
			}	
		},
		enable : function(){
			if (document.getElementById('debug')){
				if (document.getElementById('debug').className == 'debug'){
					document.getElementById('debug').className = 'hidden';
				}else{
					document.getElementById('debug').className = 'debug';
					document.getElementById('debug').scrollDown = document.getElementById('debug').offsetHeight;
				}
			}
		}
	}
}




