
////////////////////////////////////////////////////////////////////////////////////
//
//    ValdoMPlEmb_Vald_Lib.js Valdymo skriptai IE 5+ vesijai
//
////////////////////////////////////////////////////////////////////////////////////


var CurPlay=false;
var ValdasPlay=false;

var ValdasFrames=false;
var ValdasSlides=false;
var ValdasTexts=false;

var timer0=null;
var timeMs=2000;

var dragobject=null;
var type;
var onchange="";
var tx, ty;

var scrollUnit;
var shuttleUnit;
var shuttleSpot;
var volUnit;
var slideUnit;
var vidSpot;

var objPlayer;
var sBrowser;
var testJ = 0;
var fColor;

var bV=parseInt(navigator.appVersion);

IE4=(document.all)?true:false;
DocAll=(IE4)?document.all:document;


function _onmousedown() 
{
  var ev=window.event.srcElement;

  if( ev.className=="sliderHandle" ) 
  {
    dragobject=ev;	
    onchange=dragobject.getAttribute("onchange");
    if ( onchange==null ) onchange = "";
    type=dragobject.getAttribute("type");
    
    if ( type=="y" ) 
    {
      ty=(window.event.clientY-dragobject.style.pixelTop);
    }
    else 
    {
      tx=(window.event.clientX-dragobject.style.pixelLeft);
    }

    window.event.returnValue=false;
    window.event.cancelBubble=true;
  }
  else 
  {
    dragobject=null;	
  }	
}


function _onmouseup() 
{
  if( dragobject ) 
  {
    dragobject = null;
  }
}


function _onmousemove() 
{
  if( dragobject ) 
  {
    if ( type=="y" ) 
    {
      if( event.clientY>=0 ) 
      {
        if ((event.clientY - ty > 0) && (event.clientY - ty < dragobject.parentElement.style.pixelHeight - dragobject.style.pixelHeight)) 
        {
          dragobject.style.top = event.clientY - ty;
        }

        if (event.clientY - ty < 2) 
        {
          dragobject.style.top = "0";
        }

        if (event.clientY - ty > dragobject.parentElement.style.pixelHeight - dragobject.style.pixelHeight - 2) 
        {
          dragobject.style.top = dragobject.parentElement.style.pixelHeight - dragobject.style.pixelHeight;
        }
				
        if ( DocAll.Horz ) 
        {
          if (dragobject.id == DocAll.Horz.id) 
          {
            volUnit = 100 / (DocAll.Volume.style.pixelHeight - 23);
            adjustvolume(volUnit*DocAll.Horz.style.posTop);
            DocAll.Volume.style.posLeft = 418 - Math.round(DocAll.Horz.style.posTop * .27 -.5);
          }
        }
	
        if ( DocAll.hor ) 
        {
          if ( dragobject.id==DocAll.hor.id ) 
          {
            dragobject.value = dragobject.style.pixelTop / (dragobject.parentElement.style.pixelHeight - dragobject.style.pixelHeight);
            shuttleUnit = (shuttleHeight - 45) / 100;
            shuttleSpot = DocAll.hor.style.pixelTop / shuttleUnit;
            scrollUnit = (DocAll.MAIN.scrollHeight - DocAll.MAIN.offsetHeight) / 100;
            DocAll.MAIN.scrollTop = shuttleSpot * scrollUnit;
          }
        }
	
        eval(onchange.replace(/this/g, "dragobject"));

        if ((event.clientX > document.body.clientWidth) || (event.clientY > document.body.clientHeight)) {dragobject = null;}
      }
    }
    else 
    {
      if( event.clientX>=0 ) 
      {
        if ( (event.clientX-tx>0) && (event.clientX - tx<dragobject.parentElement.clientWidth - dragobject.style.pixelWidth))
        {
          dragobject.style.left = event.clientX - tx;
        }
	
        if (event.clientX - tx < 2) 
        {
          dragobject.style.left = "0";
        }
	
        if (event.clientX - tx > dragobject.parentElement.clientWidth - dragobject.style.pixelWidth - 2) 
        {
          dragobject.style.left = dragobject.parentElement.clientWidth - dragobject.style.pixelWidth;
        }
	
        if (DocAll.Slider) 
        {
          if (dragobject.id == DocAll.Vert.id) 
          {
            slideUnit = 100 / (DocAll.Slider.style.pixelWidth - 4);
            changePosition(slideUnit*DocAll.Vert.style.posLeft);
          }
        }
	
        dragobject.value = dragobject.style.pixelLeft / (dragobject.parentElement.clientWidth - dragobject.style.pixelWidth);
        eval(onchange.replace(/this/g, "dragobject"));
      }
    }
		
    window.event.returnValue = false;
    window.event.cancelBubble = true;
  } 
}


