
	/****************************************************************************/
	/* Synacor                                                                  */
	/* File Name: slide.js                                                      */
	/*                                                                          */
	/* This file contains the functionality to slide open/close elements        */
	/****************************************************************************/

	var slideSpeed = 10;
	var slideMaxLen = 1000;
	var isMoving = false;
	var tId;
	
	//A function to open / close a collapsible div.
	function slideMe (theObj,  maxHeight){
		var curObj = document.getElementById(theObj);
		if (curObj){
			
			var startTime = (new Date()).getTime();
			//Check if it needs to be expanded or contracted.
			if (!isMoving){
				if (curObj.style.display == "none"){
					//Expand.
					tId = setInterval('slideInc(\'' + theObj + '\',\'down\',\'' + maxHeight + '\',\'' + startTime + '\');',slideSpeed);
				} else {
					//Contract.
					tId = setInterval('slideInc(\'' + theObj + '\',\'up\',\'' + maxHeight + '\',\'' + startTime + '\');',slideSpeed);
				}
				isMoving = true;
			}
		}
	}
	
	//Function to increase or decrease the height of an object.
	function slideInc (theObj, upDown, maxHeight, startTime){
		var curObj = document.getElementById(theObj);
		if (curObj){
			//Find out how long we have been sliding for.
			var slideFor = (new Date()).getTime() - startTime;
			
			//Find the current height of the object.
			var curHeight = parseInt (curObj.offsetHeight);
			var inc = Math.round(slideFor / slideMaxLen * maxHeight);
			
			if (slideFor > slideMaxLen){
				endSlide (curObj, upDown, maxHeight);
			} else {
				if (upDown == "up"){
					newHeight = (parseInt (curHeight) - inc);
					//Decrease.
					if (newHeight > 0){
						curObj.style.height = String (newHeight) + "px";
					} else {
						endSlide (curObj, upDown, maxHeight);
					}
				} else {
					curObj.style.display = "block";
					newHeight = (parseInt (curHeight) + inc);
					//Increase.
					if (curHeight < maxHeight){
						curObj.style.height = String (newHeight) + "px";
					} else {
						endSlide (curObj, upDown, maxHeight);
					}
				}
			}
		}
	}
	
	//Function to stop a slide.
	function endSlide (curObj, upDown, maxHeight){
		if (curObj){
			clearInterval(tId);
			isMoving = false;
			if (upDown == "up"){
				curObj.style.height = "0px";
				curObj.style.display = "none";
			} else {
				curObj.style.height = maxHeight + "px";
			}
		}
	}
