// JavaScript Document
//Slider Array

//[0]Slider ID
//[1]Initial Position
//[2]Target Position
//[3]Animation TimeOut
//[4]Target Size
//[5]Initial Size

function prepSliders(){/*must be called before colorPicker.js*/
	document.sliderInformation = Array();
	document.sliderRateOfChange = 15;	//Distance To Move
	document.sliderRateOfUpdate = 20; 	//Timeout Setting
}

function prepVerticalSlider(verticalSliderID){
	var contentSlider = document.getElementById(verticalSliderID);
	document.sliderInformation.push(Array(verticalSliderID, contentSlider.offsetTop, "", "", "", ""));//secondary navigation slider
	document.lastVerticalSlidTerm = 'contentDonate';
}

function zipSlider(sliderToMoveID, sliderTargetPositionID, resizeSlider){
	var sliderTarget = document.getElementById(sliderTargetPositionID);
	var sliderToMove = document.getElementById(sliderToMoveID);
	sliderToMove.style.left = sliderTarget.offsetLeft + "px";
	if(resizeSlider){
		sliderToMove.width = sliderTarget.offsetWidth + "px"
	}
	for(var loopCounter =0; loopCounter < document.sliderInformation.length; loopCounter++){
		if(document.sliderInformation[loopCounter][0] == sliderToMoveID){
			clearTimeout(document.sliderInformation[loopCounter][3]);
			document.sliderInformation[loopCounter][2] = '';
			document.sliderInformation[loopCounter][1] = sliderTarget.offsetLeft;
			document.sliderInformation[loopCounter][5] = sliderToMove.offsetWidth;
		}
	}
}

function zipSliderVertical(sliderToMoveID, sliderTargetPositionID){
	document.lastVerticalSlidTerm = sliderTargetPositionID;
	document.getElementById(document.lastVerticalSlidTerm).className="defaultState";
	
	var sliderTarget = document.getElementById(sliderTargetPositionID);
	var sliderToMove = document.getElementById(sliderToMoveID);
	sliderToMove.style.top = sliderTarget.offsetTop + "px";
	
	for(var loopCounter =0; loopCounter < document.sliderInformation.length; loopCounter++){
		if(document.sliderInformation[loopCounter][0] == sliderToMoveID){
			clearTimeout(document.sliderInformation[loopCounter][3]);
			document.sliderInformation[loopCounter][2] = '';
			document.sliderInformation[loopCounter][1] = sliderTarget.offsetTop;
		}
	}
}

function slideSliderVertical(sliderToMoveID, sliderTargetPositionID){
	document.getElementById(document.lastVerticalSlidTerm).className="";
	document.lastVerticalSlidTerm = sliderTargetPositionID;
	var sliderTarget = document.getElementById(sliderTargetPositionID);
	document.getElementById(sliderToMoveID).className = "contentSlider";
	for(var loopCounter =0; loopCounter < document.sliderInformation.length; loopCounter++){
		if(document.sliderInformation[loopCounter][0] == sliderToMoveID){
			document.sliderInformation[loopCounter][2] = sliderTarget.offsetTop;
			document.sliderInformation[loopCounter][3] = setTimeout("animateVerticalSlide("+loopCounter+")", document.sliderRateOfUpdate);
		}
	}
}

function slideSlider(sliderToMoveID, sliderTargetPositionID, resizeSlider){
	var sliderTarget = document.getElementById(sliderTargetPositionID);
	for(var loopCounter =0; loopCounter < document.sliderInformation.length; loopCounter++){
		if(document.sliderInformation[loopCounter][0] == sliderToMoveID){
			document.sliderInformation[loopCounter][2] = sliderTarget.offsetLeft;
			if(resizeSlider){
				document.sliderInformation[loopCounter][4] = sliderTarget.offsetWidth;
			}
			document.sliderInformation[loopCounter][3] = setTimeout("animateSlide("+loopCounter+", "+resizeSlider+")", document.sliderRateOfUpdate);
		}
	}
}

