var sPosition;
var bolIsPlaying;
var idVideoClockTimer;
//document.onmousedown=dragLayer
document.onmouseup=new Function("dragMe=false");

tempMute=0
function StopSet() 
			{
			document.javademo.DoStop();
			bolIsPlaying=false;
			window.clearInterval(idVideoClockTimer);
			tempPlay=0;
			

			}

function muteSet() {
        if(document.javademo.GetMute() && tempMute==0)
        {
			tempMute=1;
			document.javademo.SetMute(false);
			document.getElementById('smute').src='/Arabic/Media/Audio/images/Tools_13.gif';
			document.getElementById('smute').title="Play sound";
        }
        else
        {
			tempMute=0;
			document.javademo.SetMute(true);
			document.getElementById('smute').src='/Arabic/Media/Audio/images/Tools_013.gif';
			document.getElementById('smute').title="Mute Sound";

        }
}

tempPlay=0
function PlayPauseSet() {
        if(!document.javademo.DoPlay() && tempPlay==0)
        {
              tempPlay=1;
              document.javademo.DoPlay();
              document.getElementById('splay').src='/Arabic/Media/Audio/images/Tools_003.gif';
				document.getElementById('splay').title="Play Now";
				bolIsPlaying = true;
				idVideoClockTimer = window.setInterval("intervalCalls()", 200);
			}
       else 
        {
				tempPlay=0;
				document.javademo.DoPause();
				document.getElementById('splay').src='/Arabic/Media/Audio/images/Tools_03.gif';
				document.getElementById('splay').title="Pause Now";
				bolIsPlaying = false;

        }
}

function RewindButton () {
	var pos;
   pos = document.javademo.GetPosition();
   if (pos  > 5000) {
       pos -= 5000;
      }
   else {
      pos = 0;
      //document.javademo.DoStop();
      }
	document.javademo.SetPosition(pos);
}


function FastForwardButton () {
   var pos;
	pos = document.javademo.GetPosition();
	if (pos > 0) {
       pos += 5000;
      }
	document.javademo.SetPosition(pos);
}

function chgvolume() {
	volumeLenght= document.getElementById('SoundDrag').style.pixelLeft;
	document.javademo.SetVolume(volumeLenght);
	document.getElementById('SoundDrag').title=volumeLenght*2;

	//document.getElementById('VolumeCounter').innerText=volumeLenght;
}


// Drag and move engine (original code by DynamicDrive.com), don't change unless explicitely indicated
var dragMe=false, kObj, xPos , direction, kObj1, xPos1


function moveLayer() {
if (event.button==1 && dragMe) {
	oldX = kObj.style.pixelLeft; kObj.style.pixelLeft=temp2+event.clientX-xPos;
// Limit movement of knob to stay inside layer
	if (kObj.style.pixelLeft > oldX) direction="left"; else direction="right";
	if (kObj.style.pixelLeft < 0 && direction=="right") {kObj.style.pixelLeft=0; direction="left";}
	if (kObj.style.pixelLeft > 50 && direction=="left") {kObj.style.pixelLeft=50; direction="right";
		}
	chgvolume();
	return false; }
}

function dragLayer() {
if (!document.all) return;
if (event.srcElement.className=="drag")	{dragMe=true; kObj=event.srcElement; 
temp2=kObj.style.pixelLeft; xPos=event.clientX; 
document.onmousemove=moveLayer; }
}



function videoClock()
{

	var intTimeRemaining;
	var intHours;
	var intMinutes;
	var intSeconds;

	var strHours="00";
	var strMinutes="00";
	var strSeconds="00";
	var strTime;

	if (bolIsPlaying) // check to make sure video is playing
		{
		intTimeElapsed=document.javademo.GetPosition(); // get the time elapsed
		intTimeElapsedEnd=document.javademo.GetLength(); // indicates total lenght of clip

		// Calculations to convert from milliseconds into standard 0:00:00 time format
		intTimeElapsed=Math.floor(intTimeElapsed/1000); // round down to the nearest integer, and divide by 1000 to convert to seconds
		intHours=Math.floor(intTimeElapsed/3600); // get hours (3600 seconds / hour)
		intMinutes=Math.floor(intTimeElapsed/60); // get minutes (60 seconds / minite)
		intSeconds=(intTimeElapsed%60); // get seconds (total seconds modulous 60)
		
		intTimeElapsedEnd=Math.floor(intTimeElapsedEnd/1000); // round down to the nearest integer, and divide by 1000 to convert to seconds
		intHours2=Math.floor(intTimeElapsedEnd/3600); // get hours (3600 seconds / hour)
		intMinutes2=Math.floor(intTimeElapsedEnd/60); // get minutes (60 seconds / minite)
		intSeconds2=(intTimeElapsedEnd%60); // get seconds (total seconds modulous 60)

		strHours=intHours;
		strMinutes=intMinutes;
		strSeconds=intSeconds;
		
		strHours2=intHours2;
		strMinutes2=intMinutes2;
		strSeconds2=intSeconds2;

		// insert zeros in front of time elapsed where necissary ( < 10 ) to preserve hh:mm:ss format
		if (intSeconds < 10 )
			strSeconds="0" + strSeconds;
if (intSeconds2 < 10 )
			strSeconds2="0" + strSeconds2;

		if (intMinutes < 10 )
			strMinutes="0" + strMinutes;
if (intMinutes2 < 10 )
			strMinutes2="0" + strMinutes2;
			
		if (intHours < 10 )
			strHours="0" + strHours;
if (intHours2 < 10 )
			strHours2="0" + strHours2;

		strTime=strHours + ":" + strMinutes + ":" + strSeconds; // create time string
		endTime=strHours2 + ":" + strMinutes2+ ":" + strSeconds2; // create time string

		divVideoClock.innerText=strTime; // update clock div
		divVideoClockend.innerText=endTime; // update clock div
		
		}
}


function intervalCalls()
{
	videoClock();
}


