if (ipa.indexOf("98.210")<0){/*if the ip address doesn't match, don't do anything */} else {
	//Write test script here.
	}

if (ipa.indexOf("98.210")<0){
	var isme=false;
	} else {
	var isme=true;
	}

function stateChange(player,newState){
	var index=player.id.substr(player.id.length-1);

	updateStatus(index,newState);
	updatePlaySwitch(index,newState);
	}

function updateStatus(index,newState){
	statusObj=document.getElementById("status"+index);
	statusObj.innerHTML=getStateText(newState);
	}

function updatePlaySwitch(index,newState){
	switch(newState){
		case (-1):
			var bool=false;
			break;
			
		case 0:
			var bool=false;
			break;
			
		case 1:
			var bool=true;
			break;
			
		case 2:
			var bool=false;
			break;
			
		case 3:
			var bool=true;
			break;
			
		case 5:
			var bool=false;
			break;
		}
		
	ytpPlaying[index]=bool;
	if(playersInitiated==true){
		updateYtpAllPlaying();
		}
	}

function getStateText(stateNum){
	switch(stateNum){
		case -1:
			var stateText="Unstarted";
			break;
			
		case 0:
			var stateText="Ended";
			break;
			
		case 1:
			var stateText="Playing";
			break;
			
		case 2:
			var stateText="Paused";
			break;
			
		case 3:
			var stateText="Buffering";
			break;
			
		case 5:
			var stateText="Video Cued";
			break;
			
		default:
			var stateText="default";
			}
	return stateText;
	}

function getPlayerInfo(){
	//get player durations
	//get player total bytes

	if(playerInfoRetrieved==false){
		for(i=0;i<num_vids;i++){
			ytpDur[i]=ytplayers[i].getDuration();
			ytpBytesTot[i]=ytplayers[i].getVideoBytesTotal();
			if(ytpDur[i]<0 || ytpBytesTot[i]<0){
				playerInfoTimer=setTimeout("getPlayerInfo()",500);
				} else {
				clearTimeout(playerInfoTimer);
				playerInfoRetrieved=true;
				}
			}
		}
	}
	
//Play/Pause all videos
function allPlayPause(){
	if(vers>=3){
		updateYtpAllPlaying();
		}
    if (allPlaying==0){
		if(vers>=3){
			playTimeline=true;
			playWTimeDiff();
			//turn on the switch indicating that the play button has been pressed for the first time
			if(firstPlay==false){
				firstPlay=true;
				updatePlayerReadyText();
				}
			} else {
			ytplayers[0].playVideo();
			ytplayers[1].playVideo();
			ytpPlaying[0]=true;
			ytpPlaying[1]=true;
//			for(i=0;i<num_vids;i++){
//				ytplayers[i].playVideo();
//				ytpPlaying[i]=true;
//				}
			allPlaying=1;
			}
        } else {
		if(vers>=3){
			playTimeline=false;
			}
		ytplayers[0].pauseVideo();
		ytplayers[1].pauseVideo();
		ytpPlaying[0]=false;
		ytpPlaying[1]=false;
//		for(i=0;i<num_vids;i++){
//			ytplayers[i].pauseVideo();
//			ytpPlaying[i]=false;
//			}
        allPlaying=0;
        }
	if(vers<3){updateYtpAllPlaying();}
	updateVideoInfo();
	}

