﻿function splWidgetHeaderNavInit(splWidgetHeight, splWidgetHighlightPageId) {

	var divSplWidget = document.getElementById("splWidgetHeader");
	var splPageId = "";
	if (isNaN(splWidgetHighlightPageId)) {
		splPageId = "?pageId=1";
	} else {
		splPageId = "?pageId=" + splWidgetHighlightPageId;
	}
	var ifSplWidgetHolder = document.createElement("iframe");
	ifSplWidgetHolder.src = "http://www.saclibrary.org/widget/headerNav.aspx" + splPageId;
	ifSplWidgetHolder.setAttribute("id", "ifSplWidgetHeader");
	ifSplWidgetHolder.frameBorder = 0;
	ifSplWidgetHolder.style.height = splWidgetHeight + "px";
	ifSplWidgetHolder.style.width = "1000px";
	ifSplWidgetHolder.style.visibility = "hidden";
	//This is dumb, but...
	//The iframes onload fires when the iframe is in place not when the page inside the iframe is loaded.
	//To avoid an empty white iframe added the 500ms delay before making the frame visible.
	//That may be to much or too little depending on bandwith and 5millon other things.
	//The way to fix this, don't use an iframe. Write all the html onto the page using javascript.
	//Got a lot of spare time? You do it.
	ifSplWidgetHolder.onload = new function() { setTimeout("loadDoneShowWiget('ifSplWidgetHeader')", 500); };
	ifSplWidgetHolder.setAttribute("scrolling", "no");
	divSplWidget.appendChild(ifSplWidgetHolder);
}

function splWidgetRightColumnInit(splWidgetContentPageId) {

	var divSplWidget = document.getElementById("splWidgetRightColumn");
	var splPageId = "";
	if (isNaN(splWidgetContentPageId)) {
		splPageId = "?pageId=1";
	} else {
		splPageId = "?pageId=" + splWidgetContentPageId;
	}
	var ifSplWidgetHolder = document.createElement("iframe");
	ifSplWidgetHolder.src = "http://www.saclibrary.org/widget/rightColumn.aspx" + splPageId;
	ifSplWidgetHolder.setAttribute("id", "ifSplWidgetRightColumn");
	ifSplWidgetHolder.frameBorder = 0;
	ifSplWidgetHolder.setAttribute("height", "700px");
	ifSplWidgetHolder.setAttribute("width", "170px");
	ifSplWidgetHolder.style.visibility = "hidden";
	//This is dumb, but...
	//The iframes onload fires when the iframe is in place not when the page inside the iframe is loaded.
	//To avoid an empty white iframe added the 500ms delay before making the frame visible.
	//That may be to much or too little depending on bandwith and 5millon other things.
	//The way to fix this, don't use an iframe. Write all the html onto the page using javascript.
	//Got a lot of spare time? You do it.
	ifSplWidgetHolder.onload = new function() { setTimeout("loadDoneShowWiget('ifSplWidgetRightColumn')", 550); }
	ifSplWidgetHolder.setAttribute("scrolling", "no");
	divSplWidget.appendChild(ifSplWidgetHolder);
}

function splWidgetFooterInit() {

	var splWidgetFooter = document.getElementById("splWidgetFooter");
	var ifSplWidgetHolder = document.createElement("iframe");
	ifSplWidgetHolder.src = "http://www.saclibrary.org/widget/footer.aspx";
	ifSplWidgetHolder.setAttribute("id", "ifSplWidgetFooter");
	ifSplWidgetHolder.frameBorder = 0;
	ifSplWidgetHolder.setAttribute("height", "230px");
	ifSplWidgetHolder.setAttribute("width", "1000px");
	ifSplWidgetHolder.style.visibility = "hidden";
	//This is dumb, but...
	//The iframes onload fires when the iframe is in place not when the page inside the iframe is loaded.
	//To avoid an empty white iframe added the 500ms delay before making the frame visible.
	//That may be to much or too little depending on bandwith and 5millon other things.
	//The way to fix this, don't use an iframe. Write all the html onto the page using javascript.
	//Got a lot of spare time? You do it.
	ifSplWidgetHolder.onload = new function() { setTimeout("loadDoneShowWiget('ifSplWidgetFooter')", 450); }
	ifSplWidgetHolder.setAttribute("scrolling", "no");
	splWidgetFooter.appendChild(ifSplWidgetHolder);
}

function loadDoneShowWiget(widgetId) {
	document.getElementById(widgetId).style.visibility = "visible";
}
