
function detectPlayer(media)
{
	str = document.getElementById(media.id).getAttribute('classid');
	if(str.indexOf("22D6F312")>0)
		return 1;//ms
	if(str.indexOf("CFCDAA03")>0)
		return 2;//real
	if(str.indexOf("02BF25D5")>0)
		return 3;//qt
}

function timerInit(media, player)//проверка состояния звукового потока
{
    switch(detectPlayer(media))
    {
		case 1:	//MSPlayer
		{
	       
			if(media.Mute)
			{
				CallFlash(player,'muteSound', "True");	
			}
			else
			{
				CallFlash(player,'muteSound', "False");
			}
			break;
		}
		case 2:	//RealOnePlayer
			break;
		case 3: //QTime
		{
			if(media.GetMute())
			{
				CallFlash(player,'muteSound', "True");	
			}
			else
			{
				CallFlash(player,'muteSound', "False");
			}
			break;
		}
    }
}
//for video output
function RunVideoFSCommand(command, args, media, player)
{
			if(!command) return;
		
//    var controlObj = isInternetExplorer ? document.all.control : document.control;

    switch(detectPlayer(media,player))
    {
		case 1:	//MSPlayer
		{
			if (command == "play")
			{
				if(!media.HasError)
				{
					media.Play();
				}
			}
			if (command == "pause")
				if(!media.HasError)			
			{
				if(media.GetCurrentEntry()!=0)
					media.Pause();
			}
			if (command == "stop")
				if(!media.HasError)			
			{
				//alert(media.PlayState +":"+args);	
				if(media.PlayState==0)
					media.CurrentPosition = 0;			
				if(args!=0)
					media.Stop();
			}	
	        if (command == "rewind")
   				if(!media.HasError)
		    {
                if(media.GetCurrentEntry()!=0)
                {
			        media.CurrentPosition=0;
                    media.Play();
                }
			}
			if (command == "drag")
				if(!media.HasError)
			{
                var param = args.split('|');
                media.CurrentPosition = Math.round(media.Duration*param[0]/param[1]);
			}
			if (command == "mute")
				if(!media.HasError)
			{
                media.Mute = !media.Mute;
                CallFlash(player,'muteSound', media.Mute);
		    }
		    if(command = "timer")
		    {
	    			    params = media.CurrentPosition+'|'+media.Duration;
		 			CallFlash(player,'track', params);
		    }
		    break;
		}
		case 2:	//RealOnePlayer
		{
			if (command == "play")
			{
				media.DoPlay();
			}
			if (command == "pause")
			{
				media.DoPause();
			}
			if (command == "stop")
			{
				media.SetPosition(0);
				media.DoStop();
	        }
		    if (command == "rewind")
			{
				media.DoStop();
				media.DoPlay();
			}
			if (command == "drag")
			{
                var param = args.split('|');
                media.SetPosition(Math.round(media.GetLength()*param[0]/param[1]));
	        }
		    if (command == "mute")
			{
				if(!media.GetMute()) 
				{
					media.SetMute(true); 
					CallFlash(player,'muteSound', "True");
				}
				else 
				{
					media.SetMute(false);
					CallFlash(player,'muteSound', "False");
				}
		    }
		    if(command =="timer")
		    {
		    //
		    }
			break;
		}
		case 3: //QTime
		{
	        if(command == "play")
		    {
				media.Play();
				timerInit(media,player);
			}
			if (command == "pause")
			{
				media.Stop();
		    }
			if (command == "stop")
	        {
	        //alert(args);
				if(args!=0)
				{
					media.Stop();
					media.Rewind();
				}
			}
			if (command == "rewind")
			{
				media.Rewind();
	        }
	        if (command == "drag")
		    {
                var param = args.split('|');
                media.SetTime(Math.round(media.GetDuration()*param[0]/param[1]));
			}
			if (command == "mute")
			{
				if(!media.GetMute())
				{
					media.SetMute(true); 
					CallFlash(player,'muteSound', "True");	
				}
				else
				{
					media.SetMute(false); 
					CallFlash(player,'muteSound', "False");
				}                
			}
			if(command == "timer")
			{
				params = (media.GetTime()/600)+'|'+(media.GetDuration()/600);
				CallFlash(player,'track', params);
				if(media.GetTime()==media.GetDuration())
					CallFlash(player,'stopButton.onRelease', 3);
			}
			break;
		}
    }
}
//for audio output
function RunAudioFSCommand(command, args, media, player)
{
	if(!command) return;
		
   			//controlObj = isInternetExplorer ? document.all.control : document.control;

			if (command == "play")
			{
				if(!media.HasError)
				{
					media.Play();
				}
			}
			if (command == "pause")
				if(!media.HasError)			
			{
				if(media.GetCurrentEntry()!=0)
					media.Pause();
			}
			if (command == "stop")
				if(!media.HasError)			
			{
				if(args!=0)
					media.Stop();
			}	
	        if (command == "rewind")
   				if(!media.HasError)
		    {
                if(media.GetCurrentEntry()!=0)
                {
			        media.CurrentPosition=0;
                    media.Play();
                }
			}
			if (command == "drag")
				if(!media.HasError)
			{
                var param = args.split('|');
                media.CurrentPosition = Math.round(media.Duration*param[0]/param[1]);
			}
			if (command == "mute")
				if(!media.HasError)
			{
                media.Mute = !media.Mute;
                CallFlash(player,'muteSound', media.Mute);
		    }
		    if(command = "timer")
		    {
	    			    params = media.CurrentPosition+'|'+media.Duration;
		 			CallFlash(player,'track', params);
		    }
}
//вызов функции флеш
function CallFlash(movie,function_name, parameters)
{
        movie.SetVariable('_root.function_params', parameters);
        movie.SetVariable('execute_function', function_name);
}

