/* Required by a script in templates; Remove this after community launch */
var rs_memb = '';
var rs_beta = '';

/* jQuery noConflict code used with Prototype */ 
var $j = jQuery;

/* IE6 background image caching */	
try { document.execCommand ('BackgroundImageCache', false, true); } catch (e) {}

/* Set the base domain */
(function ()
{
	try
	{
		var domainSplit = document.domain.split ('.');
		document.domain = domainSplit.splice (domainSplit.length - 2, 2).join ('.');
		document.cookie = 'domain=' + document.domain;
	}
	catch (error) {}
}) ();

/* Firebug console wrapper for error-free debugging - But don't leave any $console/console calls in the code! */
var $console = {};
$console.exists = typeof console == 'object';
$console.log = function (arg0)
{
	if (this.exists)
	{
		if (typeof arguments [1] != 'undefined') { console.log (arg0, arguments [1]); }
		else { console.log (arg0); }
	}
}

/* $trc is the Real Simple namespace for global constants and static functions, which will be transferred to $RS in the future */
var $trc = 
{
	POLL_TIMEOUT : 10000,
	POLL_INTERVAL : 500,
	IS_OPERA : typeof window.opera != 'undefined',
	IS_IE : typeof document.all != 'undefined' && !this.IS_OPERA && navigator.vendor != 'KDE',
	IS_TV : new RegExp ('/television/', 'i').test (location.pathname),
	domHook: null,
	setDomHook : function () { var domHook = $ ('<div id="domHook"></div>'); domHook.appendTo ('body'); this.domHook = domHook [0]; },
	IS_RS_HOST : /realsimple\.com/i.test (location.href),
	getUrlParameter : function (key, alternateQueryString, noHash, delimiter)
	{
		delimiter = typeof delimiter == 'string' && delimiter != '' ? delimiter : '&';
		key = key.replace (/[\[]/, '\\\[').replace (/[\]]/, '\\\]');
		var regex = new RegExp ('[\\?' + delimiter + ']' + key + '=([^' + delimiter + (typeof noHash == 'boolean' && noHash ? '' : '#') + ']*)');
		var result = regex.exec (typeof alternateQueryString == 'string' && alternateQueryString.length > 0 ? '?' + alternateQueryString : location.href);
		return result == null ? '' : result [1];
	}
}
$trc.setDomHook ();
$trc.HOST_PREFIX = $trc.IS_RS_HOST ? ((/dev\./i.test (location.href) || /dev-/i.test (location.href)) ? 'dev-' : 
	((/qa\./i.test (location.href) || /qa-/i.test (location.href)) ? 'qa-' : '')) : '';
$trc.HOST_DOT_PREFIX = $trc.HOST_PREFIX == '' ? (/sitepreview\.realsimple\.com/i.test (location.href) ? 'sitepreview.' : '') : $trc.HOST_PREFIX.replace ('-', '.');
$trc.IMG_PREFIX = $trc.IS_TV ? 'tv/' : '';

/* Sets the root folder paths for static files */
	var RELATIVE_URL = '../..';
	var rsSTIRoot = RELATIVE_URL;
	var rsStaticRoot = RELATIVE_URL;
	if (/realsimple\.com/i.test (location.href))
	{
		var HOST_PREFIX = $trc.HOST_PREFIX == '' ? 'www.' : $trc.HOST_PREFIX.replace ('-', '.');
		rsSTIRoot = rsStaticRoot = 'http://' + $trc.HOST_PREFIX + 'img4.realsimple.com/static';
	}
	if (typeof rsAssignedRoot != 'undefined' && rsAssignedRoot && rsAssignedRoot != '') { rsSTIRoot = rsAssignedRoot; }
	if (typeof rsAssignedStaticRoot != 'undefined' && rsAssignedStaticRoot && rsAssignedStaticRoot != '') { rsStaticRoot = rsAssignedStaticRoot; }

/* Dynamic Script Attachment */
function rsAddScript (src) {
    var scriptToAdd = document.createElement ('script');
    scriptToAdd.type = 'text/javascript';
    scriptToAdd.src = rsSTIRoot + src;
	if (typeof $trc.head != 'object' || !$trc.head)
	{
		/* Don't use $j ('head') for the line below because the current line performs more efficiently */
		$trc.head = document.getElementsByTagName ('head').item (0);
	}
    $trc.head.appendChild (scriptToAdd);
}

