/* All content below is the intellectual property of Crown Productions. */

// runs init after the page has been loaded to ensure there are no script errors
runAfterLoad(init);
// preload navigation roll over images
var preload = new Array();
var loadImgs = new Array('hors', 'full', 'accomp', 'tea', 'mini', 'contact', 'print','receptions','buffets','testimonials','breakfast','venues','gallery');
for(var i=0;i<loadImgs.length;i++){
	preload.push(new Image());
	preload[preload.length-1].src = 'images/nav/'+loadImgs[i]+'!.jpg';
}
// initialization function
var rightPanel;
var leftPanel;
function init(){
	// panel references
	rightPanel = document.getElementById('rightPanel');
	leftPanel = document.getElementById('leftPanel');
	// make leftPanel visible
	leftPanel.style.display = 'block';
	// don't scroll the panel at the start
	initialPos = getScrollXY()[1];
	//leftPanel.style.top = initialPos + 'px';
	// call slide to initiate the function
	//slideToTop(0);
}
// slide the left panel
function slideToTop(lastVel){
	// set the new destination for the left panel 
	newDest = getScrollXY()[1];
	// object references
	leftTop = leftPanel.offsetTop;
	leftBottom = leftPanel.offsetTop + leftPanel.offsetHeight;
	rightBottom = rightPanel.offsetTop + rightPanel.offsetHeight;
	// increment the left panels position closer to the destination
	vel = (newDest-leftTop)/5;
	vel = vel/lastVel<0?vel:vel+lastVel;
	// only move the panel if the total velocity is greater than 1 and the bottom is not flowing off the page
	if(Math.abs(vel)>1 && (leftBottom<=rightBottom || vel<0)){
		leftPanel.style.top = leftTop + vel + 'px';
		// reset the velocity
		vel = 0;
	}
	setTimeout('slideToTop('+vel+')',0);
}
// default form values
function inputDefault(field){
	var fieldValues = new Array('Name', 'E-mail Address', 'Phone Number', 'Message Subject', 'Message'); // array of possible default form values
	
	// checks if a form value is default and clears it onFocus
	for(var i=0; i<fieldValues.length; i++){
		if(field.value == fieldValues[i]){
			field.value = '';
			field.temp = fieldValues[i]; // stores the forms default value in a temp variable
			field.style.color = '#007C57';
		}
	}
}
function resetDefault(field){
	// checks if a form value is empty and resets it to it's default onBlur
	if(field.value == ''){
		field.value = field.temp;
		field.style.color = '#666';
	}	
}