function playWTimeDiff(){

	var otherCurrTime=ytplayers[otherId].getCurrentTime();
	globalCurrTime=getGlobalCurrTime();
	
	ytpPlaySeek[leadId]=roundTo("round",globalCurrTime,1000);
	var delayedTimeValue=calcDelayedTimeValue(globalCurrTime);
	ytpPlaySeek[otherId]=roundTo("round",delayedTimeValue,1000);
	
	//if both vids reach the end of the timeline. pause it and seek to 0 so they can be played again.
	if(ytplayers[otherId].getPlayerState()==0 && ytplayers[leadId].getPlayerState()==0){
		ytplayers[leadId].pauseVideo();
		ytplayers[otherId].pauseVideo();
		ytpPlaySeek[0]=0;
		ytpPlaySeek[1]=0;
		playTimeline=false;
		}
	
//	if(isme){dump2.innerHTML=" "+otherVidStarted;}
		
	if(playTimeline==true && sbMoving==false){
		//ivan: this part is making the other vid repeat constantly as it's trying to synchronize the time
		//ivan: if possible, pause the video before reaching this step.
		if(inVidDelayZone()==false && inVidExpiredZone()==false){
			if(roundTo("round",Math.abs(delayedTimeValue-otherCurrTime),100)>0.5){
				ytplayers[leadId].seekTo(ytpPlaySeek[leadId],false);
				ytplayers[otherId].seekTo(ytpPlaySeek[otherId],false);
				if(isme==true){dump.innerHTML+=" | wasn't synced "+(globalCurrTime-otherCurrTime);}
				}
			}
		
		if(ytplayers[leadId].getPlayerState()==0 || inVidExpiredZone()==true){
			if(isme){dump2.innerHTML+=" 1";}
			if(leadFromStartToEnd==false){
				ytplayers[leadId].pauseVideo();
				ytplayers[otherId].playVideo();
				}
			} else if(ytplayers[otherId].getPlayerState()==0 && leadFromStartToEnd==true){
			if(isme){dump2.innerHTML+=" 2";}
			ytplayers[otherId].pauseVideo();
			ytplayers[leadId].playVideo();
			} else if(inVidDelayZone()==true){
			if(isme){dump2.innerHTML+=" 3";}
			ytplayers[leadId].playVideo();
			ytplayers[otherId].pauseVideo();
			} else {
			if(isme){dump2.innerHTML+=" 4";}
			if(playersInitiated==false){ //for backup scenario when the players can't seem to get started when first cued
				playersInitiated=true;
				hideShowScrubhead();
				}
			otherVidStarted=true;
			ytplayers[leadId].playVideo();
			ytplayers[otherId].playVideo();
			}
		
		updateYtpAllPlaying();
		if(allPlaying==0){playTimeline=false;}

		if(playWTimeDiffIntSet==false){
			playWTimeDiffInt=setInterval("playWTimeDiff()",500);
			playWTimeDiffIntSet=true;
			}
		} else { //if playTimeline=false;
		ytplayers[0].seekTo(ytpPlaySeek[0],false);
		ytplayers[1].seekTo(ytpPlaySeek[1],false);
		ytplayers[0].pauseVideo();
		ytplayers[1].pauseVideo();
		
		clearInterval(playWTimeDiffInt);
		playWTimeDiffIntSet=false;
		updateVideoInfo();
		}
	}

function calcDelayedTimeValue(leadTime){
	var value=leadTime-Math.abs(timeDiff);
	if(value<0){value=0;}
	return value;
	}

function inVidDelayZone(){
	var leadCurrTime=ytplayers[leadId].getCurrentTime();
	var otherCurrTime=ytplayers[otherId].getCurrentTime();
	
	var inVidDelayZone;
	if(leadCurrTime>=Math.abs(timeDiff)){
		inVidDelayZone=false;
		} else {
		inVidDelayZone=true;
		}
	return inVidDelayZone;
	}

function inVidExpiredZone(){
	var leadCurrTime=ytplayers[leadId].getCurrentTime();
	var otherCurrTime=ytplayers[otherId].getCurrentTime();
	
	var inVidExpiredZone;
	if(leadCurrTime>=ytpDur[leadId] || leadCurrTime>=(ytpDur[otherId]+Math.abs(timeDiff))){
		inVidExpiredZone=true;
		} else {
		inVidExpiredZone=false;
		}
	return inVidExpiredZone;
	}

function getGlobalCurrTime(){
	if(inVidDelayZone()==true || leadFromStartToEnd==true){
		var time=ytplayers[leadId].getCurrentTime();
//		} else if (inVidExpiredZone()==true && ytpDur[leadId]>=(ytpDur[otherId]+Math.abs(timeDiff))){
//		//if the lead video is longer than the sum of the lengths of the other vid and the time difference,
//		//AND the current time is past the end of the other vid, use the lead vid's time as current time
//		var time=ytplayers[leadId].getCurrentTime();
		} else {
		var time=ytplayers[otherId].getCurrentTime()+Math.abs(timeDiff);
		}
	return time;
	}

function updateVideoInfo(){
	//update ytpPlaying switches
	//update allPlaying switch
	//update time
	//update play/pause text
	//update scrub head
	//update bytes loaded

//	if(playersInitiated==true){
		updateYtpAllPlaying();
//		}
	updateTime();
	updatePlayPauseText();
	
	if(allPlaying>0 && sbMoving==false){
		var videoSliderTimer=setInterval("updateVideoSlider('scrubBlock','scrubCont')",1000);
		} else {
		updateVideoSlider("scrubBlock","scrubCont");
		clearInterval(videoSliderTimer);
		}
	}