/* $RS is the Real Simple namespace for global constants and static functions */ 
var $RS =
{
	getParam : function (key, queryString, delimiter) { return $trc.getUrlParameter (key, queryString, true, delimiter	); }
};
$RS.getCookie = function (key) { return this.getParam (key, document.cookie, '; ') };

/* Set community ad parameters */
$RS.setCAdParams = function (adFactory)
{
	var community_ad_cookie = decodeURIComponent (this.getCookie ('ti_community_ad'));
	var adKeys = 'comm con comm1 comm2 comm3'.split (' ');
	for (var i = 0, l = adKeys.length; i < l; i++)
	{
		var key = adKeys [i];
		adFactory.setParam (key, this.getParam (key, community_ad_cookie));
	}
};

/* These variables should normally be in global.js (which is near the end of the page), but they need to be in the <head> section early on. That's' why they're here */

/* TV flat pages flag */
var tv_hide_css = document.getElementById ('tv_hide_css');

// moved from global.js to set focus sooner
function rs_focusSearchBox ()
{
	var hdr_search_input = document.getElementById ('hdr_search_input');
	if (hdr_search_input) { hdr_search_input.focus (); }
}
tii_callFunctionOnElementLoad ('hdr_search_input', function ()
{
	if (!tv_hide_css) {rs_focusSearchBox ();}
});


/* Utilities proper */
function tii_dom_removeWhitespaceTextNodes(node) {
	for (var x = 0; x < node.childNodes.length; x++) {
		var child = node.childNodes [x];
		if (child.nodeType == 3 && !/\S/.test(child.nodeValue)) {
			node.removeChild(node.childNodes[x]);
			x--;
		}
		if (child.nodeType == 1) {
			tii_dom_removeWhitespaceTextNodes(child);
		}
	}
}

function tii_callFunctionOnElementLoad(targetId, functionToCall) {
	var myArguments = arguments;
	$j (document).ready (function () {
		window.loaded = true;
	});
	var targetElement = document.getElementById (targetId);
	if (targetElement == null && !window.loaded) {
		var pollingInterval = setInterval (function () {
			if (window.loaded) {
				clearInterval (pollingInterval);
			}
			targetElement = document.getElementById (targetId);
			if (targetElement != null) {
				clearInterval(pollingInterval);
				var argumentsTemp = new Array();
				var argumentsTempLength = myArguments.length - 2;
				for (var i = 0; i < argumentsTempLength; i++) {
					argumentsTemp[i] = myArguments[i + 2];
				}		
				functionToCall.apply(this, argumentsTemp);
			}
		}, 250); /* Used to be 10 milliseconds */
	}
}

function tii_addEventHandler(targetElement, eventType, functionToCall, bubbleEventUpDOMTree) {
	if (!targetElement) {
		window.status = 'Warning: Tried to attach event to null object';
		return false;
	}
	if (typeof targetElement.addEventListener != 'undefined') {
		targetElement.addEventListener (eventType, functionToCall, bubbleEventUpDOMTree);
	}
	else if (typeof targetElement.attachEvent != 'undefined') {
		targetElement.attachEvent ('on' + eventType, functionToCall);
	}
	else {
		eventType = 'on' + eventType;
		if (typeof targetElement [eventType] == 'function') {
			var oldListener = targetElement [eventType];
			targetElement [eventType] = function () {
				oldListener ();
				return functionToCall ();


			}
		}
		else {
			targetElement [eventType] = functionToCall;
		}
	}
	return true;
}

function tii_stopDefaultAction (event) {
	event.returnValue = false;
	if (typeof event.preventDefault != 'undefined') {
		event.preventDefault ();
	}
}

function tii_getParameter (searchName, searchString)
{
	var pairs = searchString.split (';');
	for (var i = 0; i < pairs.length; i++)
	{
		var pairCrumbs = pairs [i].split ('=');
		var pairName = pairCrumbs [0];
		pairName = pairName.replace (' ', '');
		var pairValue = pairCrumbs [1];
		if (pairName == searchName) { return pairValue; }
	}
	return false;
}

