// shwSlide.js -- curtains -- (c)2008 SugarHill Works, LLC - http://www.sugarhillworks.com

// This version of shwSlide takes two DIVs with background images to create a 'curtain-opening'effect.
// Default positioning should be set in the CSS.


// get the element(s) to slide and relevant style info on body load
var curtainL, curtainR, curtains_closed_W;
function getElements() {
	curtainL = document.getElementById('curtainL');
	curtainR = document.getElementById('curtainR');
	curtains_closed_W = curtainL.offsetWidth;
}

// set vars to use in styles for when animation is completed
var curtains_open_W = 0;
var speed = 10; 


// set default vars 
var curtainsOpened = false;
var curtainsClosed = false;
var opening = false;


function openCurtains() {
	if(curtainsOpened == true) return;
	curtains_closed_W -= speed; if(curtains_closed_W < curtains_open_W) curtains_closed_W = curtains_open_W;
	if(curtains_closed_W == curtains_open_W) {
		curtainL.style.width = curtains_open_W + 'px';
		curtainL.style.visibility = "hidden";
		curtainR.style.width = curtains_open_W + 'px';
		curtainR.style.visibility = "hidden";
		opening = false;
		curtainsOpened = true;
		return;
	} else {
		opening = true;
		curtainsOpened = false;
		curtainL.style.width = curtains_closed_W + 'px';
		curtainR.style.width = curtains_closed_W + 'px';
		setTimeout('openCurtains()', 25);
		return;
	}
}
function slide() {
	if(opening == true) { //prevent overlapping instances
		setTimeout('slide()', 100);
		return;
	}
	if((curtainsOpened == true)) {
		return;
	} else {
		openCurtains();
	}
}
	
window.setTimeout("slide();", 5000);	
	