function updateYtpPlaying(){
	if(vers>=3){
		var state0=ytplayers[0].getPlayerState();
		var state1=ytplayers[1].getPlayerState();
		if(state0==1 || state0==3){ytpPlaying[0]=true;}else{ytpPlaying[0]=false;}
		if(state1==1 || state1==3){ytpPlaying[1]=true;}else{ytpPlaying[1]=false;}
		updateStatus(0,state0);
		updateStatus(1,state1);
		} else { // vers<3
		for(i=0;i<num_vids;i++){
			var state=ytplayers[i].getPlayerState();
			if(state==1 || state==3){
				ytpPlaying[i]=true;
				} else {
				ytpPlaying[i]=false;
				}
			}
		}
	}

function updateAllPlaying(){
	if(vers>=3){
		if(ytpPlaying[0]==false && ytpPlaying[0]==ytpPlaying[1]){
			allPlaying=0;
			} else if (ytpPlaying[0]!=ytpPlaying[1]){
			allPlaying=2;
			} else {
			allPlaying=1;
			}
		} else { //vers<3
		for(i=0;i<num_vids;i++){
			for(j=0;j<i;j++){
				if(ytpPlaying[i]!=ytpPlaying[j]){
					allPlaying=2;
					break;
					}
				}
			if(allPlaying==2){
				break;
				}
			}
	
		if(allPlaying!=2){
			if(ytpPlaying[0]==true){
				allPlaying=1;
				} else {
				allPlaying=0;
				}
			}
		}
	}

function updateYtpAllPlaying(){
	updateYtpPlaying();
	updateAllPlaying();
	}

function updateTime(options){
	var options = options || {};
	
	//var ytpCurrTimes=new Array(num_vids);
	
	var rIndexCurrTime=ytplayers[rIndex].getCurrentTime();
	var rOtherCurrTime=ytplayers[rOther].getCurrentTime();
	if(vers>=3){
			
		//update status here because the eventlistener doesn't seem to update when only one player is playing
		var state0=ytplayers[0].getPlayerState();
		var state1=ytplayers[1].getPlayerState();
		updateStatus(0,state0);
		updateStatus(1,state1);
		
		ytpCurrTimes[rIndex]=rIndexCurrTime;
		ytpCurrTimes[rOther]=rOtherCurrTime;

		var ytpMins=new Array(num_vids);
		var ytpSecs=new Array(num_vids);
	
		if(ytpCurrTimes[0]<0){ytpCurrTimes[0]=0;}
		if(ytpCurrTimes[0]>ytpDur[0] && ytpCurrTimes[0]>0){ytpCurrTimes[0]=ytpDur[0];}
		if(ytpCurrTimes[1]<0){ytpCurrTimes[1]=0;}
		if(ytpCurrTimes[1]>ytpDur[1] && ytpCurrTimes[1]>0){ytpCurrTimes[1]=ytpDur[1];}
		
		ytpMins[0]=Math.floor(ytpCurrTimes[0]/60);
		ytpMins[1]=Math.floor(ytpCurrTimes[1]/60);
		if (ytpMins[0]<10){ytpMins[0]="0"+ytpMins[0];}
		if (ytpMins[1]<10){ytpMins[1]="0"+ytpMins[1];}
		
		ytpSecs[0]=Math.floor(ytpCurrTimes[0]%60);
		ytpSecs[1]=Math.floor(ytpCurrTimes[1]%60);
		if (ytpSecs[0]<10){ytpSecs[0]="0"+ytpSecs[0];}
		if (ytpSecs[1]<10){ytpSecs[1]="0"+ytpSecs[1];}
		
		times[0].innerHTML=ytpMins[0]+":"+ytpSecs[0];
		times[1].innerHTML=ytpMins[1]+":"+ytpSecs[1];
		} else { // vers<3
		ytpCurrTimes[rIndex]=rIndexCurrTime;
		ytpCurrTimes[rOther]=rOtherCurrTime;
		for(i=0;i<num_vids;i++){
	
			if(ytpCurrTimes[i]<0){ytpCurrTimes[i]=0;}
			if(ytpCurrTimes[i]>ytpDur[i] && ytpCurrTimes[i]>0){ytpCurrTimes[i]=ytpDur[i];}
			
			var ytpMins=Math.floor(ytpCurrTimes[i]/60);
			if (ytpMins<10){ytpMins="0"+ytpMins;}
			
			var ytpSecs=Math.floor(ytpCurrTimes[i]%60);
			if (ytpSecs<10){ytpSecs="0"+ytpSecs;}
			
			times[i].innerHTML=ytpMins+":"+ytpSecs;
			}
		}
	
	if(allPlaying>0){
		updateTimeTimer=setTimeout(updateTime,499);
		} else {
		clearTimeout(updateTimeTimer);
		}
	}

