var topMarginTarget = 0;
var divHeightTarget = 0;
var topMarginActual = 0;
var videoFrameHeight = 440;
var videoFrameActual = 20;
var thisScene;
var sceneToCollapse;
var collapseHeight = 20;
var collapseActual = 440;
var comingScene;

function showScene(sceneIdx) {
	ctr = 1;
	comingScene = sceneIdx;
	thisScene = document.getElementById("videoFrame" + sceneIdx);
	showIt = true;
	if (thisScene.className == 'videoFrame') {
		showIt = false;		
	}

	
	if (showIt) {
 		sceneDiv = document.getElementById('sceneTitle' + sceneIdx);
 		//sceneDiv.offsetTop = topMarginActual;
		//topMarginTarget = -((sceneIdx - 1) * 209);
		padding = 0;
		if (topMarginActual == 0) {
			//first time, add a 5 px padding
			padding = 5;
		}
		if (sceneToCollapse > 0) {
			playerAllowance = collapseActual;
		}
		else {
			playerAllowance = 0;
		}
		topMarginTarget = padding - (Math.abs(topMarginActual) + (sceneDiv.offsetTop - playerAllowance));
		//topMarginActual = 0;
		videoFrameActual = 20;
		if (sceneToCollapse > 0) {
			setTimeout("collapseDiv()", 50);
		}			
		else {
			changeClass("videoFrame" + sceneIdx, 'videoFrame');
			setTimeout("growDiv()", 50);
			sceneToCollapse = sceneIdx;
		}
	}
	else {
		//ss = document.getElementById("sceneScroller");
		topMarginTarget = 0;		
		comingScene = 0;
		if (sceneToCollapse > 0) {
			setTimeout("collapseDiv()", 50);
		}
		else {	
			setTimeout("animateSlide()", 100);
		}
		
		//ss.style.marginTop = "0px";
	}
}

function collapseDiv() {
	moveStep = 35;
	smallStep = 9;		
	sdiv = document.getElementById("videoFrame" + sceneToCollapse);
	ah = parseInt(sdiv.style.height);
	if (ah != collapseHeight) {
	 	if (Math.abs(ah - collapseHeight) < moveStep) {
	 		moveStep = smallStep;	
	 	}
	 	if (Math.abs(ah - collapseHeight) <= smallStep) {
	 		ah = collapseHeight;	
	 	}
	 	if (ah > collapseHeight) {
	 		ah = ah - moveStep;
	 	}
	 	else if (ah < collapseHeight) {
	 		ah = ah + moveStep;
	 	}
	 	
		sdiv.style.height = ah + 'px';	 			
		setTimeout("collapseDiv()", 50);
	}
	else {
		sceneToCollapse = comingScene;
		ctr = 1;
		while (document.getElementById("videoFrame" + ctr)) {
			if (ctr != sceneToCollapse) {
				changeClass("videoFrame" + ctr, 'videoFrameHidden');	
			}
			ctr++;
		}		
		if (comingScene > 0) {
			changeClass("videoFrame" + comingScene, 'videoFrame');
			setTimeout("growDiv()", 100);
		}
		else {
			setTimeout("animateSlide()", 100);
		}
	}
	
}

function growDiv() {
	moveStep = 35;
	smallStep = 9;		
	if (videoFrameActual != videoFrameHeight) {
	 	if (Math.abs(videoFrameActual - videoFrameHeight) < moveStep) {
	 		moveStep = smallStep;	
	 	}
	 	if (Math.abs(videoFrameActual - videoFrameHeight) <= smallStep) {
	 		videoFrameActual = videoFrameHeight;
	 	}
	 	if (videoFrameActual > videoFrameHeight) {
	 		videoFrameActual = videoFrameActual - moveStep;
	 	}
	 	else if (videoFrameActual < videoFrameHeight) {
	 		videoFrameActual = videoFrameActual + moveStep;
	 	}
	 	
		thisScene.style.height = videoFrameActual + 'px';	 			
		setTimeout("growDiv()", 50);
	}
	else {
		setTimeout("animateSlide()", 100);
	}
	
}


function animateSlide() {
	moveStep = 35;
	smallStep = 9;
	ss = document.getElementById('sceneScroller');

	if (topMarginActual != topMarginTarget) {
	 	if (Math.abs(topMarginActual - topMarginTarget) < moveStep) {
	 		moveStep = smallStep;	
	 	}
	 	if (Math.abs(topMarginActual - topMarginTarget) <= smallStep) {
	 		topMarginActual = topMarginTarget;	
	
	 	}
	 	if (topMarginActual > topMarginTarget) {
	 		topMarginActual = topMarginActual - moveStep;
	 	}
	 	else if (topMarginActual < topMarginTarget) {
	 		topMarginActual = topMarginActual + moveStep;
	 	}
		ss.style.marginTop = topMarginActual + 'px';	 			
		setTimeout("animateSlide()", 100);
	}
}


function newThumbs(originalRequest) {
	thumbsDiv = document.getElementById('galleryThumbs');
	thumbsDiv.innerHTML = originalRequest.responseText;
}