var basePath = "";
var timedPointer = null;
var timeout = 3000;
var introTimer = null;
var showBanner2Timeout = null;
var hideBannersTimeout = null;
var timer = 5;

function pageOnload(newBasePath, newTimeout) {
	if(newBasePath) basePath = newBasePath;
	if(newTimeout) timeout = newTimeout;
	showBanner();
}

function showBanner() {

	var body = getBody();
	
	var div = document.createElement("div");
	div.style.width = "100%";
	div.style.height = "200%";
	div.style.position = "absolute";
	div.style.top = "0";
	div.style.left = "0";
	div.style.background = "transparent url("+basePath+"/lib/images/white_transparent_back.png)";
	div.style.textAlign = "center";
	div.id = "fade";
	div.style.opacity = "1";
	div.onclick = function() {
		hideBanner();
	}
	body.appendChild(div);
	
	var img = document.createElement("img");
	img.src = basePath+"/lib/images/APO_intro_white_oval.png";
	img.id = "banner";
	
	var dom = null;
	
	if(document.all) {
		dom = document.createElement("embed");
		dom.setAttribute("src", "/lib/images/apo_flash_warning.swf");
		dom.setAttribute("width", 600);
		dom.setAttribute("height", 150);
		dom.setAttribute("name", "warning");
		dom.setAttribute("allowScriptAccess","sameDomain");
		dom.setAttribute("type", "application/x-shockwave-flash");
		dom.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
	} else {
		dom = document.createElement("object");
		dom.setAttribute("type", "application/x-shockwave-flash");
		dom.setAttribute("width", 600);
		dom.setAttribute("height", 150);
		dom.setAttribute("data", "/lib/images/apo_flash_warning.swf");
	}
	dom.id = "warning";
	dom.style.marginTop = "65px";
	
	var box = document.createElement("div");
	box.style.background="transparent url(/lib/images/APO_intro_white_oval.png) no-repeat center center";
	box.style.width = "736px";
	box.style.height = "266px";
	box.style.margin = "0 auto";
	box.style.marginTop = "18%";
	box.style.verticalAlign = "middle";
	box.appendChild(dom);
	div.appendChild(box);
	
	if(hideBannersTimeout) {
		clearTimeout(hideBannersTimeout);
		hideBannersTimeout = null;
	}
	hideBannersTimeout = setTimeout(hideBanner, timeout);
}

function showBanner2() {
	var body = getBody();
	var div = document.getElementById("fade");
	if(div == null) {
		div = document.createElement("div");
		div.style.width = "100%";
		div.style.height = "200%";
		div.style.position = "absolute";
		div.style.top = "0";
		div.style.left = "0";
		div.style.background = "transparent url("+basePath+"/lib/images/black_transparent_back.png)";
		div.style.textAlign = "center";
		div.style.opacity = ".2";
		div.id = "fade";
		div.style.opacity = "1";
		body.appendChild(div);
	}	
	if(hideBannersTimeout) {
		clearTimeout(hideBannersTimeout);
		hideBannersTimeout = null;
	}
	hideBannersTimeout = setTimeout(hideBanner, parseInt(timeout*1.5,10));
	
	var img = document.getElementById("banner");
	if(img == null) {
		img = document.createElement("img");
		img.src = basePath+"/lib/images/APO_intro_red2.png";
		img.style.marginTop = "20%";
		div.appendChild(img);
	} else {
		img.src = basePath+"/lib/images/APO_intro_red2.png";
		img.onclick =  function() {
			if(hideBannersTimeout) {
				clearTimeout(hideBannersTimeout);
				hideBannersTimeout = null;
			}
			hideBanner();
		}
	}
}

function hideBanner() {
	clearNode();
}

function clearNode() {

	var div = document.getElementById("fade");
	while(div.firstChild) {
		recursiveNodeRemove(div.firstChild);
	}
	div.style.background = "none";
	div.style.height = "100%";
	div.style.zIndex = "-1";

	var body = getBody();
	if(document.all) {
		body.scroll = "yes";
	} else {
		body.style.overflow = "auto";
	}
}

function getBody() {

	var body = null;
	if(document.all) {
		body = document.body;
	} else {
		var elements = document.getElementsByTagName("body");
		for(var i=0; i<elements.length; i++) {
			if(elements[i] instanceof HTMLBodyElement) {
				body = elements[i];
				break;
			}
		}
	}		
	if(document.all) {
		body.scrolling = "no";
	} else {
		body.style.overflow = "auto";
	}
	return body;
}

function recursiveNodeRemove(node) {
	while(node.firstChild) {
		recursiveNodeRemove(node.firstChild);
	}
	node.parentNode.removeChild(node);
}

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 