
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);
}

//cookies


function getCookieSet(name)
{
	//alert(getCookie(name));
	str = getCookie(name);
	if(str)
	{
		//str.slice(",idfx,");
		cookArray = str.split(",idfx,");
		k=0;
		for(i=0;i<document.forms.length;i++)
		{
			
			for(j=0;j<document.forms[i].elements.length;j++)
			{
				if(document.forms[i].elements[j].type=='radio')
				{
					if(cookArray[k]=="false")
						document.forms[i].elements[j].checked=0;
					else
						document.forms[i].elements[j].checked=1;
					k++;
				}
				if(document.forms[i].elements[j].type=='checkbox')
				{
					if(cookArray[k]=="false")
						document.forms[i].elements[j].checked=0;
					else
						document.forms[i].elements[j].checked=1;
					k++;
				}
				if(document.forms[i].elements[j].type=='textarea')
				{
					str+=document.forms[i].elements[j].value=cookArray[k];
					k++;
				}
				if(document.forms[i].elements[j].type=='text')
				{
					str+=document.forms[i].elements[j].value=cookArray[k];
					k++;
				}
				if(document.forms[i].elements[j].type=='select-one')
				{
					str+=document.forms[i].elements[j].value=cookArray[k];
					k++;
				}
				
			}

		}
	}
	return str;
}

//------------------------cookies--------------------------
function setCookie(name, value, expires, path, domain, secure) 
{
	var expDays = 300;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	expires = exp;
	path = "/";
	var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        document.cookie = curCookie;
		
}

function getCookie(name)
{
	var prefix = name + "=";
    var cookieStartIndex = document.cookie.indexOf(prefix);
	    if (cookieStartIndex == -1)
        {
            return null;
        }
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
        if (cookieEndIndex == -1)
            cookieEndIndex = document.cookie.length;
    return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie(name, path, domain)
{	
	path = "/";
    if (getCookie(name)) 
    {
          document.cookie = name + "=" +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
           "; expires=Thu, 30-Apr-04 23:50:01 GMT"
	}
}