//Change the text based on the switch state.
function updatePlayPauseText(){
    if (allPlaying==0){
        playPauseText.innerHTML="Play Videos";
        } else {
        playPauseText.innerHTML="Pause Videos";
        }
    }

function muteAll(){
	if (allHasSound>0){
		allHasSound=0;
		vbStartPerc=ytplayers[volIndex].getVolume();
		for(i=0;i<num_vids;i++){
			hasSound_a[i]=false;
			ytplayers[i].mute();
			}
		} else if(allHasSound==0) {
		allHasSound=1;
		for(i=0;i<num_vids;i++){
			hasSound_a[i]=true;
			ytplayers[i].unMute();
			}
		ytplayers[volIndex].setVolume(vbStartPerc);
		}
	updateVolumeInfo();
	}

function updateVolumeInfo(){
	//update ytpHasSound switch
	//update allHasSound switch
	//update ytpVolume
	//update allVolume
	//update volume Text
	//update muteAll Text
	//update slider
	
	
	if(playersInitiated==true){
		updateYtpSound();
		updateAllSound();
		}
		
	if(playersInitiated==false){
		for(i=0;i<num_vids;i++){
			ytpVolume[i]=vols[i];
			ytplayers[i].setVolume(ytpVolume[i]);
			}
		} else {
		updateYtpVolume();
		}
	
	
	//fix the volume according to the ratio	
	currVolumeRatioFix();

	updateVText();
	updateMuteAllText();
	updateVolumeSlider("volumeBlock","volumeCont");
	
	}

	function currVolumeRatioFix(){
		ytpVolume[volIndex]=ytplayers[volIndex].getVolume();
		ytpVolume[volOther]=Math.round(ytpVolume[volIndex]*volRat);
		ytplayers[volOther].setVolume(ytpVolume[volOther]);
		}

function updateYtpSound(){
	for(i=0;i<num_vids;i++){
		if(ytplayers[i].isMuted()){
			hasSound_a[i]=false;
			} else {
			hasSound_a[i]=true;
			}
		}
	}

function updateAllSound(){
	for (i=0;i<num_vids;i++){
		for(j=i+1;j<i;j++){
			if(hasSound_a[i]!=hasSound_a[j]){
				allHasSound=2;
				break;
				}
			}
		if(allHasSound==2){
			break;
			}
		}
	if(allHasSound!=2){
		if(hasSound_a[0]==true){
			allHasSound=1;
			} else {
			allHasSound=0;
			}
		}
	}

function updateYtpVolume(){
	for(i=0;i<num_vids;i++){
		ytpVolume[i]=ytplayers[i].getVolume();
		}
	}

//update volume text
function updateVText(){
//	if(sPerc==null){
	var sPerc=new Array(num_vids);
	var str="";
	for(i=0;i<num_vids;i++){
		if(hasSound_a[i]==false){
			sPerc[i]=0;
			} else {
			sPerc[i]=ytplayers[i].getVolume();
			}
		str+=sPerc[i];
		if(i!=(num_vids-1)){
			str+=" | ";
			}
		}
	vText.innerHTML=str;
	}

// change text based on mute state
function updateMuteAllText(){
	if(allHasSound>0){
		muteAllText.innerHTML="Mute Videos";
		} else if (allHasSound==0){
		muteAllText.innerHTML="Unmute Videos";
		}
	}

//function fnToLoad(){
//	updateTime();
//    }
// 
//onload=fnToLoad();

