function initResize() {
	if (iframeHeight && iframeHeight > 0) {
		YAHOO.util.Dom.setStyle("icontent", "height", iframeHeight + "px");
	} else {
		resizeIframe();
		YAHOO.util.Event.addListener(window, "resize", resizeIframe);
	}
}
function resizeIframe() {
	var currHeight = YAHOO.util.Dom.getViewportHeight();
	var footerHeight = 63;
	var iframeTop = YAHOO.util.Dom.getY("icontent");
	YAHOO.util.Dom.setStyle("icontent", "height", (currHeight - iframeTop - footerHeight) + "px");
}

var iframeMgr = {
	currUrl: "",
	currTitle: "",
	originalUrl: "",
	originalTitle: "",
	timer:null,
	start: function() {
		iframeMgr.originalUrl = iframeMgr.getOriginalUrl();
		iframeMgr.originalTitle = iframeMgr.getOriginalTitle();
		// determine if the user put in a url with a hash that has
		// a second url in it, if so reset the iframe's src attribute
		iframeMgr.processHashRedirect();
		// let's grab the current URL info
		try {
			iframeMgr.currUrl = iframeMgr.getCurrUrl();
		} catch (e) {
			// let's do nothing this first time around, let things trickle through
		}
		timer = setInterval(iframeMgr.checkUrl, 100);
	},
	checkUrl: function() {
		try {
			var currUrl = iframeMgr.getCurrentUrl();
			if (currUrl != iframeMgr.currUrl && currUrl != "") {
				if (currUrl == iframeMgr.originalUrl) {
					// clear out the hash, it is the original page
					var cleanUrl = location.href.replace(/#.*/, "");
					if (cleanUrl != location && cleanUrl != "#undefined") {
						location.replace(cleanUrl);
					}
				} else {
					if ("#" + currUrl != "#undefined") {
						// new location, update accordingly
						location.replace("#" + currUrl);
					}
				}
				iframeMgr.currUrl = currUrl;
			}
			iframeMgr.updateTitle();
		} catch (e) {
			// going to a different domain site, let's just move along
			// in hopes that they eventually return to the same domain,
			// but if not, no big deal, only checking 10 times per second.
		}
	},
	/**
	 * this gets the value from the iframe's src attribute
	 **/
	getOriginalUrl: function() {
		var origUrl = document.getElementById("icontent").src;
		if (origUrl == location) {
			// firefox bug: reports parent URL when no src is set on iframe
			origUrl = "";
		}
		return origUrl;
	},
	/**
	* this gets the value from the #iframe_title <h1> tag if any
	**/
	getOriginalTitle: function() {
		if (document.getElementById("iframe_title")) {
			return document.getElementById("iframe_title").innerHTML;
		}
		return "";
	},
	/**
	* this attempts to get the value from the iframe's document.location
	**/
	getCurrentUrl: function() {
		var currUrl = window.frames[0].location.href;
		if (currUrl == "about:blank") {
			currUrl = "";
		}
		return currUrl;
	},
	updateTitle: function() {
		var titleHtml = document.getElementById("iframe_title");
		var newTitle = window.frames[0].document.title;
		if (newTitle != "" && document.title != newTitle) {
			// change the title of the page
			document.title = newTitle;
			if (titleHtml) {
				titleHtml.innerHTML = newTitle;
			}
		}
	},
	processHashRedirect: function() {
		var hashUrl = location.hash.replace(/#/, "");
		if (hashUrl != "") {
			// go ahead and reset the src of the iframe
			document.getElementById("icontent").src = hashUrl;
		}
	}
}


YAHOO.util.Event.addListener(window, "load", iframeMgr.start);
YAHOO.util.Event.addListener(window, "load", initResize);