function Mail_flash(url){document.write('<object width="500 height=400 classid=clsid27cdb6e-ae6d-11cf-96b8-444553540000"><param name="wmode" value="opaque"><param name="allowFullScreen" value="true"><param name="flashvars value=orig=2"><param name="movie value=http://img.mail.ru/r/video2/player_v2.swf?par='+url+'"><embed src="http://img.mail.ru/r/video2/player_v2.swf?par='+url+'" flashvars="orig=2" allowfullscreen="true" wmode="opaque" width="500" height="400"></object>');}
function Jan_flash(url){document.write('<object width="500" height="350"><param name="video" value="'+url+'"></param><param name="allowFullScreen" value="true"></param><param name="scale" value="noscale"></param><embed src="'+url+'" type="application/x-shockwave-flash" width="500" height="350" allowFullScreen="true" scale="noscale" ></embed></object>');}
function flash(url){document.write('<EMBED src="http://nashgorod.pnz.ru/mediaplayer.swf" type="application/x-shockwave-flash" allowfullscreen="true" flashvars="&file='+url+'&height=400&width=500&location=http://nashgorod.pnz.ru/mediaplayer.swf" height="400" width="500" />');}
function fr(url,w,h){document.write('<iframe src="'+url+'" width="'+w+'" height="'+h+'" bgcolor="#dddddd" scrolling="no" frameborder="0" allowtransparency="true" allowFullScreen="true" allowScriptAccess="always"></iframe>');}
function jw(file){document.write('<embed src="http://tv-here.ru/player/player.swf" flashvars="file=http://tv-here'+file+'&config=http://tv-here.ru/player/config.xml" width="500" height="400" bgcolor="#ffffff" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />');}
function vlc(url){document.write('<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" codebase="http://www.videolan.org/" width="500"  height="400" id="vlc" events="True"><param name="MRL" value="" /><param name="ShowDisplay" value="True" /><param name="Src" value="'+url+'" /><param name="AutoPlay" value="true" /><param name="Volume" value="25" /><EMBED pluginspage="" type="application/x-vlc-plugin" progid="VideoLAN.VLCPlugin.2" width="500" height="400" name="vlc" target="'+url+'" autoplay="true" autoloop="true" volume="25"></EMBED></OBJECT><BR><img src="http://nashgorod.pnz.ru/Filmi_2010/vlc600.gif" width="500" height="20" border="0" usemap="#playerbuttons"><map name="playerbuttons"><area shape="rect" coords="25,0,60,20" href="javascript:doPlay();" title="Воспроизведение"><area shape="rect" coords="80,0,120,20" href="javascript:doStop();" title="Стоп"><area shape="rect" coords="366,0,432,20" href="javascript:doFS()" title="На весь экран"><area shape="rect" coords="444,0,464,20" href="javascript:Mute();" title="Звук откл."><area shape="rect" coords="465,0,478,20" href="javascript:updateVolume(5);" title="Громкость +"><area shape="rect" coords="479,0,492,20" href="javascript:updateVolume(-5);" title="Громкость -"></map>'); doGo(url);}
var prevState = 0;
var monitorTimerId = 0;
var isIE = 0;
//----------------------------------------------------
function startvlc(){
    isIE	= 1;
    if( navigator.appName.indexOf("Microsoft Internet")==-1 )
    {
        onVLCPluginReady()
	isIE	= 0;
    }
    else if( document.readyState == 'complete' )
    {
        onVLCPluginReady();
    }
    else
    {
        /* Explorer loads plugins asynchronously */
        document.onreadystatechange=function() {
            if( document.readyState == 'complete' )
            {
                onVLCPluginReady();
            }
        }
    }
}

//----------------------------------------------------
//----------------------------------------------------
function getVLC(name)
{
    if (window.document[name]) 
    {
        return window.document[name];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1)
    {
        if (document.embeds && document.embeds[name])
            return document.embeds[name]; 
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(name);
    }
}

//----------------------------------------------------
function onVLCPluginReady()
{
    updateVolume(0);
};

//----------------------------------------------------
function updateVolume(deltaVol)
{
    var vlc = getVLC("vlc");
    vlc.audio.volume += deltaVol;
//    document.getElementById("volumeTextField").innerHTML = vlc.audio.volume+"%";
};

//----------------------------------------------------
function doPlay()
{
    var vlc = getVLC("vlc");
    if( vlc.playlist.isPlaying )
    {
        vlc.playlist.Play();
    }
    else if( vlc.playlist.items.count > 0 )
    {
        vlc.playlist.play();
        monitor();
    }
    else
    {
        // disable log
        vlc.log.verbosity = -1;
        alert('nothing to play !');
    }
};
//----------------------------------------------------
function doStop()
{
    getVLC("vlc").playlist.stop();
//    if( monitorTimerId != 0 )
//    {
//        clearInterval(monitorTimerId);
//        monitorTimerId = 0;
//    }
    onStop();
};
//----------------------------------------------------
function onStop()
{
    var vlc = getVLC("vlc");
    // disable logging
    vlc.log.verbosity = -1;
};
//----------------------------------------------------
function doFS()
{
	getVLC("vlc").video.toggleFullscreen();
};
//----------------------------------------------------
function Mute()
{
	getVLC("vlc").audio.toggleMute();
};
//----------------------------------------------------
function doGo(targetURL)
{
    var vlc = getVLC("vlc");
    var options = new Array(":aspect-ratio=default");
    vlc.playlist.items.clear();
    //while( vlc.playlist.items.count > 0 )
    //{
        // clear() may return before the playlist has actually been cleared
        // just wait for it to finish its job
    //}
    //var itemId = vlc.playlist.add(targetURL, null, options);
  // MS Voodoo, for some obvious reason upper call won't work with IE
    var itemId;
    if( isIE )	{
	    itemId	= vlc.playlist.add(targetURL);
    } else {
    	    itemId 	= vlc.playlist.add(targetURL, null, options);
    }
    if( itemId != -1 )
    {
        // clear the message log and enable error logging
        vlc.log.verbosity = 1;
        vlc.log.messages.clear();
        // play MRL
        vlc.playlist.playItem(itemId);
        if( monitorTimerId == 0 )
        {
            monitor();
        }
    }
    else
    {
        // disable log
        vlc.log.verbosity = -1;
        alert("cannot play at the moment !");
    }
//    updateVolume(50);
};

//----------------------------------------------------
function monitor()
{
    var vlc = getVLC("vlc");
    if( vlc.log.messages.count > 0 )
    {
        // there is one or more messages in the log
        var iter = vlc.log.messages.iterator();
        while( iter.hasNext )
        {
            var msg = iter.next();
            var msgtype = msg.type.toString();
            if( (msg.severity == 1) && (msgtype == "input") )
            {
               // alert( msg.message );
            }
        }
        // clear the log once finished to avoid clogging
        vlc.log.messages.clear();
    }
    var newState = vlc.input.state;
    if( prevState != newState )
    {
        if( newState == 0 )
        {
            // current media has stopped 
            onStop();
        }
        else if( newState == 1 )
        {
            // current media is openning/connecting
            // onOpen();
        }
        else if( newState == 2 )
        {
            // current media is buffering data
            //onBuffer();
        }
        else if( newState == 3 )
        {
            // current media is now playing
            //onPlay();
        }
        else if( vlc.input.state == 4 )
        {
            // current media is now paused
            //onPause();
        }
        prevState = newState;
    }
    else if( newState == 3 )
    {
        // current media is playing
        //onPlaying();
    }
    if( ! monitorTimerId )
    {
        monitorTimerId = setInterval("monitor()", 1000);
    }
};