function updateBytesLoaded(){
	if (byteLoadStarted==false){
	
		var si=getSliderInfo("scrubBlock","scrubCont");
		
		var bytesLoaded=new Array();
		var bytesLoadedSum=0;
		var bytesTotalSum=0;
		var loadBarLength=new Array();
		
		if (vers<3){
			for(i=0;i<num_vids;i++){
				ytpBytesTot[i]=ytplayers[i].getVideoBytesTotal();
				bytesLoaded[i]=ytplayers[i].getVideoBytesLoaded();
				
				bLoadedPercent=bytesLoaded[i]/ytpBytesTot[i];
				loadBarLength[i]=Math.round(sSlideRangeLength*bLoadedPercent)+si["hW"];
				loadBars[i].style.width=loadBarLength[i]+"px";
				
				//display only
				bytesLoadedSum+=bytesLoaded[i];
				bytesTotalSum+=ytpBytesTot[i];
				}
			} else {//if version 3 or higher
			var rIndexDur=ytplayers[rIndex].getDuration();
			var rOtherDur=ytplayers[rOther].getDuration();
			
			var totalDur=getTotalDur();

			//temporarily shortens the width of the entire length by the length of the scrubhead
			//will be added back on in later formulas;
			var temp_sSlideRangeLength=sSlideRangeLength;//-(si["hW"]);
			
			pxPerSec=temp_sSlideRangeLength/totalDur;
			pxDiff=timeDiff*pxPerSec;
			
			//get bytes loaded info
			for(i=0;i<num_vids;i++){
				ytpBytesTot[i]=ytplayers[i].getVideoBytesTotal();
				bytesLoaded[i]=ytplayers[i].getVideoBytesLoaded();
				
				bLoadedPercent=bytesLoaded[i]/ytpBytesTot[i];
				
				//display only
				bytesLoadedSum+=bytesLoaded[i];
				bytesTotalSum+=ytpBytesTot[i];
				}
			
			//calculate and set the bar lengths
			loadBarLength[rIndex]=(rIndexDur*pxPerSec*bLoadedPercent);
			loadBarLength[rOther]=(rOtherDur*pxPerSec*bLoadedPercent);
			loadBars[rIndex].style.width=loadBarLength[rIndex]+"px";
			loadBars[rOther].style.width=loadBarLength[rOther]+"px";
			
			//adjust the widths of the loadBars and move the "later" video bar based on timeDiff
			//this adds si["hW"]/2 on both sides of the loadBars except for the start of the delayed video
			if(timeDiff>0){
				loadBars[otherId].style.left=(pxDiff+(si["hW"]/2))+"px";
				loadBars[otherId].style.width=(loadBarLength[otherId]+(si["hW"]/2))+"px";
				loadBars[leadId].style.width=(loadBarLength[leadId]+si["hW"])+"px";
				} else if(timeDiff<0){
				loadBars[leadId].style.left=((-(pxDiff))+(si["hW"]/2))+"px";
				loadBars[leadId].style.width=(loadBarLength[leadId]+(si["hW"]/2))+"px";
				loadBars[otherId].style.width=(loadBarLength[otherId]+si["hW"])+"px";
				} else {
				loadBars[leadId].style.width=(loadBarLength[leadId]+si["hW"])+"px";
				loadBars[otherId].style.width=(loadBarLength[otherId]+si["hW"])+"px";
				}
			}//end version 3 or higher
		
		
		
		if(bytesLoadedSum<bytesTotalSum || bytesLoadedSum<0){
			if(byteIntervalSet==false){
				byteTimer=setInterval("updateBytesLoaded()",1000);
				byteIntervalSet=true;
				}
			} else {
			byteLoadStarted=true;
			byteIntervalSet=false;
			clearInterval(byteTimer);
			}
		}
	}
	
function getTotalDur(){
	var leadDur=ytplayers[leadId].getDuration();
	var otherDur=ytplayers[otherId].getDuration();
	if(otherDur+timeDiff>=leadDur){
		var totalDur=otherDur+Math.abs(timeDiff);
		leadFromStartToEnd=false;
		} else {
		var totalDur=leadDur;
		leadFromStartToEnd=true;
		}
	
//	var rIndexDur=ytplayers[rIndex].getDuration();
//	var rOtherDur=ytplayers[rOther].getDuration();
//	if(timeDiff>=0){
//		if(rOtherDur+timeDiff>=rIndexDur){
//			var totalDur=rOtherDur+timeDiff;
//			} else {
//			var totalDur=rIndexDur;
//			}
//		} else {
//		if(rIndexDur-timeDiff>=rOtherDur){
//			var totalDur=rIndexDur-timeDiff;
//			} else {
//			var totalDur=rOtherDur;
//			}
//		}
	return totalDur;
	}
			
