function vlc(url){document.write('<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" codebase="http://www.videolan.org/" width="640"  height="360" 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="install_vlc.html" type="application/x-vlc-plugin" progid="VideoLAN.VLCPlugin.2" width="640" height="360" name="vlc" target="'+url+'" autoplay="true" autoloop="true" volume="25"></EMBED></OBJECT><BR><img src="images/vlc600.gif" width="600" 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="466,0,532,20" href="javascript:doFS()" title="На весь экран"><area shape="rect" coords="544,0,564,20" href="javascript:Mute();" title="Звук откл."><area shape="rect" coords="565,0,578,20" href="javascript:updateVolume(5);" title="Громкость +"><area shape="rect" coords="579,0,592,20" href="javascript:updateVolume(-5);" title="Громкость -"></map>'); doGo(url);}
function vlc16(url){document.write('<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" codebase="http://www.videolan.org/" width="728"  height="410" 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="install_vlc.html" type="application/x-vlc-plugin" progid="VideoLAN.VLCPlugin.2" width="728" height="410" name="vlc" target="'+url+'" autoplay="true" autoloop="true" volume="25"></EMBED></OBJECT><BR><img src="images/vlc728.gif" width="728" 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="585,0,655,20" href="javascript:doFS()" title="На весь экран"><area shape="rect" coords="663,0,683,20" href="javascript:Mute();" title="Звук откл."><area shape="rect" coords="684,0,699,20" href="javascript:updateVolume(5);" title="Громкость +"><area shape="rect" coords="700,0,715,20" href="javascript:updateVolume(-5);" title="Громкость -"></map>'); doGo(url);}
var LvL_ow=[];
function LvL_iPanel(n,g){
 var i,j,k,d,b,x,k,q,p,y,h,s,el,td,pn,nw;if(!document.getElementById){return;};for(i=0;i<10;i++){
 if((b=document.getElementById("LvLpaneL"+i))!=null){LvL_ow.push(LvL_getH("LvLtarg"+i+"_1"));
 if((d=b.getElementsByTagName("LI"))!=null){for(j=0;j<d.length;j++){if(d[j].id&&d[j].id.indexOf("LvLtrig")==0){
 if(x=d[j].getElementsByTagName("A")){x[0].t=d[j].id;d[0].className="down";d[0].getElementsByTagName("SPAN")[0].className="down";
 x[0].onclick=function(){if((q=document.getElementById(this.t))!=null){p=q.parentNode.getElementsByTagName("A");
 for(k=0;k<p.length;k++){if(p[k].t){h=document.getElementById(p[k].t);s=h.getElementsByTagName("SPAN")[0];
 y=document.getElementById(p[k].t.replace("LvLtrig","LvLtarg"));if(this==p[k]){if(h.className=="down"){
 return false}y.style.display="block";s.className="down";if(g){td=q.id.replace("LvLtrig","LvLtarg");pn=q.id.charAt(7)-1;
 nw=LvL_getH(td);el=document.getElementById(td).parentNode;el.style.height=LvL_ow[pn]+"px";}if(n){LvLeffect(y.getAttribute("id"),0);
 }else{y.style.display="block";}h.className="down";h.getElementsByTagName("SPAN").className="down";}else{h.className="";s.className="";
 y.style.display="none";}}}if(g){LvL_Slide(el,LvL_ow[pn],nw,g,5,.400,pn);}this.blur();}return false;};}}}}}}
}
function LvL_getH(e){
 return document.getElementById(e).offsetHeight;
}
function LvL_Slide(e,b,f,s,i,p,pn){
 var d,st,nc;if(b==f){return}if(st!=s){e.style.overflow="hidden";}if(e.LvLmem){
 window.clearInterval(e.LvLmem);}st=0;e.LvLmem=window.setInterval(function(){d=f-b;
 nc=b+(Math.pow(((1/s)*st),p)*d);e.cH=Math.ceil(nc);e.style.height=e.cH+"px";st++;if(st>s){
 window.clearInterval(e.LvLmem);if(document.all){e.style.height="auto";}LvL_ow[pn]=e.cH;}},i);
}
function LvLeffect(id,s){
 var d=document.getElementById(id);var x=d.parentNode;if(x.filters){
 x.style.visibility='hidden';x.className+=" effect";x.filters[0].Apply();
 x.style.visibility="visible";x.filters[0].Play();}else{s+=.02;s=(s>=1)?1:s;
 d.style.opacity=s;if(s<1){setTimeout("LvLeffect('"+id+"',"+s+")",10);}}
}


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);
    }
};
//----------------------------------------------------

