var iframeLayer,splashLayer,splashLayerElement,splashTimer,animationState,widthChange,animationPercent=5;

var dropDowns,resumeDelay=0;



/*

function increaseDelay() { resumeDelay=5000; }

function resetDelay() { resumeDelay=0; }

*/



function stopAnimation(evt) {

	if (!evt) var evt=event;

	cancelAnimation(evt);

	resumeDelay=-1;

}



function cancelAnimation(evt) {

	if (animationState==setup || splashLayerElement.offsetWidth==splashLayer.width || splashLayerElement.offsetWidth==0) clearTimeout(splashTimer);

	else clearInterval(splashTimer);

//	if (splashLayerElement.offsetWidth==splashLayer.width && dropDowns) for (var temp=0;temp<dropDowns.length;temp++) { dropDowns[temp].style.visibility="visible"; }

	if (dropDowns) for (var temp=0;temp<dropDowns.length;temp++) { dropDowns[temp].style.visibility="visible"; }

	splashLayer.style.visibility="hidden";

	if (!evt) var evt=event;

	evt.cancelBubble=true;

}



function resumeAnimation() {

	animationState=setup;

	if (resumeDelay>=0) splashTimer=setTimeout("animationState()",resumeDelay);

}



function loadQuickQuote() {

	if (!document.getElementById("quickQuote")) return;

	document.getElementById("quickQuote").getElementsByTagName("form")[0].style.display="block"; //NOTE: Forms do not appear unless the user has javascript enabled.

	splashLayer=document.getElementById("splash");

	for (splashLayerElement=splashLayer.firstChild;splashLayerElement.nodeType!=1;splashLayerElement=splashLayerElement.nextSibling);

	splashLayer.width=splashLayerElement.width;

	widthChange=animationPercent/100*splashLayer.width;

	iframeLayer=splashLayer.getElementsByTagName("iframe")[0];

	if (iframeLayer) {

		iframeLayer.style.display="block";

		iframeLayer.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";

		iframeLayer.style.position="absolute";

		iframeLayer.style.marginLeft="-1px";

		iframeLayer.style.zIndex=splashLayer.style.zIndex-1;

		iframeLayer.width=splashLayerElement.width;

		iframeLayer.height=splashLayerElement.height;

		dropDowns=splashLayer.parentNode.getElementsByTagName('select');

	}

	animationState=setup;

	splashTimer=setTimeout("animationState()",7000);

	splashLayer.parentNode.onmouseover=cancelAnimation;

	splashLayer.parentNode.onmouseout=resumeAnimation;

	splashLayer.style.position="static";

	splashLayer.parentNode.style.position="static";

	splashLayer.style.left=(splashLayer.parentNode.offsetWidth-splashLayerElement.offsetWidth)/2+"px";

	splashLayer.style.top=splashLayer.parentNode.offsetTop-splashLayer.offsetTop+(splashLayer.parentNode.offsetHeight-splashLayerElement.offsetHeight)/2-parseFloat(splashLayer.style.left)+"px";

	splashLayer.parentNode.style.position="relative";

	splashLayer.style.position="relative";



/*

	var inputs=splashLayer.parentNode.getElementsByTagName('input');

	for (var temp=0;temp<inputs.length;temp++) {

		inputs[temp].onfocus=increaseDelay;

		inputs[temp].onblur=resetDelay;

	}

*/



	var inputs=splashLayer.parentNode.getElementsByTagName('input');

	for (var temp=0;temp<inputs.length;temp++) inputs[temp].onfocus=stopAnimation;

	inputs=splashLayer.parentNode.getElementsByTagName('select');

	for (var temp=0;temp<inputs.length;temp++) inputs[temp].onfocus=stopAnimation;

}



function setup() {

	splashLayerElement.width=1;

	if (iframeLayer) iframeLayer.width=iframeLayer.height=0;

	updatePosition();

   splashLayer.style.visibility="visible";

	switchTo(expand);

}



function expand() {

	if (splashLayerElement.width+widthChange>splashLayer.width) splashLayerElement.width=splashLayer.width;

	else splashLayerElement.width+=widthChange;

	if (iframeLayer) {

		iframeLayer.width=splashLayerElement.width;

		iframeLayer.height=splashLayerElement.height;

	}

	updatePosition();

	if (splashLayerElement.offsetWidth==splashLayer.width) {

		clearInterval(splashTimer);

		splashTimer=setTimeout("switchTo(retract)",4000);

	}

}



function switchTo(func) {

/*	if (dropDowns)

		if (func==expand) for (var temp=0;temp<dropDowns.length;temp++) { dropDowns[temp].style.visibility="hidden"; }

		else if (func==retract) for (var temp=0;temp<dropDowns.length;temp++) { dropDowns[temp].style.visibility="visible"; } */

	if (dropDowns && func==expand) for (var temp=0;temp<dropDowns.length;temp++) { dropDowns[temp].style.visibility="hidden"; }

	animationState=func;

	splashTimer=setInterval("animationState()",10);

}



function retract() {

	if (splashLayerElement.width-widthChange<=1) splashLayerElement.width=1;

	else splashLayerElement.width-=widthChange;

	if (iframeLayer) {

		iframeLayer.width=splashLayerElement.width;

		iframeLayer.height=splashLayerElement.height;

	}

	updatePosition();

	if (splashLayerElement.offsetWidth<=1) { //NOTE: Compensate for varying offsetWidth behavior

		clearInterval(splashTimer);

		splashTimer=setTimeout("switchTo(expand)",7000);

		if (dropDowns) for (var temp=0;temp<dropDowns.length;temp++) { dropDowns[temp].style.visibility="visible"; }

	}

}



function updatePosition() {

	splashLayerElement.style.marginTop=splashLayer.style.left=(splashLayer.parentNode.offsetWidth-splashLayerElement.offsetWidth)/2+"px";

	if (iframeLayer) iframeLayer.style.marginTop=splashLayerElement.style.marginTop;

}



if (window.addEventListener) window.addEventListener("load",loadQuickQuote,false);

else window.attachEvent("onload",loadQuickQuote);
