/* 
mediavlakplayer (audio,video)
detects audio, video
detects Quicktime, Mediaplayer
*/

function detectOS() {
	var os = '';
    if (navigator.userAgent.indexOf('Mac') != -1) {
    		os = 'mac';
        }
		else {
            os = 'win';
    }
	return os;
}

function getPlayer(mediaUrl){
	if (detectOS() == 'win') 
	{
			player = 'wmp';
			ext_test = mediaUrl.substring((mediaUrl.length)-3,(mediaUrl.length));
			if(ext_test == 'mp4')
				player = 'qt';
			else
				player = 'wmp';
	}
        else {
            player = 'qt';
			ext_test = media.substring((mediaUrl.length)-3,(mediaUrl.length));
			if(ext_test == 'mp4')
				player = 'qt';
			else
				player = 'wmp';
        }
	return player;
}

function clearMediaSpace(id_full){
	player='';
	playercode='';
	playercode_='';
	fotocode='';
	document.getElementById('mediaspace'+id_full).innerHTML = '';
}


function printPlayerCode(player,content_type,completeUrl,id,fotocode,mediawidth,mediaheight){
	var height = 1;
	var width = mediawidth;
	var id_full ="MediaPlayer"+id;
	var funcPlay = "WMPPlay"+id+"('"+id_full+"')";
	var funcStop = "WMPStop"+id+"('"+id_full+"')";
	
	try{ window.status ='loaded media from: ' + completeUrl; }catch(errorObject){};
	var imagesFolder = "http://www.vrtnieuws.net/html/images/player/";
	if (player=="wmp"){	
		playercode='';
		playercode += '<OBJECT ID="'+id_full+'" width="'+width+'" height="' + height + '" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
		playercode += '	<PARAM NAME="url" VALUE="'+completeUrl+'">';
		playercode += '	<PARAM NAME="uiMode" VALUE="none">';
		playercode += '	<PARAM NAME="AutoStart" VALUE="0">';
		playercode += '	<PARAM NAME="ShowControls"   VALUE="0">';
		playercode += '	<PARAM NAME="Name"         	VALUE="'+id_full+'">';
		playercode += '	<PARAM NAME="Id"         	VALUE="'+id_full+'">';
		playercode += '	<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" clsid="{6BF52A52-394A-11d3-B153-00C04F79FAA6}"';
		playercode += '	  src="'+completeUrl+'"';
		playercode += '	  name="'+id_full+'"';
		playercode += '	  id="'+id_full+'"';
		playercode += '	  width="'+width+'"';
		playercode += '   height="' + height + '"'; 
		playercode += '	  uiMode="none" showControls="0"';
		playercode += '	  autostart="0"';
		playercode += '	  ></embed>';
		playercode += '	</OBJECT>';
		//alert(replaceChars(playercode));
		if ((  navigator.userAgent.indexOf('Netscape') >= 0) ||  ( navigator.userAgent.indexOf('Gecko') >= 0) || (navigator.userAgent.indexOf("Firefox") > 0)||(navigator.userAgent.indexOf("Mac") > 0)){
			playercode_ = '<img src="' + imagesFolder + 'wm_play.gif" OnClick="javascript:'+funcPlay+'";" alt="fragment play"  align="top">';
			playercode_ += '<img src="' + imagesFolder + 'wm_stop.gif" OnClick="try{ document.'+id_full+'.Stop();}catch(errorObject){ try{document.'+id_full+'.controls.stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').Stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').controls.stop()}catch(errorObject){ try{'+funcStop+';}catch(errorObject){location.reload();} } }} } " alt="fragment stoppen"  align="top">';
			playercode_ += '<img src="' + imagesFolder + 'wm_controlbar.gif" width="'+eval(width+"-32")+'" height="16" align="top">';
		}else{
			if(content_type == 'video'){
				height=mediaheight;
				playercode_ = '<img src="' + imagesFolder + 'wm_play.gif" OnClick="document.'+id_full+'.height='+"'"+height+"'"+';nondisplayFoto('+"'"+id+"'"+');try{document.'+id_full+'.Play();}catch(errorObject){document.'+id_full+'.controls.play()}"  alt="fragment afspelen"  align="top">';
				playercode_ += '<img src="' + imagesFolder + 'wm_stop.gif" OnClick="document.'+id_full+'.height='+"'"+"1"+"'"+';displayFoto('+"'"+id+"'"+');try{document.'+id_full+'.Stop()}catch(errorObject){ try{document.'+id_full+'.controls.stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').Stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').controls.stop()}catch(errorObject){ location.reload();} } } } " alt="fragment stoppen"  align="top">';						
			}else{
				height = 1;
				playercode_ = '<img src="' + imagesFolder + 'wm_play.gif" OnClick="document.'+id_full+'.height='+"'"+height+"'"+';try{document.'+id_full+'.Play();}catch(errorObject){document.'+id_full+'.controls.play()}"  alt="fragment afspelen"  align="top">';
				playercode_ += '<img src="' + imagesFolder + 'wm_stop.gif" OnClick="document.'+id_full+'.height='+"'"+height+"'"+';try{document.'+id_full+'.Stop()}catch(errorObject){ try{document.'+id_full+'.controls.stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').Stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').controls.stop()}catch(errorObject){ location.reload();} } } } " alt="fragment stoppen"  align="top">';
			}
			
			playercode_ += '<img src="' + imagesFolder + 'wm_pause.gif" OnClick="try{document.'+id_full+'.Pause()}catch(errorObject){document.'+id_full+'.controls.pause()}"  alt="fragment pauzeren"  align="top">';
			playercode_ += '<img src="' + imagesFolder + 'wm_controlbar.gif" width="'+eval(width+"-48")+'" height="16">';
		}
	
	}else if (player=="qt"){
		if(content_type == 'video'){
			height = eval(mediaheight+"+ 17");
		}else{
			height = 17;
		}
		playercode='';
		playercode += '<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
		playercode += '	codebase="" ';
		playercode += '	        width="'+width+'" height="'+ height +'" ';
		playercode += '        id="'+id_full+'" > ';
		playercode += '        <PARAM name="src" value="'+completeUrl+'"> ';
		playercode += '        <PARAM name="scale" value="aspect"> ';
		playercode += '        <PARAM name="autoplay" value="false"> ';
		//playercode += '        <PARAM name="QTNEXT1" value="play"> ';
		playercode += '        <PARAM name="TARGET1" value="_self"> ';
		playercode += '        <PARAM name="enablejavascript" value="true"> ';
		playercode += '		   <PARAM name="bgcolor" value="000000">';		
		playercode += '        <PARAM name="pluginspage" value="http://www.apple.com/quicktime/download/"> ';	
		playercode += '        <PARAM name="type" value="video/quicktime"> ';	
		
		playercode += '	<embed src="'+completeUrl+'" ';
		playercode += '	width="'+width+'" ';
		playercode += '	height="'+ height + '" ';
		playercode += '	border="0" ';
		playercode += '	scale="aspect"';
		playercode += '	controller="true" ';
		playercode += '	bgcolor="000000" ';
		playercode += '	autoplay="false"';
		playercode += '	name="'+id_full+'"';
		playercode += '	id="'+id_full+'"';
		//playercode += '	qnext1="play"';
		playercode += '	target1="_self"';
		playercode += '	enablejavascript="true" type="video/quicktime"';
		playercode += '	pluginspage="http://www.apple.com/quicktime/download/"';
		playercode += '></embed>';
		playercode += ' </OBJECT>'; 
	}
}


