// ************ VUNDERMENHU by Neil Challis ************

// ************ CONFIG STARTS ************
var fadeSpeed = 10;                             // how many px to move each frame?
var numPopups = 7;                              // how many popups you got then?
// ************ CONFIG ENDS ************

var currentPopup = null;                        // to track current popup
var currentOpacity = 0;                            // we need this to track popup's x as attempting to read
												// back style.left appends "px" to the value, which is a hassle
var reallyHidePopups = false;
var currentPopupTop = 0;

function ShowPopup(current) {                   // SHOW A SELECTED POPUP
	CancelHidePopups();							// Cancel any scheduled hide
	
	HidePopups();

	currentPopup = document.getElementById("popup"+current);    // Grab handle to current popup
	currentOpacity = 0;                    // set our position tracker
	currentPopupTop = 125 + (current * 33);
	setTimeout('AnimateCurrentPopup()', 20);    // request a timer event in 20ms
	
	return;

}

function HidePopupsWithDelay() {
	setTimeout('HidePopupsWithCheck()', 500);
	reallyHidePopups = true;
}

function HidePopupsWithCheck() {
	if (reallyHidePopups) {
		HidePopups();           
	}
}

function CancelHidePopups() {
	reallyHidePopups = false;
}

function HidePopups() {
	for (var i=0; i<numPopups; i++) {           // Turn all the popups off
		var e = document.getElementById("popup"+i);
		if (e==null) continue;
		e.style.display = 'none';
	}            
}

function AnimateCurrentPopup() {                // ANIMATE CURRENT POPUP
	if (currentOpacity < 100) {               // not there yet?
		currentPopup.style.display = 'block';       // make it visible
		
		currentOpacity += fadeSpeed;
		
		var isIE = /*@cc_on!@*/false;
		
		opacityString = (currentOpacity / 100);
		filterString = "alpha(opacity=" + currentOpacity + ")";
		
		var pageWidth = 0;
		var realPopupTop = currentPopupTop;

		if (isIE) {
			currentPopup.style.filter = filterString;
			pageWidth = document.body.clientWidth;
			//alert(document.body.scrollTop);
			//realPopupTop += document.body.scrollTop;
		} else {
			currentPopup.style.opacity = opacityString;
			pageWidth = window.innerWidth;
			//realPopupTop += window.pageYOffset;
		}
		
		currentPopup.style.top = realPopupTop + "px";
		
		var left =  1180;          // set horizontal start point of popup
		var leftIE = 1180;        // set horizontal start point of popup for Internet Explorer only
		
		if (isIE) {
		currentPopup.style.left = leftIE + "px";
		}else {
		currentPopup.style.left = left + "px";
		}
		
		setTimeout('AnimateCurrentPopup()', 20);// since it's not at stop pos yet, re-request the timer
	}
}