function setValue(el,val) 
{
  el.value = val;

  if (el.getAttribute("TYPE") == "x")
    el.style.left =  val * (el.parentElement.clientWidth - el.style.pixelWidth);
  else
    el.style.top =  val * (el.parentElement.clientHeight - el.style.pixelHeight);

  eval(el.onchange.replace(/this/g, "el"))
}

//----------------------------------------------------------------------

function changePosition(pos) 
{
  var dur;

  if ( ValdasPlay==false ) return;

  if ( WMPVer=='6.4' ) 
  { 
    dur=eVPlay.duration/100;
    eVPlay.CurrentPosition=pos*dur;
  }
  else
  {
    dur=eVPlay.currentMedia.duration/100;
    eVPlay.controls.CurrentPosition=pos*dur;
  }

//  str=pos+"  "+dur+"  "+eVPlay.controls.CurrentPosition;
//  window.parent.frames("Valdymas").lapai.innerHTML=str; 
}

function changeTimePos(tim) 
{
  var dur;

  if ( tim<0 ) tim=0;
  if ( tim>dur ) tim=dur;

  if ( ValdasPlay==false ) return;

  if ( WMPVer=='6.4' ) 
  { 
    eVPlay.CurrentPosition=tim;
  }
  else
  {
    eVPlay.controls.CurrentPosition=tim;
  }

  PlayClick();
}


function ChangeTime() 
{
  var cur, dur, dmin, dsek, dtm, min, sek, tm, tmt, pos;

  if ( ValdasPlay==false ) return;

  if ( WMPVer=='6.4' ) 
  { 
    cur=eVPlay.CurrentPosition; 
    dur=eVPlay.duration; 
  }
  else
  {
    cur=eVPlay.controls.CurrentPosition; 
    dur=eVPlay.currentMedia.duration; 
  }

  vidSpot=dur/100; 
  slideUnit=100/(DocAll.Slider.style.pixelWidth);

  tm=Math.round(cur);
  min=Math.round((tm-30)/60); sek=tm-min*60;
  tmt=min*60+sek;

  dtm=Math.round(dur);
  dmin=Math.round((dtm-30)/60); dsek=dtm-dmin*60;

  pos=0;

  if ( WMPVer=='6.4' )
  {
    Laikas.innerHTML=min+':'+sek+' | '+dmin+':'+dsek;
    if ( eVPlay.PlayState==0 || eVPlay.PlayState==1 || eVPlay.PlayState==2 ) pos=1;
  }
  else
  {
    Laikas.innerHTML=min+':'+sek+' | '+dmin+':'+dsek;
    if ( eVPlay.PlayState==1 || eVPlay.PlayState==2 || eVPlay.PlayState==3 || eVPlay.PlayState==10 ) pos=1; 
  }

  if ( pos==1 )
  {
    if ( cur>=0 ) 
    {
      DocAll.Vert.style.posLeft=(cur/vidSpot)/slideUnit;
    }
	
    timer=window.setTimeout("ChangeTime();",500,"JavaScript");

    if ( ValdasSlides ) ChangeSlide(tmt);
  } 
  else 
  {
    return;	
  }
}


function ShowStatus() 
{
  if ( ValdasPlay==false ) return;

  if ( WMPVer=='6.4' ) 
  { 
    Laikas.innerHTML=ps64Array[eVPlay.PlayState];
  }
  else 
  { 
    Laikas.innerHTML=psArray[eVPlay.PlayState];  
  }

  return;	
}


function LoadPlayer()
{
  window.focus();
  timer=setTimeout("Refresh()",timeMs);
}

function Refresh()
{
  Stop_Play_Timer();
  timer0=setTimeout("Refresh()",timeMs);
  window.focus();
}

function Stop_Play_Timer()
{
  clearTimeout(timer0);
}


function PlayNextMarker() 
{
  if ( ValdasPlay==false ) return;

  nextMarker=parseFloat(MarkerVar)+1;

  if ( nextMarker>1 ) 
  {
    if ( WMPVer=='6.4' ) 
    { 
      eVPlay.Stop();
      eVPlay.CurrentMarker=nextMarker;
      eVPlay.Play();
    }
    else 
    { 
      eVPlay.controls.Stop();
      eVPlay.controls.CurrentMarker=nextMarker;
      eVPlay.controls.Play();
    }
  }
}