var xplayer; 
var plugin; 
var hasActiveX=false;

try{
 	if(window.ActiveXObject)
  	{
       hasActiveX = true;
       xplayer = new ActiveXObject("WMPlayer.OCX.7");
    }
    else if (window.GeckoActiveXObject)
    {
     	hasActiveX = true;    
      	xplayer = new GeckoActiveXObject("WMPlayer.OCX.7");
   	}
  } catch(oError) { }
  try{
 		if(navigator.mimeTypes)
  		{
      		plugin = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin; 
   		} 
  }catch (oError) {}

var haveqt = false;	


// this is een hack for firefox Play()
function printPlayerCode2(player,content_type,completeUrl,id,fotocode,width,mediaheight){
	var id_full ="MediaPlayer"+id;
	var funcPlay = "WMPPlay"+id+"('"+id_full+"')";
	var funcStop = "WMPStop"+id+"('"+id_full+"')";
	
	try{ window.status ='loaded media from: ' + completeUrl; }catch(errorObject){};

	var height;
	var imagesFolder = "http://www.vrtnieuws.net/html/images/player/";
	if (player=="wmp"){	
		if(content_type == 'video'){
			height = mediaheight;
		}else{
			height = 1;
		}
		
		playercode='';
		playercode += '<OBJECT ID="'+id_full+'" width="'+width+'" height="' + height + '" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
		playercode += '	<PARAM NAME="url" VALUE="'+completeUrl+'">';
		playercode += '	<PARAM NAME="uiMode" VALUE="none">';
		playercode += '	<PARAM NAME="AutoStart" VALUE="1">';
		playercode += '	<PARAM NAME="ShowControls"   VALUE="0">';
		playercode += '	<PARAM NAME="Name"         	VALUE="'+id_full+'">';
		playercode += '	<PARAM NAME="Id"         	VALUE="'+id_full+'">';
		playercode += '	<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" clsid="{6BF52A52-394A-11d3-B153-00C04F79FAA6}"';
		playercode += '	  src="'+completeUrl+'"';
		playercode += '	  name="'+id_full+'"';
		playercode += '	  id="'+id_full+'"';
		playercode += '	  width="'+width+'"';
		playercode += '   height="' + height + '"'; 
		playercode += '	  uiMode="none" showControls="0"';
		playercode += '	  autostart="1"';
		playercode += '	  ></embed>';
		playercode += '	</OBJECT>';

		if ((  navigator.userAgent.indexOf('Netscape') >= 0) ||  ( navigator.userAgent.indexOf('Gecko') >= 0) || (navigator.userAgent.indexOf("Firefox") > 0)||(navigator.userAgent.indexOf("Mac") > 0)){ 
			playercode_ = '<img src="' + imagesFolder + 'wm_play.gif" OnClick="javascript:'+funcPlay+'";" alt="fragment play"  align="top">';
			playercode_ += '<img src="' + imagesFolder + 'wm_stop.gif" OnClick="try{ document.'+id_full+'.Stop();}catch(errorObject){ try{document.'+id_full+'.controls.stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').Stop()}catch(errorObject){ try{document.getElementById(\''+id_full+'\').controls.stop()}catch(errorObject){ try{'+funcStop+';}catch(errorObject){location.reload();} } }} } " alt="fragment stoppen"  align="top">';
			playercode_ += '<img src="' + imagesFolder + 'wm_controlbar.gif" width="'+eval(width+"-32")+'" height="16" align="top">';
		}
	}
}

function nondisplayFoto(id){
document.getElementById("fotoMediaPlayer"+id).style.display = "none";
}

function displayFoto(id){
document.getElementById("fotoMediaPlayer"+id).style.display = "inline";
}

