var varr = new Array();
    varr[0]=0;
    varr[1]=7;
    varr[2]=14;
    varr[3]=21;
    varr[4]=28;
    varr[5]=35;
    varr[6]=42;
    varr[7]=49;
    varr[8]=56;
    varr[9]=63;
    varr[10]=70;
    varr[11]=77;
    varr[12]=84;
    varr[13]=100;

    var gN=0;
		var gV=0;
		var gDrag=0;
		var gDragInx=6;
		var gDragX=0;
		var	gImgDestI;
		var gImgDestN;
		var gVol=0;
		var gVolPos;
		var gVMouseX;
		var gVMouseY;
		var gNewVolX;
		var gFullScr=0;
		var g_arrVolume=new Array(10);
		var gIsPressedStop=false;
		var G_START_PLAY=83;
		var G_VOL_START;
		var G_VOL_LENGTH=60;
    var ARR_SIZE=100;
		var vIsPlay = new Array(ARR_SIZE);
    var StateFlag = new Array(ARR_SIZE);
    var next = new Array(ARR_SIZE);
    var CanSetPos = new Array(ARR_SIZE);
    var SetPosStart = new Array(ARR_SIZE);
    var orix = new Array(ARR_SIZE);
    var moveon = new Array(ARR_SIZE);
    var movelen = new Array(ARR_SIZE);
    var dragapproved = new Array(ARR_SIZE);
    var z;
    var x;
    var y;
    var temp1;
    var temp2;

    for(var i=0; i<ARR_SIZE; i++){
	   StateFlag[i]=0;
    	next[i]=1;
    	CanSetPos[i]=true;
    	SetPosStart[i]=false;
    	orix[i]=0;
    	moveon[i]=false;
    	movelen[i]=417;
    	dragapproved[i]=false;
			vIsPlay[i]=0;
    }


    function doPlay(n){
		try{
	   		window.document.getElementById("player"+n).Controls.play();
		 		gIsPressedStop=false;
		 		//window.document.getElementById("divPict"+n).style.display="none";
		 		window.document.getElementById("divScreen"+n).style.display="";
			}			
			catch(err){
							 ;
		}
    }


    function doStop(n){
		 vIsPlay[n]=0;
	   window.document.getElementById("player"+n).Controls.stop();
		 gIsPressedStop=true;
		 window.document.getElementById("divScreen"+n).style.display="none";
		// window.document.getElementById("divPict"+n).style.display="";
    }



    function doPause(n){
		try{
	   		window.document.getElementById("player"+n).Controls.pause();
			}
			catch(err){
							 ;
		}
    }


    
    function doFastForward(n){
	   window.document.getElementById("player"+n).Controls.FastForward();
    }



    function FullScreen(n){
			try{	
						var p=window.document.getElementById("player"+n);	
							 if (p.playState==3)
							 {
							 	
							 		if(gFullScr>0)
									{
									 			
							 			window.document.getElementById("player"+gFullScr).fullScreen = 'false';
									  
								  }
	   					 		p.fullScreen = 'true';
									gFullScr=n;
									
							}
							 
		  }
		  catch(err){;}
    }


//Mute or unMute the volume
    function doVolumeMute(n){
	   var p=window.document.getElementById("player"+n);
	   if(p.Settings.mute==true){
      		p.Settings.mute=false;
      		window.document.getElementById("mButton"+n).src='images/sound.gif';
					window.document.getElementById("spnSound"+n).innerHTML="השתק סאונד";
   	    }
       else
   	    {
      		p.Settings.mute=true;
      		window.document.getElementById("mButton"+n).src='images/sound_.gif';
					window.document.getElementById("spnSound"+n).innerHTML="הפעל סאונד";
   	    }
    }


//Change the volume
function adjVol(n,num)
{
	if (num == null)num = 7;
	if (num>13) num=13;
	if (num<0) num=0;

	nVol=num;
  window.document.getElementById("player"+n).Settings.volume=varr[nVol];
}

//Write current and total time
function sdu(n)
{
	var p=window.document.getElementById("player"+n);
	try { var time_str=p.controls.currentPositionString; } catch(e){}
	try { window.document.getElementById("times"+n).innerHTML = time_str+" / "+p.currentMedia.durationString;}	catch(e){}
	try	{ window.document.getElementById("status"+n).innerHTML=p.currentMedia.getItemInfo('TITLE');	}	catch(e){}
}



function playMedia(n){
	try{
		var p=window.document.getElementById("player"+n);
		showPos(n);
		
		//Set "Play" after movie end
		if(p.status=="Stopped" && gIsPressedStop==false)
		{
		 			doStop(n);
					window.document.getElementById("imgPlay"+n).src='images/play_.gif';
					vIsPlay[n]=0; 
					gIsPressedStop=true;
					doPause(n);
		}
		
		window.setTimeout("playMedia("+n+")",1000);
	}
	catch(err){;}
}


function moves(n)
{
	if(CanSetPos[n] && event.button!=2)
        {
 		orix[n]=event.x;
		orileft[n]=window.document.getElementById("trackball"+n).style.pixelLeft;
                SetPosStart[n]=true;
        }
        else
        {
                return false;
        }
}