function returnSlider(sliderToMoveID, resizeSlider){
	for(var loopCounter =0; loopCounter < document.sliderInformation.length; loopCounter++){
		if(document.sliderInformation[loopCounter][0] == sliderToMoveID){
			clearTimeout(document.sliderInformation[loopCounter][3]);
			document.sliderInformation[loopCounter][2] = document.sliderInformation[loopCounter][1];
			if(resizeSlider){
				document.sliderInformation[loopCounter][4] = document.sliderInformation[loopCounter][5];
			}
			document.sliderInformation[loopCounter][3] = setTimeout("animateSlide("+loopCounter+", "+resizeSlider+")", document.sliderRateOfUpdate);
		}
	}
}

function returnSliderVertical(sliderToMoveID){
	var sliderTarget = document.getElementById(sliderToMoveID);
	sliderTarget.className = "activeSlider";
	document.getElementById(document.lastVerticalSlidTerm).className="defaultState";
	/*for(var loopCounter =0; loopCounter < document.sliderInformation.length; loopCounter++){
		if(document.sliderInformation[loopCounter][0] == sliderToMoveID){
			clearTimeout(document.sliderInformation[loopCounter][3]);
			document.sliderInformation[loopCounter][2] = document.sliderInformation[loopCounter][1];
			document.sliderInformation[loopCounter][3] = setTimeout("animateVerticalSlide("+loopCounter+")", document.sliderRateOfUpdate);
		}
	}*/
}

function animateVerticalSlide(sliderArrayKey){
	var targetSlider = document.getElementById(document.sliderInformation[sliderArrayKey][0]);
	var currentPosition = targetSlider.offsetTop;
	var targetPosition = document.sliderInformation[sliderArrayKey][2];
	if(currentPosition < targetPosition){
		var newPosition = currentPosition + document.sliderRateOfChange;
		if(newPosition > targetPosition){
			newPosition = targetPosition;
		}
	}else{
		var newPosition = currentPosition - document.sliderRateOfChange;
		if(newPosition < targetPosition){
			newPosition = targetPosition;
		}
	}
	targetSlider.style.top = newPosition + "px";
	if(newPosition != targetPosition){
		document.sliderInformation[sliderArrayKey][3] = setTimeout("animateVerticalSlide("+sliderArrayKey+")", document.sliderRateOfUpdate);
	}
}

function animateSlide(sliderArrayKey, resizeSlider){
	var targetSlider = document.getElementById(document.sliderInformation[sliderArrayKey][0]);
	var currentPosition = targetSlider.offsetLeft;
	var targetPosition = document.sliderInformation[sliderArrayKey][2];
	if(resizeSlider){
		var currentSize = targetSlider.offsetWidth;
		var targetSize = document.sliderInformation[sliderArrayKey][4];
		
		if(currentSize < targetSize){
			var newSize = currentSize + document.sliderRateOfChange;
			if(newSize > targetSize){
				newSize = targetSize;
			}
		}else{
			var newSize = currentSize - document.sliderRateOfChange;
			if(newSize < targetSize){
				newSize = targetSize;
			}
		}
		
		targetSlider.style.width = newSize + "px";
	}
	
	if(currentPosition < targetPosition){
		var newPosition = currentPosition + document.sliderRateOfChange;
		if(newPosition > targetPosition){
			newPosition = targetPosition;
		}
	}else{
		var newPosition = currentPosition - document.sliderRateOfChange;
		if(newPosition < targetPosition){
			newPosition = targetPosition;
		}
	}
	
	targetSlider.style.left = newPosition + "px";
	
	if(newPosition != targetPosition){
		document.sliderInformation[sliderArrayKey][3] = setTimeout("animateSlide("+sliderArrayKey+", "+resizeSlider+")", document.sliderRateOfUpdate);
	}else{
		if(resizeSlider){
			if(newSize != currentSize){
				document.sliderInformation[sliderArrayKey][3] = setTimeout("animateSlide("+sliderArrayKey+", "+resizeSlider+")", document.sliderRateOfUpdate);
			}else{
				clearTimeout(document.sliderInformation[sliderArrayKey][3]);
			}
		}else{
			clearTimeout(document.sliderInformation[sliderArrayKey][3]);
		}
	}
}