/*Sniffing*/
var ua = navigator.userAgent;
var isMac = ua.indexOf('Mac OS X') == -1 ? false : true;
var isFirefox = ua.indexOf('Firefox') == -1 ? false : true;
var isSafari = ua.indexOf('Safari') == -1 ? false : true;
if(isMac && isFirefox) {
	head = document.getElementsByTagName('head')[0];
	newStyle = document.createElement('style');
	newStyle.setAttribute('type','text/css');
	newStyle.innerHTML='.bc{background-position:right center;}';
	head.appendChild(newStyle);
}

/*Background Fader*/
function toHex(x) {
	hex = [];
	for(i=0;i<10;i++){hex[i]=i;}
	hex[10] = "a";
	hex[11] = "b";
	hex[12] = "c";
	hex[13] = "d";
	hex[14] = "e";
	hex[15] = "f";
	return ("" + hex[Math.floor(x/16)] + hex[x%16]);
}

function fader(element,f,t,time) {
	var fadeCount=1;
	var fadeInterval = setInterval(function(){
		if(fadeCount==30) {clearInterval(fadeInterval);}
		element.style.backgroundColor='#'+toHex(Math.ceil(f[0]+((t[0]-f[0])/30)*fadeCount))+toHex(Math.ceil(f[1]+((t[1]-f[1])/30)*fadeCount))+toHex(Math.ceil(f[2]+((t[2]-f[2])/30)*fadeCount));
		fadeCount++;
	},Math.floor(time/30));
}

/* Check ad popups */
TiiAdConfig.prototype.checkPopups = function () { if (!/realsimple\.com/.test (document.referrer)) { this.setPopups (false); } }

/* Temporary ad fix */
TiiAd.prototype.removePgUrl = false;

function TiiAd_getAdParams() {
	var adParams	= this._formatParams();
	var tileParam	= ";tile=" + this.tileNumber;

	var secureParam = "";
	if (TiiAd_isSecure()) {
		secureParam = ";sec=1";
	}

	var puParam = "";
	if (!this.config.popups) {
		puParam = ";pu=0";
	}

	var ordParam	= ";ord=" + this.randomNumber;
	var rhost	= document.referrer.split("/")[2];
	var rhostParam	= "";
	if (typeof(rhost) != "undefined") rhostParam	= ";rhost=" + rhost;
	var pageParam = '';
	if (!this.removePgUrl)
	{
		pageParam	= ";pgurl=" + escape(document.location);
	}
	
	return this.sitename + "/" + this.zone.toLowerCase() + adParams + pageParam + rhostParam + tileParam + puParam + secureParam + ordParam + "?";
}

/* Homepage Carousel */
var hpc = {
	flashHash : {},
	register : function (data)
	{
		this.flashHash [data.slideIndex] = data.videoIndex;
	}
};



/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^ THE CODE BELOW SHOULD ONLY BE FOR NAVIGATION ^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

/* This function sets the top nav highlight */
function rs_pnav_performTopNavHighlight ()
{
	var highlightId;
	if (typeof rs_topNavHighlightId != 'undefined' && rs_topNavHighlightId && rs_topNavHighlightId != '')
	{
		highlightId = rs_topNavHighlightId; 
	}
	else
	{
		var HOST_PREFIX = /realsimple\.com/i.test (location.href) ? ((/dev\./i.test (location.href) || /dev-/i.test (location.href)) ? 'dev-' : 
		((/qa\./i.test (location.href) || /qa-/i.test (location.href)) ? 'qa-' : '')) : '';
		
		/* Check if the URL is the RS 'television' channel; if so, display its nav; if not, display regular RS nav */
		var IS_TV = new RegExp ('/television/', 'i').test (location.pathname);
		var topNavHash;
		if (IS_TV)
		{
			topNavHash = new Array (['episode-guide', 'nav_episode_guide'], ['browse-by-topic', 'nav_browse_by_topic'], ['host-guests', 'nav_host_and_experts'], ['tools', 'nav_tools'], ['about-show', 'nav_about_the_show']);
			var navEpisode = document.getElementById ('nav_episode_guide');
			var isie6 = navigator.userAgent.indexOf ('MSIE 6.0') > -1;
			var issafari = navigator.vendor == 'Apple Computer, Inc.';
			if (navEpisode && !(isie6 || issafari)) { navEpisode.style.marginLeft = '0'; }
		}
		else
		{
			topNavHash = new Array (['beauty-fashion', 'tn_beauty'], ['food-recipes', 'tn_recipes'], ['health', 'tn_health'], ['holidays-entertaining', 'tn_holidays'], ['home-organizing', 'tn_home'], ['magazine-more', 'tn_magazine'], ['work-life', 'tn_work'], [HOST_PREFIX + 'community.realsimple.com', 'tn_my_realsimple']);
		}
		var tnhLength = topNavHash.length;
		for (var i = 0; i < tnhLength; i++)
		{
			if (new RegExp ('/' + topNavHash [i] [0] + '/', 'i').test (location.href))
			{
				highlightId = topNavHash [i] [1];
				break;
			}
		}
	}
	
	/* If the URL contains one of the top nav IDs, highlight the <li> that contains it */
	if (highlightId)
	{
		var li = document.getElementById (highlightId);
		if (li) { li.className += ' current_page'; }
	}
}	// End rs_pnav_performTopNavHighlight ()

