var attPopupOpen = 0; //number of popups that disables the screen that are open.
var popOnStart = "";
var currPopupClearFunc = null;
var currPopupName = null;
var popupInfoObj;
var popupSetFailed = false;
var popupSetRetryTimer;

function managePopup(popupClearFunc){
		if ((currPopupClearFunc!=null)&&(popupClearFunc!=currPopupClearFunc)){
			currPopupClearFunc();
		}
		currPopupClearFunc = popupClearFunc;
		//document.getElementById("popups").className = "popups";
}

function disable(disableType){
	if (attPopupOpen<2){
		switch (disableType){
			case "trans":
				document.getElementById("blocker").className = "cover";
				document.getElementById("blockerContainer").className = "transDisabler";
				document.getElementById("blockerContainer").style.top=-10;
				document.getElementById("blockerContainer").style.height = overallHeight+10;
				fadeBlockerIn();
			break;
			default: break;
		}
	}
	return;
}

function enable(){
	if (attPopupOpen<2){
		/*var swf = document.getElementById("blocker");
		swf.fadeBlockerOutAndAbout();*/
		fadeBlockerOut();
		//hideBlocker();
		document.getElementById("popups").className = "f-hide";
	}
}

function hideBlocker(){
	document.getElementById("blockerContainer").className = "hiddenForm";
	
}

function showPopup(popupName, infoObj){
	//loads a popup and tries to set infoObj to it
	currPopupName = popupName;
	//cancelling timer if another poup is still trying to set:
	clearTimeout(popupSetRetryTimer);
	//overwrite all SWFsArray properties that appear in infoObj:
	for (i in infoObj){
		SWFsArray[popupName][i] = infoObj[i]
	}
	//setting all the CSS:
	document.getElementById("popups").className = "popups";	
	embedSWF(SWFsArray[popupName],0);
	document.getElementById("popups").style.top = SWFsArray[popupName].posY;
	document.getElementById("popups").style.marginLeft = -SWFsArray[popupName].width/2-490+SWFsArray[popupName].posX;
	//block view:
	attPopupOpen++;
	disable("trans");

	//trying to set infoObj into the SWF:
	if (document.getElementById(SWFsArray[popupName].divName).setPopup){
		document.getElementById(SWFsArray[popupName].divName).setPopup(infoObj);
		popupSetFailed = false;
	} else {
		popupInfoObj = infoObj;
		popupSetFailed = true;
	}
}

function forcePopupSet(){
	//trying again after the popup SWF was completely loaded:	
	if (!popupSetFailed){
		//if set popup was successful - no need to continue
		return;
	}
	if (document.getElementById(SWFsArray[currPopupName].divName).setPopup){
		//if function exists - perform set
		document.getElementById(SWFsArray[currPopupName].divName).setPopup(popupInfoObj);
		popupSetFailed = false;
	} else {
		//if still not recognizing the function - keep trying in timeouts:
		popupSetRetryTimer = setTimeout("forcePopupSet();",1000);
	}
}

function hidePopup(){
	document.getElementById("normalPopup").className = "f-hide";
	document.getElementById("popups").className = "f-hide";
	//unblock view:
	attPopupOpen--;
	enable();
}