var allHTMLTags = new Array();

function getElementsByClass(theClass) {
  var allHTMLTags=document.getElementsByTagName("*");
	var tempArr = new Array();
  for (i=0; i<allHTMLTags.length; i++) {
    if (allHTMLTags[i].className==theClass) {tempArr.push(allHTMLTags[i]);}
  }
	return tempArr;
}


var popupArray = new Array();

if (document.getElementById) {
// GLOBAL VARIABLES
	var op = 0;
	var MS = "Microsoft Internet Explorer";
	var sec; var doc; var popup; var popup_Height; var popup_Width;
	
	function closeLayer(target) {
		var temp = document.getElementById(target);
		temp.style.display =  "none";
		//if (navigator.appName == MS) self.setTimeout("fadeOutLayer(popup.filters.alpha, 0, 10)", 5);
		//else self.setTimeout("fadeOutLayer(popup.style, 0.0, 0.1)", 5);
	}
	function displayLayer(pIndex) {
		var wrap = document.createElement("div");
		wrap.setAttribute('class','popup_ad');
		popupArray[pIndex].doc.appendChild(wrap);
		//wrap.style.backgroundColor = "transparent";
		wrap.style.height = popupArray[pIndex].h;
		//wrap.style.margin = "0px auto";
		//wrap.style.position = "relative";
		wrap.style.width = popupArray[pIndex].w;
		/*
		if (navigator.appName == MS) wrap.style.filter = 'alpha(opacity=0)'; // IE ONLY 
		else wrap.style.opacity = 0.0;
		*/
		popupArray[pIndex].popup = wrap;
				
		while (popupArray[pIndex].doc.firstChild.getAttribute("class") != 'popup_ad') {
			element = popupArray[pIndex].doc.firstChild;
			popupArray[pIndex].doc.removeChild(element);
			wrap.appendChild(element);
		}
			
		popupArray[pIndex].doc.style.display = 'block';
		var topPos = document.body.scrollTop + document.body.clientHeight/2 - wrap.offsetHeight/2;
		if (topPos < 0) topPos = 0; 
		popupArray[pIndex].doc.style.top = topPos;
				
		if (navigator.appName == MS) self.setTimeout(function(){fadeInLayer(pIndex,popupArray[pIndex].popup.filters.alpha, 100, 10);}, 1);
		else self.setTimeout(function(){fadeInLayer(pIndex,popupArray[pIndex].popup.style, 1.0, 0.1);}, 1);
		
		
	}
	function fadeInLayer(pIndex, styleAttribute, maxAmount, counter) {
		if (navigator.appName == MS) popupArray[pIndex].popup.style.filter = 'alpha(opacity=100)'; /* IE ONLY */
		else popupArray[pIndex].popup.style.opacity = 1;
		popupArray[pIndex].popup.style.display = 'block';
		/*
		op+=counter;
		styleAttribute.opacity = op;
		
		if (styleAttribute.opacity < maxAmount) {
			if (navigator.appName == MS) self.setTimeout("fadeInLayer(popup.filters.alpha, 100, 10)", 5);
			else self.setTimeout("fadeInLayer(popup.style, 1.0, 0.1)", 5);
		}
		*/
	}
	function fadeOutLayer(pIndex, styleAttribute, maxAmount, counter) {
		
		
		//if (navigator.appName == MS) popupArray[pIndex].popup.style.filter = 'alpha(opacity=0)'; /* IE ONLY */
		//else popupArray[pIndex].popup.style.opacity = 0;
		popupArray[pIndex].popup.style.display = 'none';
		/*
		op-=counter;
		styleAttribute.opacity = op;
		if (styleAttribute.opacity > maxAmount) {
			if (navigator.appName == MS) self.setTimeout("fadeOutLayer(popup.filters.alpha, 0, 10)", 5);
			else self.setTimeout("fadeOutLayer(popup.style, 0.0, 0.1)", 5);
		}
		else doc.style.display = 'none';
		*/
	}
	
	function runFakePopup(targetID ,num, popHeight, popWidth) {
		var tempObj = new Object();
		var num = num * 1000;
		doc = document.getElementById(targetID);
		sec = num;
		popup_Height = popHeight;
		popup_Width = 0;
		if (popWidth == "auto") popup_Width = 960;
		else popup_Width = popWidth;
		
		tempObj.doc = document.getElementById(targetID);
		tempObj.h = popup_Height;
		tempObj.w = popup_Width;
		
		doc.style.display = "none";
		doc.style.height = "auto";
		doc.style.position = "absolute";
		doc.style.textAlign = "center";
		//if (navigator.appName == MS) doc.style.left = -100;
		doc.style.top = 0;
		doc.style.width = 960; 
		doc.style.zIndex = 100;
		
		var tempIndex = popupArray.length;
		popupArray.push(tempObj);		
		//alert(eval("'displayLayer("+tempIndex+")'"));
		self.setTimeout(function(){displayLayer(tempIndex);}, num);
	}	
}
