var csaMin = -720; // minimum value for left (hidden)
var csaMax = 0; // maximum value for left (visible)
var csaStep = 50; // distance in pixels of each step
var csaInt = 20; // interval of time in ms between steps
var csaCurrent = null; // updated position of sliding ad - do not modify
var csaTimer = null; // pointer for setInterval
var csaAutoT = null;

var csaStore = GetCookie("csa");
var csaLeader = null, csaBanner = null, csaButton = null;
csaButton = document.getElementById("csaButton");
if((csaLeader = document.getElementById("csaLeader")) && (csaBanner = document.getElementById("csaBanner")) && (csaStore == null)){
	csaLeader.style.visibility = "visible";
	csaLeader.style.display = "block";
	csaButton.style.visibility = "hidden";
	csaCurrent = csaMax;
	csaBanner.style.left = csaCurrent + "px";
	csaAutoT = setTimeout("csaAuto()",5500);
}
else{
	csaCurrent = csaMin;
	csaBanner.style.left = csaCurrent + "px";
}

function csaAuto(){ // auto close banner
	if(csaAutoT){
		clearTimeout(csaAutoT);
		csaAutoT = null;
		setTimeout("csaReveal()",500);
	}
	if(csaTimer == null){
		csaTimer = setInterval("csaSlide(csaMin)",csaInt);
		setTimeout("csaReveal()",500);
	}

}

function csaClick(url){ // opens form in popup window, closes banner and sets cookie forever
	window.open(url,'enf','height=600,width=800,scrollbars');
	if(csaAutoT){
		clearTimeout(csaAutoT);
		csaAutoT = null;
		setTimeout("csaReveal()",500);
	}
	if(csaTimer == null){
		csaTimer = setInterval("csaSlide(csaMin)",csaInt);
		setTimeout("csaReveal()",500);
	}
	var expiry = new Date("12/31/2050");
	SetCookie("csa","csaDisabled",expiry,"/",".topekacivictheatre.com");
	return false;
}

function csaClose(){ // closes banner and sets cookie for one day
	if(csaAutoT){
		clearTimeout(csaAutoT);
		csaAutoT = null;
		setTimeout("csaReveal()",500);
	}
	if(csaTimer == null){
		csaTimer = setInterval("csaSlide(csaMin)",csaInt);
		setTimeout("csaReveal()",500);
	}
	var expiry = new Date();
	expiry.setTime(expiry.getTime() + 86400000);
	SetCookie("csa","csaDisabled",expiry,"/",".topekacivictheatre.com");
	return false;
}

function csaTease(){ // opens banner
	csaButton.style.visibility = "hidden";
	if(csaAutoT){
		clearTimeout(csaAutoT);
		csaAutoT = null;
	}
	if(csaTimer == null){
		csaTimer = setInterval("csaSlide(csaMax)",csaInt);
	}

	return false;
}

function csaSlide(target){ // slider engine
	if(csaCurrent == csaMin) csaLeader.style.display = "block";
	
	if(target == csaMin && csaCurrent > target){
		csaCurrent -= csaStep;
		if(csaCurrent < target) csaCurrent = target;
	}
	else{
		if(target == csaMax && csaCurrent < target){
			csaCurrent += csaStep;
			if(csaCurrent > target) csaCurrent = target;
		}
		else{
			if(csaCurrent == csaMin) csaLeader.style.display = "none";

			clearInterval(csaTimer);
			csaTimer = null;
		}
	}
	csaBanner.style.left = csaCurrent + "px";
}

function csaReveal(){
	csaButton.style.visibility = "visible";
}