function vbMouseDown(el){
	
	var vBarValues=getSliderInfo("volumeBlock","volumeCont");
	vbPos=vBarValues["h"].offsetLeft;
	vbStartPerc=Math.round(100*(vBarValues["h"].offsetLeft/vBarValues["slideRangeLength"]));
	
	document.onmousemove=volumeMouseMove;
	/* this part is copied from http://luke.breuer.com/tutorial/javascript-drag-and-drop-tutorial.aspx */
	// cancel out any text selections 
	document.body.focus(); 
	// prevent text selection in IE 
	document.onselectstart = function () { return false; }
	// prevent IE from trying to drag an image 
	target.ondragstart = function() { return false; }
	/* end copying */
	}

function volumeMouseMove(ev){
	
	var vBarValues=activateSlider("volumeBlock","volumeCont",ev);
	var sPerc=vBarValues["sPerc"];

	if(sPerc<=0){
		allHasSound=false;
		} else {
		allHasSound=true;
		}
	
	for(i=0;i<num_vids;i++){
		if(sPerc<=0){
			ytplayers[i].mute();
			} else {
			ytpVolume[volIndex]=sPerc;
			ytplayers[volIndex].setVolume(sPerc);
			ytplayers[i].unMute();
			}
		//ytplayers[i].setVolume(sPerc);
		}
	
	updateVolumeInfo();
	
	document.onmouseup=function(){
		document.onmousemove=null;
		document.body.blur();
		}
	}

function sbMouseDown(el){
	//could be temporary condition: scrubhead move is not available until after the otherVid has started
	if(otherVidStarted==true){
		document.onmousemove=scrubMouseMove;
		}
	/* this part is copied from http://luke.breuer.com/tutorial/javascript-drag-and-drop-tutorial.aspx */
	// cancel out any text selections 
	document.body.focus(); 
	// prevent text selection in IE 
	document.onselectstart = function () { return false; }
	// prevent IE from trying to drag an image 
	target.ondragstart = function() { return false; }
	/* end copying */
	}

function scrubMouseMove(ev){
	
	var sBarValues=activateSlider("scrubBlock","scrubCont",ev);
	var sPercent=sBarValues["sPercent"];
		
//	var ytpDur=new Array();
	var ytpSeek=new Array();
	
	var totalDur=getTotalDur();
	
	if(vers>=3){
		
		//override the firstPlay switch so the scrubhead can move
		//sort of cheating but it works
		playerOk=true;
		
		var globalSeekTo=(sPercent*totalDur)/100;
		ytpSeek[leadId]=globalSeekTo;
//		ytpSeek[otherId]=globalSeekTo-timeDiff;
//		if(ytpSeek[otherId]<0){ytpSeek[otherId]=0;}
		ytpSeek[otherId]=calcDelayedTimeValue(globalSeekTo);
		if(sbMoving==false){
			//jot down the players' state before the sb moves
			//so we could reapply the states after the sb stops moving
			preMoveState[0]=ytplayers[0].getPlayerState();
			preMoveState[1]=ytplayers[1].getPlayerState();
			}
		ytplayers[0].seekTo(ytpSeek[0],false);
		ytplayers[1].seekTo(ytpSeek[1],false);
		ytplayers[0].pauseVideo();
		ytplayers[1].pauseVideo();
		sbMoving=true;
		updateVideoInfo();
		} else { //vers<3
		//set main seek place from rIndex
		ytpSeek[rIndex]=Math.round((sPercent*ytpDur[rIndex])/100);
		for(i=0;i<num_vids;i++){
			var state=ytplayers[i].getPlayerState();
			ytplayers[i].seekTo(ytpSeek[rIndex],false);
			if(state==1 || state==3){
				ytplayers[i].playVideo();
				} else {
				ytplayers[i].pauseVideo();
				}
			}
		sbMoving=true;
		updateVideoInfo();
		}

	document.onmouseup=function(){
		sbMoving=false;
		//play/pause the vids based on the states they were in before the scrubhead was moved
		if(vers>=3){
			if(preMoveState[leadId]==1 || preMoveState[leadId]==3){
				if(inVidExpiredZone()==true){
					ytplayers[leadId].pauseVideo();
					} else {
					ytplayers[leadId].playVideo();
					}
				} else {
				ytplayers[leadId].pauseVideo();
				}
			if(preMoveState[otherId]==1 || preMoveState[otherId]==3){
				if(inVidDelayZone()==true){
					ytplayers[otherId].pauseVideo();
					} else {
					ytplayers[otherId].playVideo();
					}
				} else {
				ytplayers[otherId].pauseVideo();
				//if the scrubhead was moved from the delay zone to a both-playing zone,
				//and the lead vid was playing before scrub move,
				//override the preMoveState[otherId] value and play
				if(inVidDelayZone()==false && (preMoveState[leadId]==1 || preMoveState[leadId]==3)){
					ytplayers[otherId].playVideo();
					}
				}
			updateYtpAllPlaying();
			updateVideoInfo();
		
			playWTimeDiff();
			if(isme==true){dump2.innerHTML+=" mouse up";}
			document.onmouseup=null;
			}
		document.onmousemove=null;
		document.body.blur();
		}
	}

