tilt.attachEvent(document, "layout", function() {
	var form = document.getElementById("form");
	var audiences;

	if (form) {
		var areas = objectize(
			[
				"titling",
				"feeds",
				"content",
				"extensions",
				"navigation",
				"siteSections",
				"siteTools",
				"search",
				"policyLinks",
				"siteContactInfo",
				"pageContactInfo",
				"login",
				"properties"
			]
		);
		
		var feeds = distribute(areas.feeds, 
			[
				"events",		// upcomingEvents
				"promo-1",		// recent posts
				"promo-2",		// campusNews
				"promo-3",		// featuredMajor
				"highlights",	// highlights
				"quick-links",
				"headlines",
				"subsections",
				"features",
				"related"		// siteFeatures & seeAlso
			], "related"
		);
			
		var safari = document.childNodes && !document.all && !navigator.taintEnabled;
		if (safari) {
			document.body.className = document.body.className + " l-safari"
		}

		// break down the titles
		var oSiteTitle = [];
		var oPageTitle;
		var oSectionTitle = [];
		var oOtherTitle = [];
		var oSiteImage = [];
		var oSectionImage = [];
		var oPageImage;
		var oOtherImage = [];
		foreach(areas["titling"], function(child) {
			var className = child.className;
			if (child.getElementsByTagName("img").Length > 0) {
				if (className.indexOf("page") >= 0) {
					oPageImage = child;
				} else if (className.indexOf("Site") >= 0) {
					oSiteImage.push(child);
				} else if (className.indexOf("Section") >= 0) {
					oSectionImage.push(child);
				} else {
					oOtherImage.push(child);
				}
			} else {
				if (className.indexOf("page") >= 0) {
					oPageTitle = child;
				} else if (className.indexOf("Site") >= 0) {
					var oImg = first(child.getElementsByTagName("img"));
					if (oImg) {
						oImg.className = "l-site";
					}
					oSiteTitle.push(child);
				} else if (className.indexOf("Section") >= 0) {
					oSectionTitle.push(child);
				} else {
					oOtherTitle.push(child);
				}
			}
		});
		
		///////////////////////////////////////////////////////////////////////
		// format site-search area
		///////////////////////////////////////////////////////////////////////
		if (areas["search"]) {
			var inputs = areas["search"].getElementsByTagName("input");
			searchBox = first(inputs);
			if (searchBox) {
				var defaultValue = "   Search";
				var defaultClassName = searchBox.className;
				searchBox.value = defaultValue;
				tilt.attachEvent(searchBox, "focus", function(box) {
					if (searchBox.value == defaultValue) {
						searchBox.value = "";
						searchBox.className = defaultClassName + " active";
					}
				});
				tilt.attachEvent(searchBox, "blur", function(box) {
					if (searchBox.value.length === 0) {
						searchBox.value = defaultValue;
						searchBox.className = defaultClassName;
					}
				});
				// modify search box for Safari
				if (safari) {
					searchBox.type = "search";
				}
			}
			searchSubmit = inputs[1];
			if (searchSubmit) {
				searchSubmit.value = "";
				if (safari) {
					searchSubmit.type = "image";
				}
			}
			while (areas["search"].hasChildNodes()) areas["search"].removeChild(areas["search"].firstChild);
			var oNewDiv = document.createElement("div");
			oNewDiv.className = "l-input-label";
			areas["search"].appendChild(oNewDiv);
			areas["search"].appendChild(searchBox);
			areas["search"].appendChild(searchSubmit);
		}
		
		/////////////////////////////////////////////////////////////
		// get the breadcrumb and adjust navigation
		/////////////////////////////////////////////////////////////
		var oNewNavList = null;
		var oBreadcrumb = null;
		var oNav = document.getElementById("navigation");
		if ((oNav) && first(getElements(areas["navigation"], "li", "ancestor"))) {
			oBreadcrumb = document.createElement("div");
			oBreadcrumb.className = "breadcrumb";
			var oCurrent = first(getElements(oNav, "li", "current"));
			if (oCurrent) {
				oNewNavList = first(getElements(oCurrent, "ul", "*"));
				oCurrent.parentNode.removeChild(oCurrent);
				var oList = document.createElement("ol");
				var bolFirstLink = "true";
				foreach (map(getElements(oNav, "li", "ancestor")), function(oAncestor) {
					var oLink = first(oAncestor.getElementsByTagName("a"));
					var oLi = document.createElement("li");
					if (bolFirstLink == "true") {
						bolFirstLink = "false";
						oLi.className = "first";
						oLink.innerHTML = "Home";
					}
					oLi.appendChild(oLink.cloneNode(true));
					oList.appendChild(oLi);
				});
				if (oPageTitle) {
					var oLi = document.createElement("li");
					var oDiv = document.createElement("div");
					oDiv.innerHTML = oPageTitle.innerHTML;
					oLi.appendChild(oDiv);				
					oList.appendChild(oLi);
				}
				oBreadcrumb.appendChild(oList);
				var oSeparator = oBreadcrumb.appendChild(document.createElement("div"));
				oSeparator.className = "l-separator";
				oNav.innerHTML = "";
				if (oNewNavList) {
					oNav.appendChild(oNewNavList);
				}
			}
			classifyLastElement(oBreadcrumb, "li");
			document.body.className = document.body.className + " l-inner";
		} else {
			document.body.className = document.body.className + " l-home";
		}
		classifyLastElement(areas["siteSections"], "li");
		/*
		///////////////////////////////////////////////////////////////////////
		// check for inside capital link
		///////////////////////////////////////////////////////////////////////
		var oInsideCapital = null, oInsideCapitalDiv = null;
		if (areas.siteTools) {
			oInsideCapital = first(getElements(areas.siteTools, "a", "inside-capital"));
			if (oInsideCapital) {
				oInsideCapitalDiv = document.createElement("div");
				oInsideCapitalDiv.className = "inside-capital";
				oInsideCapitalDiv.appendChild(oInsideCapital);
			}
		}
		*/
		///////////////////////////////////////////////////////////////////////
		// check for top tab links
		///////////////////////////////////////////////////////////////////////
		var oTopTabs = [], oNewDiv = null;
		if (areas.siteTools) {
			foreach(getElements(areas.siteTools, "a", "top-tab"), function(oTabLink) {
				oNewDiv = document.createElement("div");
				oNewDiv.className = "top-tab";
				oTabLink.className = oTabLink.className.replace("top-tab","");
				oNewDiv.appendChild(oTabLink);
				oTopTabs.push(oNewDiv);
			});
		}

		///////////////////////////////////////////////////////////////////////
		// create current date div
		///////////////////////////////////////////////////////////////////////
		var oCurrentDate = null;
		if (document.body.className.indexOf("l-home") >= 0) {
			oCurrentDate = document.createElement("div");
			var oAbbrDate = document.createElement("abbr");
			oCurrentDate.className="l-current-date";
			var oNow = new Date();
			oAbbrDate.setAttribute("title", oNow);
			oAbbrDate.innerHTML = formatDate(oNow, 'MMM d, y');
			oCurrentDate.appendChild(oAbbrDate);
		}
		
		///////////////////////////////////////////////////////////////////////
		// create spacer div
		///////////////////////////////////////////////////////////////////////
		var oSpacerDiv = null;
		if (document.body.className.indexOf("l-inner") >= 0) {
			oSpacerDiv = document.createElement("div");
			oSpacerDiv.className="l-spacer";
		}
		
		///////////////////////////////////////////////////////////////////////
		// build the layout
		///////////////////////////////////////////////////////////////////////
		form.appendChild(tilt.createTable({
			"l-top-tabs-row": {
				"l-top-tabs-cell": [
					oTopTabs
				]
			},
			"l-header-search-row": {
				"l-header-search-cell": [
					tilt.createTable({
						"l-header-search-inner-row": {
							"l-header-cell": [
								oSiteTitle,
								oSiteImage,
								oSectionTitle,
								oSectionImage,
								oOtherTitle,
								oOtherImage
							],
							"l-search-tools-cell": [
								tilt.createTable({
									"l-tools-row": {
										"l-tools-cell": [
											areas["siteTools"],
										]
									},
									"l-search-row": {
										"l-placeholder-cell": [
											addPlaceholder("l-placeholder")
										],
										"l-search-cell": [
											areas["search"]
										]
									}
								}, "l-search-tools-table")
							]
						}
					}, "l-header-search-inner-table")
				]
			},
			"l-siteSections-row": {
				"l-siteSections-cell": [ 
					htabulate(areas.siteSections)
				]
			},
			"l-breadcrumb-row": {
				"l-breadcrumb-cell": [
					oBreadcrumb
				]
			},
			"l-middle-row": {
				"l-middle-cell": [
					tilt.createTable({
						"l-middle-table-row": {
							"l-middle-left-cell": [
								(hasList(first(feeds["subsections"])) ? feeds["subsections"] : null),
								feeds["highlights"],
								feeds["quick-links"],
								areas.pageContactInfo
							],
							"l-middle-middle-cell": [
								oSpacerDiv,
								feeds["headlines"],
								oPageTitle,
								oPageImage,
								areas["content"],
								areas["extensions"]
							],
							"l-middle-right-cell": [
								oCurrentDate,
								feeds["related"],
								feeds["features"]
							]
						}
					}, "l-middle-table")
				]
			},
			"l-promo-row": {
				"l-promo-1-cell": [
					feeds["promo-1"]
				],
				"l-promo-2-cell": [
					feeds["promo-2"]
				],
				"l-promo-3-cell": [
					feeds["promo-3"]
				]
			},
			"l-site-contact-row": {
				"l-site-contact-cell": [
					areas["siteContactInfo"]
				]
			},
			"l-policyLinks-row": {
				"l-policyLinks-cell": [
					areas["policyLinks"]
				]
			}
		} , "l-main"));
		
		
		///////////////////////////////////////////////////////////////////////
		// create authoring UI
		///////////////////////////////////////////////////////////////////////
		createAdminUI();		
		
		///////////////////////////////////////////////////////////////////////
		//*******************************************************************//
		// this is a hack to pluck out the logo from the spotlight images
		//*******************************************************************//
		///////////////////////////////////////////////////////////////////////
		if (feeds["promo-1"]) {
			var oImgs = first(feeds["promo-1"]).getElementsByTagName("img");
			if (oImgs && oImgs.length > 1) {
				var oImg = first(oImgs);
				if (oImg) {
					oImg.parentNode.removeChild(oImg);
				}
			}
		}
		if (feeds["promo-2"]) {
			var oImgs = first(feeds["promo-2"]).getElementsByTagName("img");
			if (oImgs && oImgs.length > 1) {
				var oImg = first(oImgs);
				if (oImg) {
					oImg.parentNode.removeChild(oImg);
				}
			}
		}
		if (feeds["promo-3"]) {
			var oImgs = first(feeds["promo-3"]).getElementsByTagName("img");
			if (oImgs && oImgs.length > 1) {
				var oImg = first(oImgs);
				if (oImg) {
					oImg.parentNode.removeChild(oImg);
				}
			}
		}
		///////////////////////////////////////////////////////////////////////
		//*******************************************************************//
		// end hack
		//*******************************************************************//
		///////////////////////////////////////////////////////////////////////
	
		///////////////////////////////////////////////////////////////////////
		// process promo-1, promo-2 and promo-3, features
		///////////////////////////////////////////////////////////////////////
		processPromo(feeds["promo-1"]);
		processPromo(feeds["promo-2"]);
		processPromo(feeds["promo-3"]);
		processPromo(feeds["features"]);
		processPromo(feeds["headlines"]);
	
		/* add rss link under promo-1 */
		var oPromo1 = first(getElements(document,"td","l-promo-1-cell"));
		if (oPromo1) {
			var oNewRss = document.createElement("div");
			oNewRss.className = "l-promo-rss";
			var oNewRssLink = oNewRss.appendChild(document.createElement("a"));
			if (oNewRssLink) {
				oNewRssLink.href = "604.rss";
				oNewRssLink.innerHTML = "RSS";
				oNewRssLink.className = "rss";
				oPromo1.appendChild(oNewRss);
			}
		}
		var oSpotlightHolders = getElements(document, "div", "l-spotlights");
		if (oSpotlightHolders && oSpotlightHolders.length <= 0) {
			oSpotlightHolders = null;
		} else {
			var intIdx = 0;
			foreach(oSpotlightHolders, function(oSpotlightHolder) {
				var oSpotlights = getElements(oSpotlightHolder, "*", "spotlight");
				if (oSpotlights && (oSpotlights.length > 0)) {
					var oCurSpotlight;
					foreach(oSpotlights, function(oSpotlight) {				
						oSpotlight.parentNode.className = oSpotlight.parentNode.className + " l-hide-spotlight";
						oCurSpotlight = oSpotlight;
					});
				}
				if (oSpotlights.length > 1) {
					var intTimeout = 60000 + (Math.floor(Math.random() * 10) + 1) * 1000;
					showSpotlight(intIdx);
					setSpotlightTimeout(intIdx++, intTimeout);
				} if (oSpotlights.length == 1) {
					oSpotlights[0].parentNode.className = oSpotlights[0].parentNode.className.replace("l-hide-spotlight", "l-show-spotlight");	
				}
			});
		}
		

		///////////////////////////////////////////////////////////////////////
		// build the quick links drop down
		///////////////////////////////////////////////////////////////////////
		if (feeds["quick-links"]) {
			var oNewQuicklinks = buildQuickLinks(feeds["quick-links"]);
			if (oNewQuicklinks) {
				if (areas.pageContactInfo) {
					areas.pageContactInfo.parentNode.insertBefore(oNewQuicklinks,areas.pageContactInfo);
				} else {
					var oTd = first(getElements(document, "td", "l-middle-left-cell"));
					if (oTd) {
						oTd.appendChild(oNewQuicklinks);
					}
				}
				audiences = oNewQuicklinks.getElementsByTagName("h3");
			}
		}
		
		///////////////////////////////////////////////////////////////////////
		// 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
		///////////////////////////////////////////////////////////////////////
		if (areas.content) {
			if (foreach(areas.content.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");	
		}
		
		///////////////////////////////////////////////////////////////////////
		// mark first li as "first"
		///////////////////////////////////////////////////////////////////////
		foreach(form.getElementsByTagName("ul"), function(ul) {
			var items = ul.getElementsByTagName("li");
			if (items.length > 0) {
				var li = items[0];
				li.className = li.className + " first";
			}
		});
		if (areas.navigation) {
			if (!hasList(areas.navigation)) {
				areas.navigation.parentNode.removeChild(areas.navigation);
			}
		}
		if (areas.feeds) {
			if (!first(getElements(areas.feeds, "div", "feed"))) {
				areas.feeds.parentNode.removeChild(areas.feeds);
			}
		}
		if (areas.titling) {
			if (!first(getElements(areas.titling, "a", "*"))) {
				areas.titling.parentNode.removeChild(areas.titling);
			} else if (!first(getElements(areas.titling, "div", "*"))) {
				areas.titling.parentNode.removeChild(areas.titling);
			}
		}
		
		////////////////////////////////////////////////////////////////////
		// This code sets all text input elements in an ancestor element
		// with a single submit input to post when enter is hit while in the
		// text field
		////////////////////////////////////////////////////////////////////    
	    var oInputSubmits = getElementsByType(document, "input", "submit");
	    var iIdx = 0;
	    foreach (map(oInputSubmits), function(oInputSubmit) {
		    var oAncestorNode = null;
		    oCurrentNode = oInputSubmit.parentNode;
		    while (oAncestorNode == null && oCurrentNode != document) {
			    var oInputTextFields = getElementsByType(oCurrentNode, "input", "text");
			    if (oInputTextFields && oInputTextFields.length > 0) {
				    oAncestorNode = oCurrentNode;
			    } else {
				    oCurrentNode = oCurrentNode.parentNode;
			    }
		    }
		    if (oAncestorNode) {
			    var oSubmitCheck = getElementsByType(oAncestorNode, "input", "submit");
			    if (oSubmitCheck && oSubmitCheck.length == 1) {
				    if (oInputSubmit.id == "") {
					    oInputSubmit.id = oInputSubmit.name;
				    }
				    foreach (map(oAncestorNode.getElementsByTagName("input")), function (oInput) {
					    if (oInput.type == "text" || oInput.type == "password") {
						    oInput.setAttribute("submitId", oInputSubmit.id);
				            tilt.attachEvent(oInput, "keydown", function(oNode, oE) {
				                if (oE.keyCode == 13) {
					                var oSubmitId = oNode.getAttribute("submitId");
                   					window.setTimeout("var oSubmit = document.getElementById(\"" + oSubmitId + "\");oSubmit.focus();oSubmit.click()", 0);
				                    return false;
				                }
				                return true;
				            });
					    }
				    });
                    iIdx++;
			    }
		    }
		    
			(function() {
		
				var plugins = navigator.plugins && navigator.plugins.length;
				var ie = [ "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' width='", 1, "' height='", 3 ,"'><param name='src' value='", 5, "' /><param name='autoplay' value='true' /><param name='controller' value='true' /></object>" ];
				var other = [ "<embed width='", 1, "' height='", 3, "' src='", 5, "' controller='true' autoplay='true' type='video/quicktime' pluginspage='http://www.apple.com/quicktime/download/'></embed>" ];
				
				if (detect()) {
					foreach(filter(document.getElementsByTagName("A"), function(a) {
						return a.type == "video/quicktime";
					}), function(a) {
						var parent = a.parentNode;
						var div = parent.insertBefore(document.createElement("div"), a);
						var img = first(a.getElementsByTagName("img"));
						var frame = plugins ? other : ie;
						frame[1] = (img && img.width) || div.offsetWidth;
						frame[3] = (img && img.height) || 500;
						frame[5] = a.href;
						parent.removeChild(a);
						div.innerHTML = frame.join("");
					});
				}
			
				function detect() {
					if (plugins) {
						for (var i = 0; i < navigator.plugins.length; i++ ) {
						 var plugin = navigator.plugins[i];
						 if (plugin.name.indexOf("QuickTime") > -1) {
							return true;
						 }
					  }
					} else {
						return true;
					}
					return false;
				}
		
			})();		    
		    
	    });
	}	
	
	///////////////////////////////////////////////////////////////////////
	// process elements of the promo content areas
	///////////////////////////////////////////////////////////////////////
	function processPromo(oPromoFeed) {
		var oPromoBox;
		oPromoBox = null;
		foreach(map(oPromoFeed), function(oPromo) {
			if (oPromoBox == null) {
				oPromoBox = oPromo;
			}
			// set the text for date fields
			foreach(map(getElements(oPromo, "abbr", "date")), function(oDate) {
				if (oDate) {
					oDate.parentNode.className = "l-relative-date";
					oDate.parentNode.innerHTML = setDateText(oDate);
				}
			});
			// clip the abstract to 200 characters
			foreach(map(getElements(oPromo, "p", "abstract")), function(oAbstract) {
				if (oAbstract) {
					var strAbstract = oAbstract.innerHTML;
					if (strAbstract.length > 200) {
						strAbstract = trim(strAbstract.substring(0,200));
						if (strAbstract.substring(strAbstract.length-3) != "...") {
							if (strAbstract.substring(strAbstract.length-2) != "..") {
								if (strAbstract.substring(strAbstract.length-1) != ".") {
									oAbstract.innerHTML = strAbstract + "...";
								} else {
									oAbstract.innerHTML = strAbstract + "..";
								}
							} else {
								oAbstract.innerHTML = strAbstract + ".";
							}
						} else {
							oAbstract.innerHTML = strAbstract;
						}
					}
				}
			});
			var bolHasSpotlight = false;
			// change a img.spotlight to a link with a background image
			foreach(map(getElements(oPromo, "img", "spotlight")), function(oImg) {
				bolHasSpotlight = true;
				var oTitle = first(oImg.parentNode.getElementsByTagName("a"));
				if (oTitle) {
					var oNewA = document.createElement("a");
					oNewA.className = "spotlight";
					oNewA.href = oTitle.href;
					//oNewA.style.display = "block";
					oNewA.style.backgroundImage = "url(" + oImg.src + ")";
					oImg.parentNode.insertBefore(oNewA, oImg);
					oImg.parentNode.removeChild(oImg);
				}
			});
			foreach(map(getElements(oPromo, "img", "thumbnail")), function(oImg) {
				var oTitle = first(oImg.parentNode.getElementsByTagName("a"));
				if (oTitle) {
					var oNewA = document.createElement("a");
					oNewA.className = "thumbnail";
					oNewA.href = oTitle.href;
					oNewA.style.display = "block";
					oNewA.style.backgroundImage = "url(" + oImg.src + ")";
					oImg.parentNode.insertBefore(oNewA, oImg);
					oImg.parentNode.removeChild(oImg);
				}
			});
			foreach(map(getElements(oPromo, "div", "author")), function(oAuthor) {
				oAuthor.innerHTML = "by " + oAuthor.innerHTML;
			});
			if (oPromoBox != oPromo) {
				var oUl = first(oPromoBox.getElementsByTagName("ul"));
				if (oUl) {
					foreach(map(oPromo.getElementsByTagName("li")), function(oPostFeed) {
						oUl.appendChild(oPostFeed);
					});
				}
				oPromo.parentNode.removeChild(oPromo);
			}
			if (bolHasSpotlight) {
				oPromoBox.className = oPromoBox.className + " l-spotlights";
			}
		});
	}
	function createAdminUI() {
        var form = document.getElementById("form");
        var authoring = document.body.insertBefore(document.createElement("form"), document.body.firstChild);
        authoring.method = form.method;
        authoring.action = form.action;
        authoring.id = "l-authoring";
	    var trigger = authoring.appendChild(document.createElement("a"));
	    trigger.href = "admin";
	    trigger.className = "l-trigger";
	    tilt.attachEvent(trigger, "click", function(a) {
		    var currentClassName = a.parentNode.className;
		    if (currentClassName.indexOf("l-admin-open") >= 0) {
			    a.innerHTML = "Authoring";
			    a.parentNode.className = "l-admin-closed";
			    document.cookie = "keep-authoring-open=false";
		    }
		    else {
			    a.innerHTML = "Close";
			    a.parentNode.className = "l-admin-open";
			    document.cookie = "keep-authoring-open=true";
		    }
		    return false;
	    });
	    var properties = document.getElementById("properties");
	    if (properties) {
	        authoring.appendChild(properties);
		    foreach(properties.getElementsByTagName("input"), function(input) {
		        if (input.type == "text") {
		            tilt.attachEvent(input, "keydown", function(node, e) {
		                if (e.keyCode == 13) {
	                        window.setTimeout("document.getElementById(window.__authoringPropertiesApplyId).click()", 0);
	                        return false;
		                }
		                return true;
		            });
		        }
		        else {
		            window.__authoringPropertiesApplyId = input.id;
		        }
		    });
		    var pid;
		    foreach(properties.getElementsByTagName("a"), function(a) {
		        if (a.className == "admin") {
		            var href = a.href;
		            var pos = href.indexOf("durki=");
		            if (pos >= 0) {
		                pid = href.substring(pos + 6);
		            }
		        }
		    });
		    if (pid) {
		        var div = properties.appendChild(document.createElement("div")); 
		        div.className = "l-pid";
		        div.innerHTML = "page id: " + pid;
		    }
	    }
	    var isOpen = document.cookie.indexOf("keep-authoring-open=true") >= 0 || properties;
	    if (isOpen) {
	        authoring.className = "l-admin-open";
		    trigger.innerHTML = "Close";
	    }
	    else {
	        authoring.className = "l-admin-closed";
		    trigger.innerHTML = "Authoring";
	    }
	    var login = authoring.appendChild(document.getElementById("login"));
	    foreach(login.getElementsByTagName("input"), function(input) {
	        if (input.type == "text") {
	            tilt.attachEvent(input, "keydown", function(node, e) {
	                if (e.keyCode == 13) {
                        window.setTimeout("document.getElementById(window.__authoringLoginId).click()", 0);
                        return false;
	                }
	                return true;
	            });
	        }
	        else {
	            window.__authoringLoginId = input.id;
	        }
	    });
	    foreach(authoring.getElementsByTagName("legend"), function(legend) {
	        var value = legend.innerHTML;
	        var parent = legend.parentNode;
	        var div = parent.insertBefore(document.createElement("div"), legend);
	        div.className = "l-legend";
	        div.innerHTML = value;
	        parent.removeChild(legend);
	    });
	    foreach(authoring.getElementsByTagName("fieldset"), function(fieldset) {
	        var parent = fieldset.parentNode;
	        var div = parent.insertBefore(document.createElement("div"), fieldset);
	        div.innerHTML = fieldset.innerHTML;
	        parent.removeChild(fieldset);
	    });
    }	
   	////////////////////////////////////////////////////////////////////
	// set the date text to an english relative statement
	////////////////////////////////////////////////////////////////////
	function setDateText(oDate) {
		var strDateText = "";
		if (oDate) {
			var strDate = oDate.getAttribute("title");
			strDateText = strDate;
			if (strDate) {
				var oToday = new Date();
				var oPostDate = new Date(strDate);
				var intDiff = (oToday - oPostDate) / 1000;
				if (intDiff < 60) {
					strDateText = "few seconds ago";
				} else if (intDiff < 120) {
					strDateText = "a minute ago";
				} else if (intDiff < 3600) {
	 				strDateText = Math.floor(intDiff/60) + " minutes ago";
				} else if (intDiff < 7200) {
	 				strDateText = "an hour ago";
				} else if (intDiff < 86400) {
	 				strDateText = Math.floor(intDiff/3600) + " hours ago";
				} else if (intDiff < 172800) {
	 				strDateText = "yesterday";
				} else if (intDiff <= 2592000) {
	 				strDateText = Math.floor(intDiff/86400) + " days ago";
				} else if (intDiff > 2592000) {
	 				strDateText = "over a month ago";
				}
			} else {
				strDateText = oDate.innerHTML;
			}
		}
		return strDateText;
	}
	function addPlaceholder(oName) {
		var oPlaceholder = document.createElement("div");
		oPlaceholder.className = oName;
		return oPlaceholder;
	}
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	////////////////////////////////////////////////////////////////////
	// This function is being reused from the Capital 1.0 project.
	////////////////////////////////////////////////////////////////////
	function buildQuickLinks(quickLinks)
	{
		var oNewOuterDiv = document.createElement("div");
		oNewOuterDiv.className = "l-quick-links";
		
		var topEdgeDiv = oNewOuterDiv.appendChild(document.createElement("div"));
		topEdgeDiv.className = "TopEdge";
		var topRightCornerDiv = topEdgeDiv.appendChild(document.createElement("div"));
		topRightCornerDiv.className = "TopRightCorner";
		var oHeader = oNewOuterDiv.appendChild(document.createElement("h4"));
		oHeader.innerHTML = "Quick Links For ...";

		foreach(map(quickLinks), function(oFeed) {
			oNewOuterDiv.appendChild(oFeed);
		});
		
		var bottomEdgeDiv = oNewOuterDiv.appendChild(document.createElement("div"));
		bottomEdgeDiv.className = "BottomEdge";
		var bottomRightCornerDiv = bottomEdgeDiv.appendChild(document.createElement("div"));
		bottomRightCornerDiv.className = "BottomRightCorner";
		
		audiences = oNewOuterDiv.getElementsByTagName("h3");
		var selectorDiv = oNewOuterDiv.insertBefore(document.createElement("div"), oHeader.nextSibling);
		selectorDiv.className = "AudienceSelector";
		var selector = selectorDiv.appendChild(document.createElement("select"));
		var cookieSelection = getCookieSelection();		
		for(var i = 0; i < audiences.length; i++)
		{
			var audienceTitle = audiences[i];
			var option = selector.appendChild(document.createElement("option"));
			if (cookieSelection < 0)
			{
				if (audienceTitle.className == "Default")
				{
					option.selected = true;				
				}
			}
			else
			{
				if (cookieSelection == i)
				{
					option.selected = true;
				}				
			}
			option.appendChild(document.createTextNode(getInnerText(audienceTitle)));
		}
		selectAudience();
	
		tilt.attachEvent(selector, "change", function() {
			selectAudience();
			setCookieSelection();
		});
		
		return oNewOuterDiv;
		
		function getCookieSelection()
		{
			var cookies = document.cookie.split(";");
			for(var i = 0; i < cookies.length; i++)
			{
				var cookie = cookies[i];
				var nvp = cookie.split("=");
				if (nvp[0] == "audienceSelection")
				{
					return parseInt(nvp[1], 10);
				}
			}
			return -1;
		}
		
		function setCookieSelection()
		{
			document.cookie = "audienceSelection=" + selector.selectedIndex;		
		}
		
		function selectAudience()
		{
			var index = selector.selectedIndex;
			for(var i = 0; i < audiences.length; i++)
			{
				var audience = audiences[i].parentNode;
				if (index != i)
				{
					audience.style.display = "none";
				}
				else
				{
					audience.style.display = "block";
				}
			}
		}
	}
	function distribute(col, classNames, defaultClassName) {
		var result = {};
		foreach(col, function(node) {
			push(getClassName());
			
			function push(className) {
				var items = result[className];
				if (!items) {
					items = [];
					result[className] = items;
				}
				items.push(node);
			}
			
			function getClassName() {
				var result = defaultClassName;
				foreach(classNames, function(className) {
					if (foreach(node.className.split(" "), function(nodeClassName) {
						return nodeClassName == className;
					})) {
						result = className;
						return true;
					}
				});
				return result;
			}

		});
		return result;
	}
	
	function hasList(oElm) {
		var rv = false;
		if (first(getElements(oElm, "li", "*"))) {
			rv = true;
		}
		return rv;
	}
	function htabulate(o) {
		var cells = {};
		foreach(o.getElementsByTagName("li"), function(li, i) {
			cells["l-cell-" + i] = first(li);
		});
		if (cells) {
			var firstChild = o.firstChild;
			var child = o.firstChild;
			while(child) {
				o.removeChild(child);
				child = o.firstChild;
			}
			o.appendChild(tilt.createTable({ "l-htable" : cells }, "l-htable"), o.firstChild);
		}
		return o;
	}
	
	function getInnerText(node)
	{
		var text = node.innerText;
		if (!text)
		{
			text = "";
			var childNode = node.firstChild;
			while(childNode)
			{
				if (childNode)
				{
					text += childNode.nodeType == 3 ? childNode.nodeValue : getInnerText(childNode);
				}
				childNode = childNode.nextSibling;
			}
		}
		return text;
	}
	
	function objectize(arrayOfIds)	{
		var result = {};
		foreach(arrayOfIds, function(item) {
			var o = document.getElementById(item);
			if (o) {
				result[item] = o;
			}
			else {
				result.complete = true;
			}
		})
		result.complete = !result.complete;
		result.contains = function(matches) {
			return foreach(matches, function(match) {
				if (result[match]) {
					return true;
				}
			});
		}
		return result;
	}

	function classifyLastElement(oElm, strTagname)
	{
		if (oElm) {
			var arrItems = oElm.getElementsByTagName(strTagname);
			if (arrItems && arrItems.length > 0)
			{
				arrItems[arrItems.length - 1].className = arrItems[arrItems.length - 1].className + " l-last";
			}
		}
	}
	
	var listnum = 0;
	function numberLists(node) {
		var inum = 0;
		var nodes = node.childNodes;
		if (nodes) {
			var length = nodes.length;
			for (var idx = 0; idx < length; ++idx) {
				if (nodes[idx].tagName) {
					switch (nodes[idx].tagName.toLowerCase()) {
						case "ul":
							nodes[idx].className = nodes[idx].className + " l" + listnum++; 
							numberLists(nodes[idx]);
							break;
						case "li":
							nodes[idx].className = nodes[idx].className + " i" + inum++;
							numberLists(nodes[idx]);
							break;
					}
				}
			}
		}
	}
	
	////////////////////////////////////////////////////////////////////////////
	// This function uses the same 'format' strings as the 
	// java.text.SimpleDateFormat class, with minor exceptions.
	// The format string consists of the following abbreviations:
	// 
	// Field        | Full Form          | Short Form
	// -------------+--------------------+-----------------------
	// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
	// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
	//              | NNN (abbr.)        |
	// Day of Month | dd (2 digits)      | d (1 or 2 digits)
	// Day of Week  | EE (name)          | E (abbr)
	// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
	// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
	// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
	// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
	// Minute       | mm (2 digits)      | m (1 or 2 digits)
	// Second       | ss (2 digits)      | s (1 or 2 digits)
	// AM/PM        | a                  |
	//
	// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
	// Examples:
	//  "MMM d, y" matches: January 01, 2000
	//                      Dec 1, 1900
	//                      Nov 20, 00
	//  "M/d/yy"   matches: 01/20/00
	//                      9/2/00
	//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
	// ------------------------------------------------------------------
	// formatDate (date_object, format)
	// Returns a date in the output format specified.
	/////////////////////////////////////////////////////////////////////////////
	function formatDate(date,format) {
		var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
		function LZ(x) {return(x<0||x>9?"":"0")+x}
		format=format+"";
		var result="";
		var i_format=0;
		var c="";
		var token="";
		var y=date.getYear()+"";
		var M=date.getMonth()+1;
		var d=date.getDate();
		var E=date.getDay();
		var H=date.getHours();
		var m=date.getMinutes();
		var s=date.getSeconds();
		var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
		// Convert real date parts into formatted versions
		var value=new Object();
		if (y.length < 4) {y=""+(y-0+1900);}
		value["y"]=""+y;
		value["yyyy"]=y;
		value["yy"]=y.substring(2,4);
		value["M"]=M;
		value["MM"]=LZ(M);
		value["MMM"]=MONTH_NAMES[M-1];
		value["NNN"]=MONTH_NAMES[M+11];
		value["d"]=d;
		value["dd"]=LZ(d);
		value["E"]=DAY_NAMES[E+7];
		value["EE"]=DAY_NAMES[E];
		value["H"]=H;
		value["HH"]=LZ(H);
		if (H==0){value["h"]=12;}
		else if (H>12){value["h"]=H-12;}
		else {value["h"]=H;}
		value["hh"]=LZ(value["h"]);
		if (H>11){value["K"]=H-12;} else {value["K"]=H;}
		value["k"]=H+1;
		value["KK"]=LZ(value["K"]);
		value["kk"]=LZ(value["k"]);
		if (H > 11) { value["a"]="PM"; }
		else { value["a"]="AM"; }
		value["m"]=m;
		value["mm"]=LZ(m);
		value["s"]=s;
		value["ss"]=LZ(s);
		while (i_format < format.length) {
			c=format.charAt(i_format);
			token="";
			while ((format.charAt(i_format)==c) && (i_format < format.length)) {
				token += format.charAt(i_format++);
				}
			if (value[token] != null) { result=result + value[token]; }
			else { result=result + token; }
			}
		return result;
	}
});

////////////////////////////////////////////////////////////////////
// show the next spotlight
////////////////////////////////////////////////////////////////////
function showSpotlight(intIdx) {
	var bolChanged = false;
	var oSpotlightHolders = getElements(document, "div", "l-spotlights");
	if (oSpotlightHolders) {
		var oSpotlights = getElements(oSpotlightHolders[intIdx], "*", "spotlight");
		for(var intX=0; intX < oSpotlights.length; ++intX) {
			if (oSpotlights[intX].parentNode.className.indexOf("l-show-spotlight") >= 0) {
				oSpotlights[intX].parentNode.className = oSpotlights[intX].parentNode.className.replace("l-show-spotlight", "l-hide-spotlight");
				if (++intX >= oSpotlights.length) {
					intX = 0;
				}
				oSpotlights[intX].parentNode.className = oSpotlights[intX].parentNode.className.replace("l-hide-spotlight", "l-show-spotlight");	
				intX = oSpotlights.length;
				bolChanged = true;
			}
		}
		if (!bolChanged) {
			oSpotlights[0].parentNode.className = oSpotlights[0].parentNode.className.replace("l-hide-spotlight", "l-show-spotlight");	
		}
	}
}

function setSpotlightTimeout(intIdx, intTimeout) {
	var strFunctionCall = 'showSpotlight( ' + intIdx + '); setSpotlightTimeout(' + intIdx + ', ' + intTimeout + ');';
	setTimeout(strFunctionCall, intTimeout);
}

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)
}