new function() {

	eval(estrada.namespace);
	var arrChildren = [];
	attachEvent(document, "layout", function() {
		document.body.className = "l-inner";

		// build the layout
		var layout = frame("page",
			cols(
				area("logo"),
				frame("header",
					area("school-name"),
					area("sections"),
					cols(
						area("tools"),
						area("search")
					),
					area("supercrumb")
				)
			),
			cols(
				frame("main-left", 
					area("title"),
					cols(
						frame("left",
							area("highlight"),
							area("also")
						),
						frame("right",
							area("content")
						)
					)
				),
				area("related")
			),
			area("footer"),
			area("reviewed")).build(document.getElementById("form"));
		
		// grab titling properties	
		layout.push(grab(document.getElementById("titling"), {
			"page": "title"
		}));
		
		// grab navigation properties
		layout.push(grab(document.getElementById("navigation"), {
			supercrumb: "supercrumb"	
		}));
		
		// grab context properties
		layout.push(grab(document.getElementById("context"), {
			reviewed: "reviewed",
			footer: "footer"
		}));
		
		// grab feeds
		layout.push(grab(document.getElementById("feeds"), {
			tools: "tools",
			sections: "sections",
			highlight: "highlight",
			also: "also",
			related: "related"
		}));
		
		// grab content areas
		layout.push({
			content: "content",
			search: "search"
		});
		layout.push(grab(document.getElementById("titling"), {
			"site-inner": "logo"
		}));
		var searchQuery = document.getElementById("search-query");
		if (searchQuery) {
			var defaultText = "Search";
			var blurClassName = "text l-blur";
			searchQuery.value = defaultText;
			searchQuery.className = blurClassName;
			attachEvent(searchQuery, "focus", function() {
				if (searchQuery.value == defaultText) {
					searchQuery.value = "";
					searchQuery.className = "text";
				}
			});
			attachEvent(searchQuery, "blur", function() {
				if (searchQuery.value.length == 0) {
					searchQuery.value = defaultText;
					searchQuery.className = blurClassName;
				}
			});
			attachEvent(searchQuery, "keydown", function(searchQuery, e) {
                if (e.keyCode == 13) {
                    window.setTimeout("document.getElementById(\"search-submit\").click()", 0);
                    return false;
                }
                return true;
			});
		}
		var searchSubmit = document.getElementById("search-submit");
		if (searchSubmit) {
			var parent = searchSubmit.parentNode;
			var div = parent.appendChild(document.createElement("div"));
			div.id = "l-search-submit";
			attachEvent(div, "click", function() {
				document.getElementById("search-submit").click();
			});
		}
		// add sections behavior
		var oSections = getElements(document, "div", "sections");
		if (oSections) {
			foreach(map(oSections), function(oSection) {
				var oLinks = first(getElements(oSection, "div", "links"));
				if (oLinks) {
					if (oLinks.className) {
						oLinks.className = oLinks.className + " l-hide";
					} else {
						oLinks.className = "l-hide";
					}
				}
				tilt.attachEvent(oSection, "mouseout", toggleSection);
				tilt.attachEvent(oSection, "mouseover", toggleSection);
			});
		}
		
		// add supercrumb behavior
		var oSupercrumb = first(getElements(document, "div", "supercrumb"));
		if (oSupercrumb) {
			var oNewSupercrumb = document.createElement("div");
			oNewSupercrumb.className = "supercrumb";
			oNewUl = oNewSupercrumb.appendChild(document.createElement("ul"));
			foreach(map(oSupercrumb.getElementsByTagName("li")), function(oLi) {
				if (oLi.className && (oLi.className.indexOf("ancestor") >= 0 || oLi.className.indexOf("current") >= 0)) {
					var oNewLi = oNewUl.appendChild(document.createElement("li"));
					oNewLi.className = oLi.className;
					var oTopElement;
					foreach(map(oLi), function(oElm) {
						if (oElm.nodeType == 1 && (oElm.tagName.toLowerCase() == "a" || oElm.tagName.toLowerCase() == "strong")) {
							oTopElement = oElm;
							return(true);
						}
					});
					if (oTopElement) {
						oNewLi.appendChild(oTopElement.cloneNode(true));
					}
					var oChildren = oNewLi.appendChild(document.createElement("div"));
					oChildren.className = "children l-hide";
					arrChildren.push(oChildren);
					var oUl = first(oLi.getElementsByTagName("ul"));
					if (oUl) {
						addController(oNewLi);
					}
					else {
						addEmptyController(oNewLi);
					}
					foreach(map(oUl), function(oChild) {
						var oTopElement;
						foreach(map(oChild), function(oElm) {
							if (oElm.nodeType == 1 && (oElm.tagName.toLowerCase() == "a" || oElm.tagName.toLowerCase() == "strong")) {
								oTopElement = oElm;
								return(true);
							}
						});
						if (oTopElement) {
							var oNewLink;
							if ((oTopElement.tagName.toLowerCase() == "a") && (oTopElement.parentNode.className && oTopElement.parentNode.className.indexOf("ancestor") >= 0)) {
								oNewLink = document.createElement("strong");
								oNewLink.innerHTML = oTopElement.innerHTML;
							} else {
								oNewLink = oTopElement.cloneNode(true);
							}
							oChildren.appendChild(oNewLink);
						}
					});
				}
			});
		}
		oSupercrumb.parentNode.insertBefore(oNewSupercrumb, oSupercrumb);
		oSupercrumb.parentNode.removeChild(oSupercrumb);
		tilt.attachEvent(document.body, "click", hideChildren);
		/* Z-index fix for supercrumbs - IE transparency */
		var zCounter = 450;
		foreach (map(oNewSupercrumb.getElementsByTagName("li")), function(li) {
			li.style.zIndex = zCounter;
			zCounter = zCounter - 1;
			foreach (li.getElementsByTagName("a"), function(a) {
				a.style.zIndex = zCounter;
				zCounter = zCounter - 1;
			});
			foreach (li.getElementsByTagName("div"), function(div) {
				div.style.zIndex = zCounter;
				zCounter = zCounter - 1;
			});
			zCounter = zCounter - 7;  //totally arbitrary decrease
		});	

		foreach(document.getElementsByTagName("ul"), function(ul) {
			foreach(ul.getElementsByTagName("li"), function(li) {
				if (li.className) {
					li.className += " l-first";
				} else {
					li.className = "l-first";
				}
				return true;
			});
		});
	
		///////////////////////////////////////////////////////////////////////
		// include script for datetime picker, if needed
		///////////////////////////////////////////////////////////////////////
		if (filter(document.getElementsByTagName("input"), function(input) {
			return input.className.indexOf("date") >= 0;
		}).length > 0) {
			tilt.addScript("datetime.js");	
		}
		
		///////////////////////////////////////////////////////////////////////
		// include script for grid, if needed
		///////////////////////////////////////////////////////////////////////
		var oContent = document.getElementById("l-content");
		if (oContent) {
			if (foreach(oContent.getElementsByTagName("div"), function(div) {
				if (div.className == "visibility") {
					div.id = "grid-visibility";
					return true;
				}
			})) {
				tilt.addScript("grid.js");
			}
		}
		
		///////////////////////////////////////////////////////////////////////
		// include script for category-editor, if needed
		///////////////////////////////////////////////////////////////////////
		if (filter(document.getElementsByTagName("div"), function(div) {
			return div.className.indexOf("category-editor") >= 0;
		}).length > 0) {
			tilt.addScript("dynamictree.js");	
		}

		///////////////////////////////////////////////////////////////////////
	    // replace images with flash by convention
		///////////////////////////////////////////////////////////////////////
		foreach(map(document.getElementsByTagName("img")), function(img) {
			var oSrc = img.src;
			if (oSrc && oSrc.indexOf(".swf.") > 0) {
				replaceWithFlash(img);
			}
		});	
		
		function replaceWithFlash(img)
		{
			var width = img.currentStyle ? img.currentStyle.width.replace(/px/, "") : img.width;			
			var height = img.currentStyle ? img.currentStyle.height.replace(/px/, "") : img.height;
			var src = img.src;
			if (width && height && src) {
				var movie = src.replace(/\.swf\..+/, ".swf");
				var version = 4;
				var useNetscapePlugins = navigator.plugins && navigator.mimeTypes.length;
				if (detectFlash())
				{
					var child = img;
					var oParent = img.parentNode;
					if (oParent.nodeName.toUpperCase() == "A") {
						child = oParent;
						oParent = oParent.parentNode;
					}
					var classname = child.className;
					var flashDiv = document.createElement("div");
					flashDiv.className = classname;
					flashDiv.innerHTML = createMovieHtml();
					oParent.replaceChild(flashDiv, child);
				}
				
			}
	
			function createMovieHtml()
			{
				var sizeAttributes = "width=\"" + width + "\" height=\"" + height + "\"";
				return useNetscapePlugins ?
					"<embed type=\"application/x-shockwave-flash\" src=\"" + movie + "\" " + sizeAttributes + "></embed>"
					:
					"<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " + sizeAttributes + "><param name=\"movie\" value=\"" + movie + "\" /></object>";
			}
			
			function detectFlash()
			{
				return getFlashVersion() >= version;
	
				function getFlashVersion()
				{
					if (useNetscapePlugins)
					{
						var plugin = navigator.plugins["Shockwave Flash"];
						if(plugin && plugin.description)
						{
							var description = plugin.description;
	   						return description.charAt(description.indexOf('.')-1);
						}
					} 
					else
					{
						var version = 0;
						for(var i = 4; i >= 3; i--)
						{
							var testObject;
							try
							{
								testObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." +  i);
							}
							catch(e)
							{
								continue;
							}
							return i;
	   					}
					}
					return 0;
				}
			}
		}
	});
	attachEvent(document, "layouterror", function(errors) {
		var msg = "";
		foreach(errors, function(error) {
			msg = "\n\t" + error.name + ": " + error.message;
		});
		alert("errors occured:" + msg);
	});	
	function hideChildren(oElm) {
		foreach(map(arrChildren), function(oChildren) {
			oChildren.className = oChildren.className.replace("l-show", "l-hide");
			oChildren.parentNode.style.position = "static";
		});
		return(true);
	}
	function addController(oElm) {
		var oController = document.createElement("div");
		oController.className = "l-controller";
		oController.innerHTML = "V";
		tilt.attachEvent(oController, "click", controllerClick);
		oElm.appendChild(oController);
		return oController;
	}
	function addEmptyController(oElm) {
		var oController = document.createElement("div");
		oController.className = "l-empty-controller";
		oController.innerHTML = "V";
		oElm.appendChild(oController);
		return oController;
	}
	function controllerClick(oElm) {
		foreach(map(arrChildren), function(oChildren) {
			oChildren.className = oChildren.className.replace("l-show", "l-hide");
		});
		var oChildren = first(getElements(oElm.parentNode, "div", "children"));
		if (oChildren) {
			if (oChildren.className.indexOf("show") >= 0) {
				oChildren.className = oChildren.className.replace("l-show", "l-hide");
			} else if (oChildren.className.indexOf("hide") >= 0) {
				oChildren.className = oChildren.className.replace("l-hide", "l-show");
				oChildren.parentNode.style.position = "relative";
			} else {
				oChildren.className = oChildren.className + " l-show";
				oChildren.parentNode.style.position = "relative";
			}
		}
	}		
	function toggleSection(oElm) {
		if (oElm) {
			var oLinks = first(getElements(oElm, "div", "links"));
			if (oLinks) {
				if (oLinks.className) {
					if (oLinks.className.indexOf("show") >= 0) {
						oLinks.className = oLinks.className.replace("l-show", "l-hide");
					} else if (oLinks.className.indexOf("hide") >= 0) {
						oLinks.className = oLinks.className.replace("l-hide", "l-show");
					} else {
						oLinks.className = oLinks.className + " l-show";
					}
				} else {
					oLinks.className = "l-show";
				}
			}
		}
	}		
	function getElements(oElm, strTagName, strClassName) {
		var oElement;
		var arrReturnElements = [ ];
		if (oElm) {
			var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
			for(var i=0;i<arrElements.length;i++) {
				oElement = arrElements[i];
				if (oElement.className) {
					var oClasses = oElement.className.split(" ");
					var bolFound = false;
					var intXX = 0;
					while (!bolFound && (intXX < oClasses.length)) {
						if (oClasses[intXX] == strClassName) {
							bolFound = true;
						} else {
							++intXX;
						}
					}
					if (!bolFound) {
						if (strClassName == "*") {
							bolFound = true;
						}
					}
				} else {
					if (strClassName == "*") {
						bolFound = true;
					}
				}
				if (bolFound) {
					arrReturnElements.push(oElement);
				}
			}
		}
		return (arrReturnElements)
	}	
}