function PlayerBackMarker() 
{
  if ( ValdasPlay==false ) return;

  nextMarker=parseFloat(MarkerVar)-1;

  if ( nextMarker>0 ) 
  {
    if ( WMPVer=='6.4' ) 
    { 
      eVPlay.Stop();
      eVPlay.CurrentMarker=nextMarker;
      eVPlay.Play();
    }
    else 
    { 
      eVPlay.controls.Stop();
      eVPlay.controls.CurrentMarker=nextMarker;
      eVPlay.controls.Play();
    }
  }
}

function PlayLastMarker() 
{
  if ( ValdasPlay==false ) return;

  lastMarker=document.eVPlay.MarkerCount;
 
  if ( WMPVer=='6.4' ) 
  { 
    eVPlay.Stop();
    eVPlay.CurrentMarker=nextMarker;
    eVPlay.Play();
  }
  else 
  { 
    eVPlay.controls.Stop();
    eVPlay.controls.CurrentMarker=nextMarker;
    eVPlay.controls.Play();
  }
}

function PlayClick()
{
  if ( ValdasPlay==false ) return;

  if ( is_WMP_plugins )
  {
    if ( WMPVer=='6.4' ) 
    { 
      document.eVPlay.Play();
    }
  }
  else
  {
    if ( WMPVer=='6.4' ) 
    { 
      eVPlay.Play();
    }
    else 
    { 
      if ( eVPlay.controls.isAvailable('Play') )
        eVPlay.controls.play();
    }
  }
}

function PauseClick()
{
  if ( ValdasPlay==false ) return;

  if ( is_WMP_plugins )
  {
    if ( WMPVer=='6.4' ) 
    { 
      document.eVPlay.Pause();
    }
  }
  else
  {
    if ( WMPVer=='6.4' ) 
    { 
      eVPlay.Pause();
    }
    else 
    { 
      if ( eVPlay.controls.isAvailable('Pause') )
        eVPlay.controls.pause();
    }
  }
}

function StopClick()
{
  if ( ValdasPlay==false ) return;

  if ( WMPVer=='6.4' ) 
  { 
      eVPlay.Stop();
  }
  else 
  { 
    if ( eVPlay.controls.isAvailable('Stop') )
      eVPlay.controls.stop();
  }
}

function CloseClick()
{
  if ( ValdasPlay==false ) return;

  StopClick();
  if ( WMPVer!='6.4' ) eVPlay.close();
}


function PlayerRewind() 
{
  if ( ValdasPlay==false ) return;

  if ( WMPVer=='6.4' ) 
  { 
    eVPlay.stop();
    eVPlay.CurrentPosition=0;
    eVPlay.play();
  }
  else 
  { 
    eVPlay.controls.stop();
    eVPlay.controls.CurrentPosition=0;
    eVPlay.controls.play();
  }
}


function Switch(bar) 
{
  if ( ValdasPlay==false ) return;

  if ( WMPVer=='6.4' ) 
  { 
    eVPlay.stop();
    eVPlay.CurrentMarker=bar;
    eVPlay.play();
  }
  else 
  { 
    eVPlay.controls.stop();
    eVPlay.controls.CurrentMarker=bar;
    eVPlay.controls.play();
  }
}

function WinCloseClick()
{
  if ( ValdasPlay==false ) return;

  StopClick();
  CloseClick();
  window.close();
}

//----------------------------------------------------------------------

if ( IE4 ) 
{
  document.onmouseover = mouseOver;
  document.onmouseout = mouseOut;
  document.onmousedown = _onmousedown;
  document.onmouseup = _onmouseup;
  document.onmousemove = _onmousemove;
}

function mouseOver() 
{
  var vSrc=window.event.srcElement;

  if ( IE4 ) 
  {
    if ( vSrc.className=="mLink" ) 
    {
      fColor=vSrc.style.color;
      vSrc.style.color="#000000";
      window.event.cancelbubble==true;
    }
  }
}

function mouseOut() 
{
  var vSrc=window.event.srcElement;

  if ( vSrc.className=="mLink" ) 
  {
    vSrc.style.color=fColor;
    window.event.cancelbubble==true;
  }
}