/* Skip the enclosed code if the page is a flat TV page */
if (!tv_hide_css)
{

	/* Global dropdown menu variables */
	var tii_pnav_closeMenuDelay = 1; /* milliseconds */
	var tii_pnav_closeMenuDelayIE6 = 1; /* milliseconds */

	/* This is the core dropdown menu function */
	function tii_pnav_initializeDropdownMenu (primaryNavId, hideOrShowMenuFunction, changeStateFunction)
	{
		var isopera = typeof window.opera != 'undefined';
		var isie = typeof document.all != 'undefined'
			&& !isopera && navigator.vendor != 'KDE';
		var isie6 = navigator.userAgent.indexOf ('MSIE 6.0') > -1;
		var issafari = navigator.vendor == 'Apple Computer, Inc.';
		var isfirefox = navigator.userAgent.toLowerCase ().indexOf ('firefox') > -1;
		var root = document.getElementById (primaryNavId);
		var doHandleFocus = true;
		var doHandleAllFocus = true;
		var focusEventSource;
		var focusLevel = -1;
		var lastEventType = -1;
		var lastEventSource;
		var lastPrimaryLi;
		var lastLevel = -1;
		var lastMenu;
		var delayMenuClose;
		var delayMenuUlClose;
		var lastBlurEventSource;
		var lastBlurPrimaryLi;
		var lastBlurLevel = -1;
		var lastLastEventType = -1;
		var lastLastBlurEventSource;
		var lastLastBlurPrimaryLi;
		var lastLastBlurLevel = -1;
		if (!root)
		{
			return false;
		}
		var primeUl = root.getElementsByTagName ('ul').item (0);
		if (!primeUl)
		{
			return false;
		}
		if (!isie)
		{
			primeUl.contains = containsFunction;
			tii_dom_removeWhitespaceTextNodes (primeUl);
		}
		var primeLis = primeUl.childNodes;
		var primeLisLength = primeLis.length;
		for (var i = 0; i < primeLisLength; i++)
		{
			primeLi = primeLis.item (i);
			if (!isie)
			{
				primeLi.contains = containsFunction;
			}
			var primeLiKids = primeLi.childNodes;
			var primeLiKidsLength = primeLiKids.length;
			for (var j = 0; j < primeLiKidsLength; j++)
			{
				var primeLiKid = primeLiKids.item (j);
				var primeLiKidNodeName = primeLiKid.nodeName;
				if (primeLiKidNodeName == 'A')
				{
					addLinkEventHandlers (primeLiKid, 0);
				}
				else if (primeLiKidNodeName == 'UL')
				{
					if (!isie)
					{
						primeLiKid.contains = containsFunction;
						tii_dom_removeWhitespaceTextNodes (primeLiKid);
					}
					tii_pnav_assignFlyoutLis (primeLiKid, addLinkEventHandlers)
				}
			}
		}	// End for
		
		tii_addEventHandler (primeUl, 'mouseout', function (event)
		{
			var related = typeof event.relatedTarget != 'undefined' ? event.relatedTarget : window.event.toElement;
			if (related && !primeUl.contains (related))
			{
				var menu = getMenu (event);
				if (menu)
				{
					if (!focusEventSource || focusEventSource != lastEventSource || menu.contains (focusEventSource))
					{
						deactivateLink (lastEventSource, lastLevel, true, true);
					}
				}
			}		
		}, false);
		
		var keyevent = issafari || isie ? 'keydown' : 'keypress';

		tii_addEventHandler (document, keyevent, function (event)
		{
			var target = typeof event.target != 'undefined'? event.target : event.srcElement;
			if (primeUl.contains (target) && target.getAttribute ('href'))
			{
				if (event.keyCode == 27) /* escape key */
				{
					closeAllDropdowns ();
					if (typeof event.preventDefault != 'undefined')
					{
						event.preventDefault ();
					}
					return false;
				}
			}
			return true;
		}, false);
		
		var elements = document.getElementsByTagName ('*');
		var elementsLength = elements.length;

		for (p = 0; p < elementsLength; p++)
		{
			tii_addEventHandler (elements.item (p), 'focus', function (event)
			{
				if (doHandleAllFocus)
				{
					var target = typeof event.target != 'undefined'? event.target : event.srcElement;
					if (!primeUl.contains (target))
					{
						closeAllDropdowns ();
					}
				}
			}, false);
		}	// End for
		
		if (isfirefox)
		{
			tii_addEventHandler (document, 'focus', function (event) 
			{
				var target = typeof event.target != 'undefined'? event.target : event.srcElement;
				if (target == document)
				{
					if (lastBlurPrimaryLi)
					{
						doHandleFocus = false;
						deactivateLink (lastBlurPrimaryLi.getElementsByTagName ('a').item (0), 0, true, true);
						var resetDelay = setTimeout (function () { changeStateFunction (lastBlurPrimaryLi, false, 0); }, 1);
					}
				}
			}, false);
		}
		else
		{
			tii_addEventHandler (window, 'blur', function () 
			{
				if (lastEventSource)
				{
					deactivateLink (lastEventSource, lastLevel, true, true);
				}
			}, false);	
		}	// End if-else
		
		function containsFunction (node)
		{
			if (node == null)
			{
				return false;
			}
			if (node == this)
			{
				return true;
			}
			else
			{
				return this.contains (node.parentNode);
			}
		}	// End containsFunction()
		
		function getMenu (event)
		{
			try
			{
				var menu = typeof event.target != 'undefined'? event.target : event.srcElement;
				while (menu && menu.parentNode.parentNode.parentNode != root)
				{
					menu = menu.parentNode;
				}
				if (menu && menu.parentNode.parentNode.parentNode == root)
				{
					return menu;
				}
				else
				{
					return null;
				}
			}
			catch (error) { return null; }
		}	// End getMenu()
		
		function closeAllDropdowns ()
		{
			for (var n = 0; n < primeLisLength; n++)
			{
				deactivateLink (primeLis.item (n).getElementsByTagName ('a').item (0), 0, true, true);
			}
		}	// End closeAllDropdowns()
		
		function addLinkEventHandlers (link, level)
		{
			tii_addEventHandler (link, 'mouseover', callHandleEvent, false);
			tii_addEventHandler (link, 'mouseout', callHandleEvent, false);
			tii_addEventHandler (link, 'focus', callHandleEvent, false);
			tii_addEventHandler (link, 'blur', callHandleEvent, false);
			function callHandleEvent (event)
			{
				handleEvent (event, level);
			}
		}	// End  addLinkEventHandlers()

		function handleEvent (event, level)
		{
			var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
			while (eventSource && eventSource.nodeName != 'A')
			{
				eventSource = eventSource.parentNode;
			}
			if (!eventSource || eventSource.nodeName != 'A')
			{
				return;
			}
			var eventType = event.type;
			if (issafari && (eventType == 'mouseover' || eventType == 'mouseout') && tii_pnav_isUnwantedTextEvent ())
			{
				return;
			}
			if (eventType == 'mouseover')
			{
				handleMouseover (eventSource, level);
			}
			if (eventType == 'mouseout' && level == 0)
			{
				handleMouseout (eventSource, level, event);
			}
			else if (eventType == 'focus')
			{
				handleFocus (eventSource, level);
			}
			else if (eventType == 'blur')
			{
				handleBlur (eventSource, level);
			}
		}	// End handleEvent()
		
		function handleMouseover (eventSource, level)
		{
			var closeMenu = false;
			if (level == 0)
			{
				if (eventSource.parentNode != lastPrimaryLi)
				{
					closeMenu = true;
				}
				else
				{
					if (lastLevel > 0)
					{
						clearTimeout (delayMenuClose);
					}
					closeMenu = false;
				}
				deactivateLink (lastEventSource, lastLevel, false, closeMenu);
				activateLink (eventSource, level);
			}
			else
			{
				if (!isie)
				{
					if (lastPrimaryLi && !lastPrimaryLi.contains)
					{
						lastPrimaryLi.contains = containsFunction;
					}
				}
				if (isfirefox && lastEventType == 2 && lastLastEventType == 2)
				{
					if (!lastLastBlurPrimaryLi.contains (eventSource) || !lastBlurPrimaryLi.contains (eventSource))
					{
						var delayBlurMenuClose = setTimeout (function () 
						{
							var lastLastBlurMenu = lastLastBlurPrimaryLi.getElementsByTagName ('ul').item (0);
							hideOrShowMenuFunction (lastLastBlurMenu, true, lastLastBlurPrimaryLi);
							changeStateFunction (lastLastBlurPrimaryLi, false, 0);
						}, (isie6 ? tii_pnav_closeMenuDelayIE6 : tii_pnav_closeMenuDelay));
					}
				}
				if (lastEventSource)
				{
					if (lastPrimaryLi.contains (eventSource))
					{
						clearTimeout (delayMenuClose);
						closeMenu = false;
					}
					else
					{
						closeMenu = true;
					}
					deactivateLink (lastEventSource, lastLevel, false, closeMenu);
				}
				activateLink (eventSource, level);
			}
			lastLastEventType = lastEventType;
			lastEventType = 0;
			lastEventSource = eventSource;
			lastPrimaryLi = level == 0 ? lastEventSource.parentNode : (level == 1 ? lastEventSource.parentNode.parentNode.parentNode : lastEventSource.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode);
			lastLevel = level;
			doHandleFocus = false;
			doHandleAllFocus = false;
			eventSource.focus ();
		}	// End handleMouseOver()
		
		function handleMouseout (eventSource, level, event)
		{
			var related = typeof event.relatedTarget != 'undefined' ? event.relatedTarget : window.event.toElement;
			if (!eventSource.parentNode.contains (related))
			{
				deactivateLink (eventSource, level, true, true);
			}
		}	// End handleMouseOut()
		
		function handleFocus (eventSource, level)
		{
			var closeMenu = false;
			if (!doHandleFocus)
			{
				doHandleFocus = true;
				return;
			}
			doHandleAllFocus = true;
			focusEventSource = eventSource;
			focusLevel = level;
			if (lastEventSource)
			{
				if (!isie && !lastPrimaryLi.contains)
				{
					lastPrimaryLi.contains = containsFunction;
				}
				if (lastPrimaryLi && lastPrimaryLi.contains (eventSource))
				{
					closeMenu = false;
				}
				else
				{
					closeMenu = true;
				}
				deactivateLink (lastEventSource, lastLevel, true, closeMenu);
			}
			activateLink (eventSource, level);
			lastLastEventType = lastEventType;
			lastEventType = 2;
			lastEventSource = eventSource;
			lastPrimaryLi = level == 0 ? lastEventSource.parentNode : (level == 1 ? lastEventSource.parentNode.parentNode.parentNode : lastEventSource.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode);
			lastLevel = level;
		}	// End handleFocus()
		
		function handleBlur (eventSource, level)
		{
			lastLastBlurEventSource = lastBlurEventSource;
			lastLastBlurPrimaryLi = lastBlurPrimaryLi;
			lastLastBlurLevel = lastBlurLevel;
			lastBlurEventSource = eventSource;
			lastBlurPrimaryLi = level == 0 ? lastBlurEventSource.parentNode : (level == 1 ? lastBlurEventSource.parentNode.parentNode.parentNode : lastBlurEventSource.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode);
			lastBlurLevel = level;
		}	// End handlBlur()
		
		function activateLink (link, level)
		{
			if (level == 0)
			{
				changeStateFunction (link.parentNode, false, 2);
				var menu = link.parentNode.getElementsByTagName ('ul').item (0);
				if (!menu)
				{
					return;
				}
				hideOrShowMenuFunction (menu, false, menu.parentNode);
			}
			else if (level == 1 || level == 2)
			{
				var secondLi = link.parentNode;
				if (level == 1)
				{
					menu = secondLi.parentNode;
				}
				else
				{
					menu = secondLi.parentNode.parentNode.parentNode.parentNode;
				}
				hideOrShowMenuFunction (menu, false, menu.parentNode);
				changeStateFunction (secondLi, true, 2);
				if (lastLevel == 0)
				{
					changeStateFunction (menu.parentNode, false, 1);
				}
			}
		}	// End activateLink()
		
		function deactivateLink (link, level, skipDelay, closeMenu)
		{
			var menu;
			var primeLi;
			var secondLi;
			if (level == 0)
			{
				primeLi = link.parentNode;
				menu = primeLi.getElementsByTagName ('ul').item (0);
				if (!menu)
				{
					changeStateFunction (primeLi, false, 0);
					return;
				}
			}
			else if (level == 1 || level == 2)
			{
				secondLi = link.parentNode;
				changeStateFunction (secondLi, true, 0);
				if (level == 1)
				{
					menu = secondLi.parentNode;
				}
				else
				{
					menu = secondLi.parentNode.parentNode.parentNode.parentNode;
				}
				primeLi = menu.parentNode;
			}
			if (menu && closeMenu)
			{
				doMenuClose (menu, primeLi, skipDelay);
			}
		}	// End deactivateLink()

		function doMenuClose (menu, primeLi, skipDelay)
		{
			if (skipDelay)
			{
				hideOrShowMenuFunction (menu, true, menu.parentNode);
				changeStateFunction (primeLi, false, 0);
				return;
			}
			delayMenuClose = setTimeout (function () 
			{
				hideOrShowMenuFunction (menu, true, menu.parentNode);
				changeStateFunction (primeLi, false, 0);
			}, (isie6 ? tii_pnav_closeMenuDelayIE6 : tii_pnav_closeMenuDelay));
		}	// End doMenuClose
	}	// End tii_pnav_initializeDropdownMenu()

	function tii_pnav_assignFlyoutLis (flyoutUl, addLinkEventHandlers)
	{
		var isMulticolumn = true;
		var flyoutLis = flyoutUl.childNodes;
		var flyoutLisLength = flyoutLis.length;
		for (var k = 0; k < flyoutLisLength; k++)
		{
			var flyoutLi = flyoutLis.item (k);
			var secondFlyoutLis = flyoutLi.getElementsByTagName ('li');
			var secondFlyoutLisLength = secondFlyoutLis.length;
			if (secondFlyoutLisLength == 0)
			{
				var flyoutLinks = flyoutLi.getElementsByTagName ('a');
				var flyoutLinksLength = flyoutLinks.length;
				for (var m = 0; m < flyoutLinksLength; m++)
				{
					addLinkEventHandlers.call (this, flyoutLinks.item (m), 1);
				}
			}
			else
			{
				for (var n = 0; n < secondFlyoutLisLength; n++)
				{
					var secondFlyoutLi = secondFlyoutLis.item (n);
					var secondFlyoutLinks = secondFlyoutLi.getElementsByTagName ('a');
					var secondFlyoutLinksLength = secondFlyoutLinks.length;
					for (var p = 0; p < secondFlyoutLinksLength; p++)
					{
						addLinkEventHandlers.call (this, secondFlyoutLinks.item (p), 2);
					}
				}
			}	// End if-else
		}	// End for
	}	// End tii_pnav_assignFlyoutLis()

	function tii_pnav_isUnwantedTextEvent ()
	{
	 	return (navigator.vendor == 'Apple Computer, Inc.'
	      && (event.target == event.relatedTarget.parentNode
	      || (event.eventPhase == 3
	      && event.target.parentNode == event.relatedTarget)));
	}	// End tii_pnav_isUnwantedTextEvent()

	/* These two function calls initialize the primary navigation menu after the 'topnav_loaded' span is loaded. */
	tii_callFunctionOnElementLoad ('topnav_loaded', function ()
	{
		rs_pnav_performTopNavHighlight ();
		tii_pnav_initializeDropdownMenu.apply (this, new Array ('topnav', pnav_hideOrShowMenuFunction, pnav_changeStateFunction));
	});

	/* This is the hide/show menu function that needs to be defined for each site */
	function pnav_hideOrShowMenuFunction (menu, hideElseShow, menuParent)
	{
		menu.style.left = (hideElseShow ? '-9999' : (menu.className.indexOf ('tn_from_left') > -1 ? -1 : menuParent.offsetWidth - 543)) + 'px';
	}	// End pnav_hideOrShowMenuFunction

	/* This is the change/clear status function that needs to be defined for each site */
	function pnav_changeStateFunction (element, isADropdownItem, state)
	{
		if (isADropdownItem)
		{
			element.className = element.className.replace(/active/gi, '');
			switch (state)
			{
				case 0: /* default */
					break;
				case 2:
					element.className += (element.className == '' ? '' : ' ') + 'tn_flyout_active';
					break;
			}
		}
		else
		{
			element.className = element.className.replace(/active/gi, '');
			switch (state)
			{
				case 0: /* default */
					element.className = element.className.replace(/current_marker/gi, 'current_page');
					break;
				default:
					element.className = element.className.replace(/current_page/gi, 'current_marker');
					element.className += (element.className == '' ? '' : ' ') + 'active';
					break;
			}
		}
	}	// End pnav_changeStateFunction()

	/* 
	 * CSS adjustments made for specific browsers on PC or Mac via Javascript, because static CSS files alone 
	 * do not produce desired effect consistently on all browsers 
	 */
	
	/* inject a <style> element with overriding CSS into the <head> of page */
	var head = document.getElementsByTagName('head')[0];
	var newStyle = document.createElement('style');
	newStyle.setAttribute('type','text/css');
	
	if (isMac) 
	{
		// Firefox on Mac
		if (isFirefox) {
			newStyle.innerHTML = '#topnav ul li a.tn_a_prime_mm { padding: 6px 11px 6px 11px !important; }\n' + 
								 '#topnav ul li.active a.tn_a_prime_mm { padding: 5px 10px 6px 10px !important; }\n' +
								 '#topnav ul #tn_health ul.tn_flyout { width: 540px !important; }\n' +
					 			 '#topnav ul #tn_work ul.tn_flyout { width: 540px !important; }';
		} else if (isSafari) {
				// Safari uses innerText instead of innerHTML
				newStyle.innerText = '#topnav ul li.tn_li_prime a {padding: 6px 15px 6px 15px; !important;}' +
				'\n#topnav ul li.active a.tn_a_prime {padding: 5px 14px 6px 14px !important;}' +
				'\n#topnav ul li a.tn_a_prime_mm {padding: 6px 15px 6px 14px !important;}' +
				'\n#topnav ul li.active a.tn_a_prime_mm {padding: 5px 14px 6px 13px !important;}';
			} // End if-else-if
	} 
	else // isPC
	{
		if (isFirefox) {
			/* While the \ escape character has been used for multi-line strings, it's not part of the Javascript standard, so it's not future-proof; reverting to other techniques */
			newStyle.innerHTML = '#topnav ul li.tn_li_prime a.tn_a_prime { padding: 6px 8px 6px 11px !important; }\n' +
								 '#topnav ul li a.tn_a_prime_mm { padding: 6px 10px 6px 13px !important; }\n' + 
								 '#topnav ul li.active a.tn_a_prime { padding: 6px 8px 6px 11px !important; }\n' +
								 '#topnav ul li.active a.tn_a_prime_mm { padding: 6px 10px 6px 13px !important; }\n' +
								 '#topnav ul #tn_holidays ul.tn_flyout { width: 541px !important; }\n' + 
								 '#topnav ul #tn_health ul.tn_flyout { width: 539px !important; }';
		}
	}	// End if-else

	head.appendChild(newStyle);
/* End of tv_hide_css enclosure */
}
else
{
	tii_callFunctionOnElementLoad ('topnav_loaded', function ()
	{
		rs_pnav_performTopNavHighlight ();
	});
}