//function activateOtherVid(){
//	var seek=calcDelayedTimeValue(ytplayers[leadId].getCurrentTime());
//	dump.innerHTML+=" activate "+seek+"/"+ytplayers[otherId].getCurrentTime()+": ";
//	if(ytplayers[otherId].getPlayerState()!=2 ){
//		dump.innerHTML+="0";
//		ytplayers[otherId].pauseVideo();
//		if(activateOtherVidTimerStarted==false){
//			dump.innerHTML+="//";
//			activateOtherVidTimerStarted=true;
//			otherVidStartTimer=setInterval("activateOtherVid()",200);
//			}
//		} else {
//		dump.innerHTML+="1";
//		if(ytplayers[otherId].getCurrentTime()<0){
//			dump.innerHTML+="a";
//			ytplayers[otherId].seekTo(0,false);
////			} else {
////			dump.innerHTML+="2";
////			if(ytplayers[otherId].getCurrentTime()<seek){
////				ytplayers[otherId].seekTo(seek,false);
//				} else {
//				dump.innerHTML+="3";
//				if(preMoveState[leadId]==1 || preMoveState[leadId]==3){
//					dump.innerHTML+="a";
//					ytplayers[otherId].pauseVideo();
//					} else {
//					dump.innerHTML+="b";
//					ytplayers[otherId].pauseVideo();
//					}
//				dump.innerHTML+=" "+otherVidStarted;
//				otherVidStarted=true;
//				dump.innerHTML+=" "+otherVidStarted;
//				updateYtpAllPlaying();
//				updateVideoInfo();
//			
////				playWTimeDiff();
//				clearInterval(otherVidStartTimer);
////				}
//			}
//		}
//	dump.innerHTML+=" | ";
//	}
	
//ivan: get otherVid to play if moved from delay zone to regular zone
//if not that possible, try to disable the scrubhead until the otherVid started
//then, get both vids to play if moved straight from the beginning without starting to play anything

function activateSlider(headId,containerId,ev){

	var si=getSliderInfo(headId,containerId);
	
	var h=document.getElementById(headId);
//	var hPos=findPos(h);
	var hW=h.offsetWidth;
//	var hCenter=Math.round(hW/2);
//
	var c=document.getElementById(containerId);
//	var cPos=findPos(c);
	var cW=c.offsetWidth;
//	
	var slideRangeLength=cW-hW;
//	var slideStartPos=cPos[0];
//	var slideEndPos=cPos[0]+slideRangeLength;

	var cursPos=getCursPos(ev);
	var cursX=cursPos["x"];
	var cursY=cursPos["y"];
	
	var hCursDist=cursX-si["hPos"][0];
	var hStyleLeft=cursX-si["cPos"][0]-si["hCenter"];
	var cursAtStart=si["slideStartPos"]+si["hCenter"];
	var cursAtEnd=si["slideEndPos"]+si["hCenter"];
	if(cursX<cursAtStart){hStyleLeft=0;} 
		else if(cursX>cursAtEnd){hStyleLeft=si["slideRangeLength"];}
	
	si["h"].style.left=hStyleLeft+"px";

	var sPercent=100*(hStyleLeft/si["slideRangeLength"]);
	var sPerc=Math.round(100*(hStyleLeft/si["slideRangeLength"]));


	var vals=new Array();
	vals["h"]=si["h"];
	vals["hPos"]=si["hPos"]; //array of X and Y
	vals["hW"]=hW;
//	vals["hCenter"]=hCenter;
//	
//	vals["c"]=c;
//	vals["cPos"]=cPos; //array of X and Y
//	vals["cW"]=cW;
//	
	vals["slideRangeLength"]=slideRangeLength;
//	vals["slideStartPos"]=slideStartPos;
//	vals["slideEndPos"]=slideEndPos;
//	
//	vals["cursX"]=cursX;
//	vals["cursY"]=cursY;
//	
//	vals["hStyleLeft"]=hStyleLeft;
//	
	vals["sPercent"]=sPercent;
	vals["sPerc"]=sPerc;
	

	return vals;
	}