//Set position of the movie
function setpos(n)
{
	var p=window.document.getElementById("player"+n);
	SetPosStart[n]=false;
	var newleft=window.document.getElementById("trackball"+n).style.pixelLeft-G_START_PLAY;
	var rcp=newleft * p.currentMedia.duration / movelen[n];
	p.controls.currentPosition  = rcp;

}


//Show slider position
function showPos(n){
	try{
		var p=window.document.getElementById("player"+n);
		if(SetPosStart[n])return;
	  var blockpos=movelen[n]*p.controls.currentPosition/p.currentMedia.duration;			
		var tmp=G_START_PLAY;
		if(blockpos)tmp+=blockpos;

	  window.document.getElementById("trackball"+n).style.pixelLeft=tmp;
		window.document.getElementById("trackbg"+n).style.width=tmp-G_START_PLAY;
	}
	catch(err){;}
}

//Move volume slider	
function moveVolume(){
	if(event.button==1 && gVol==1)
	{
	 		var newPosX=gNewVolX + event.clientX - gVMouseX;
			var part;
			//Check desired volume position in reqiered interval
			if(newPosX <=	G_VOL_START || newPosX >= G_VOL_START + G_VOL_LENGTH-7)
						return;
			else
			{
			 		window.document.getElementById("spnVolSlider"+gV).style.pixelLeft=newPosX;
					window.document.getElementById("imgVolWhite"+gV).style.width=newPosX-G_VOL_START;
					part=G_VOL_LENGTH/13;
					gVolPos=(newPosX-G_VOL_START-7)/part;	
					gVolPos=parseInt(gVolPos);
					adjVol(gV,gVolPos);
					
					return false;		 
			}	
	}
}	

//Move movie slider
function move(){
	if (event.button==1 && dragapproved[gN]){
        	var newPosX = temp1+event.clientX-x;
          if(newPosX <=G_START_PLAY || newPosX > G_START_PLAY + movelen[gN])
								return;
          window.document.getElementById("trackball"+gN).style.pixelLeft=newPosX;
					window.document.getElementById("trackbg"+gN).style.width=newPosX-G_START_PLAY;
          rcp=newPosX * window.document.getElementById("player"+gN).currentMedia.duration / movelen[gN];
					return false;
        }
}

function drags(){
	if (!document.all)return;
		if(event.srcElement.id=="imgPointer"+gN)
		{
  	  dragapproved[gN]=true;
  		temp1=window.document.getElementById("trackball"+gN).style.pixelLeft;
  		temp2=window.document.getElementById("trackball"+gN).style.pixelTop;
			x=event.clientX;
		  y=event.clientY;
		  document.onmousemove=move;
			SetPosStart[gN]=true;
		}	 
  
}


function volMouseDown(n){
				gVol=1;
				gNewVolX=window.document.getElementById("spnVolSlider"+n).style.pixelLeft;
				gVMouseX=event.clientX;
		  	gVMouseY=event.clientY;
		  	document.onmousemove=moveVolume;
}


function mouseUped(){
	if(gVol==1 && event.srcElement.id=="imgVolSlider")
	{
		gVol=0;
		gV=0;
	}
	else if(gN!=0)
	{
	 		 dragapproved[gN]=false;
       if(SetPosStart[gN])
			 		setpos(gN);
	}
}


function init(n){
	G_START_PLAY=window.document.getElementById("trackball"+n).style.pixelLeft;
	G_VOL_START=window.document.getElementById("spnVolWhite"+n).style.pixelLeft;
	setVolume(n);
	setDescription(n);
	document.onmousedown=drags;
	document.onmouseup=mouseUped;
	document.body.onmousedown=drags;
	document.body.onmouseup=mouseUped;
	
	if (window.Event)
	{
		 document.captureEvents(Event.MOUSEUP);
	}
}


function mouseOnSound(imgObj,n){
	var p=window.document.getElementById("player"+n);
	imgObj.src=(p.Settings.mute)?"images/sound_off.gif":"images/sound_on_.gif";
}

function mouseOutSound(imgObj,n){
	var p=window.document.getElementById("player"+n);
	imgObj.src=(p.Settings.mute)?"images/sound_off.gif":"/images/sound_on.gif";
}

function getX(obj) {
    try{
        return(obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent));
    }catch (e) {
					 alert(e.description);
		}       
} 
      
function getY(obj) {
    try{
        return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
    } catch (e) {}
}


function setVolume(n){
		var volWidth=window.document.getElementById("spnVolSlider"+n).style.pixelLeft-G_VOL_START;
		window.document.getElementById("imgVolWhite"+n).style.width=volWidth;
		
}

function setDescription(n){

var marq=window.document.getElementById("mrqDescr"+n);
var desc=marq.innerHTML;
		if(desc.length>22)
		{
				marq.scrollAmount=2.5;
				document.getElementById("spnMovieName"+n).style.display="";
				document.getElementById("spnMovieNameStatic"+n).style.display="none";
		}
		else
		{
		 		marq.scrollAmount=0;
				document.getElementById("spnMovieNameStatic"+n).style.display="";
				document.getElementById("spnMovieName"+n).style.display="none";
		}
		
}