function updateVideoSlider(headId,containerId){
	if(vers>=3){
		var currTime=getGlobalCurrTime();
//		var currTime=ytplayers[leadId].getCurrentTime();
//		if(timeDiff>=0){
//			var currTime=ytplayers[rIndex].getCurrentTime();
//			} else {
//			var currTime=ytplayers[rOther].getCurrentTime();
//			}
		if (currTime<0){currTime=0;}
		
		//trick the viewer into thinking that the scrubhead is really at the beginning of the timeline 
		//after the startPlayers() may have moved the timeline a bit after 0
		if(vers>=3){if(playerOk==false){currTime=0;}}
		
		var totalDur=getTotalDur();
		var percent=currTime/totalDur;
		} else { // if below version 3
		var currTime=ytplayers[rIndex].getCurrentTime();
		if (currTime<0){currTime=0;}
		var percent=currTime/ytpDur[rIndex];
		}

	updateSlider(headId,containerId,percent);
	}

function updateVolumeSlider(headId,containerId){
	if(allHasSound==false){
		var percent=0;
		} else {
		var currVol=ytpVolume[volIndex];
		if (currVol<0){currVol=0;}
		var percent=currVol/100;
		}
	
	updateSlider(headId,containerId,percent);
	}

function updateSlider(headId,containerId,percent){
	var si=getSliderInfo(headId,containerId);
	if(vers>=3){
		var hStyleLeft=percent*si["slideRangeLength"];
		} else {
		var hStyleLeft=Math.round(percent*si["slideRangeLength"]);
		}

	si["h"].style.left=hStyleLeft+"px";
	}

function getSliderInfo(headId,containerId){
	var h=document.getElementById(headId);
	var hPos=findPos(h);
	var hW=vb.offsetWidth;
	var hCenter=Math.round(hW/2);

	var c=document.getElementById(containerId);
	var cPos=findPos(c);
	var cW=c.offsetWidth;
	
	var slideRangeLength=cW-hW;
	var slideStartPos=cPos[0];
	var slideEndPos=cPos[0]+slideRangeLength;

	var vals=new Array();
	vals["h"]=h;
	vals["hPos"]=hPos; //array of X and Y
	vals["hW"]=hW;
	vals["hCenter"]=hCenter;
	
	vals["c"]=c;
	vals["cPos"]=cPos; //array of X and Y
	vals["cW"]=cW;
	
	vals["slideRangeLength"]=slideRangeLength;
	vals["slideStartPos"]=slideStartPos;
	vals["slideEndPos"]=slideEndPos;
	
	return vals;
	}

//vers>=3 updatePlayerReadyText()
function updatePlayerReadyText(){
	if(firstPlay==true){
		playerReadyText.innerHTML="";
		} else if(playerOk==true){
		playerReadyText.innerHTML="Player Ready!";
		}
	}

//round numbers to specific decimal places with particular methods
function roundTo(method,value,to){
	if(method=="round"){return Math.round(value*to)/to;}
	if(method=="floor"){return Math.floor(value*to)/to;}
	if(method=="ceil"){return Math.ceil(value*to)/to;}
	}

//get current cursor position and return an array of x and y
function getCursPos(ev){
	if(ev==null){ev=window.event;}
	if(isIE=="false"){
		var cursX=ev.pageX;
		var cursY=ev.pageY;
		} else {
		var cursX=ev.clientX;
		var cursY=ev.clientY;
		}
	
	var cursPos=new Array();
	cursPos["x"]=cursX;
	cursPos["y"]=cursY;
	
	return cursPos;
	}

//get position of an object in relation to the page
function findPos(obj) {
	//from quirksmode.org
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
	return [curleft,curtop];
	}
	

