
function tii_dom_createElement (nodeName, attributes)
{
	var isopera = typeof window.opera != 'undefined';
	var isie = typeof document.all != 'undefined'
   		&& !isopera && navigator.vendor != 'KDE';
		
	var newElement;
	try
	{
		newElement = document.createElement (nodeName);
	}
	catch (error)
	{
		return null;
	}
	
	var attributesLength = attributes.length;
	for (var i = 0; i < attributesLength; i++)
	{
		var attribute = attributes [i] [0];
		var value = attributes [i] [1];
		newElement.setAttribute (attribute, value);
		switch (attribute)
		{
			case 'id':
				newElement.id = value;
				break;
			case 'class':
				if (isie)
				{
					newElement.setAttribute ('className', value);
				}
				newElement.className = value;
				break;
			case 'style':
				newElement.style.cssText = newElement.style.cssText + ' ' + value;
				break;
			case 'for':
				if (isie)
				{
					newElement.setAttribute ('htmlFor', value);
				}
				newElement.htmlFor = value;
		}
	}
	
	return newElement;
}


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_callFunctionOnWindowLoad (functionToCall)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener ('load', functionToCall, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener ('load', functionToCall, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent ('onload', functionToCall);
  }
  else
  {
    var oldFunctionToCall = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = functionToCall;
    }
    else
    {
      window.onload = function ()
      {
        oldFunctionToCall ();
        functionToCall ();
      };
    }
  }
}


function tii_callFunctionOnElementLoad (targetId, functionToCall)
{
	var myArguments = arguments;
	tii_callFunctionOnWindowLoad (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);
				}
			}, 10);
	}
}


function tii_addEventHandlerOnElementLoad (targetId, eventType, functionToCall, bubbleEventUpDOMTree)
{
	tii_callFunctionOnWindowLoad (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);
					tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree);
				}
			}, 10);
	}
}


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_removeEventHandler (targetElement, eventType, functionToRemove, bubbleEventUpDOMTree)
{
  if (typeof targetElement.removeEventListener != "undefined")
  {
    targetElement.removeEventListener (eventType, functionToRemove, bubbleEventUpDOMTree);
  }
  else if (typeof targetElement.detachEvent != "undefined")
  {
    targetElement.detachEvent ("on" + eventType, functionToRemove);
  }
  else
  {
    targetElement ["on" + eventType] = null;
  }
  
  return true;
}


/***** EW Global Variables *****/
var ew_isopera = typeof window.opera != 'undefined';
var ew_isie = typeof document.all != 'undefined'
   	&& !ew_isopera && navigator.vendor != 'KDE';
var ew_issafari = navigator.vendor == 'Apple Computer, Inc.';

/***** EW Global Functions *****/

/* Remove IE6 image flickering */
try
{
	document.execCommand ('BackgroundImageCache', false, true);
}
catch (error) {}

/* Sets up Top 5 tabs */
function ew_setTop5Tabs (issafari)
{
	var top5 = document.getElementById ('top5');
	if (top5 == null)
	{
		return;
	}
	
	var tabCount = 5;
	var tabs = new Array ('movies', 'dvd', 'tv', 'music', 'books');
	var tabAnchors = new Array (tabCount);
	
	for (var i = 0; i < tabCount; i++)
	{
		var tab = document.getElementById (tabs [i] + 'tab');
		var tabAnchor = null;
		if (tab)
		{
			tabAnchor = tab.getElementsByTagName ('a').item (0);
			tabAnchors [i] = tabAnchor;		
		}
		else
		{
			window.status = 'Warning: Top 5 tab is null';
			continue;
		}
		var pattern = /.*#/;
		if (issafari && pattern.test (tabAnchor.href))
		{
			tabAnchor.href = 'javascript:{}';
		}
		
		function changeTab (event)
		{
			if (event.type == 'keypress' && event.keyCode != 13)
			{
				return false;
			}
			var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;				
			var newTabIdRaw = eventSource.parentNode.id;
			if (typeof newTabIdRaw == 'undefined' || newTabIdRaw == '')
			{
				tii_stopDefaultAction (event);
				return false;
			}
			var newTabId = newTabIdRaw.replace(/tab/gi, '');
			for (var i = 0; i < tabCount; i++)
			{
				var tabAnchor = tabAnchors [i];
				if (tabAnchor)
				{
					tabAnchor.className = '';
				}
				var table = document.getElementById ('top5' + tabs [i]);
				if (table)
				{
					table.style.display = 'none';
				}
			}
			var newTab = document.getElementById (newTabId + 'tab');
			if (newTab)
			{
				var newTabAnchor = newTab.getElementsByTagName ('a').item (0);
				if (newTabAnchor)
				{
					newTabAnchor.className = 'selected';
				}
			}
			var newTable = document.getElementById ('top5' + newTabId);
			if (newTable)
			{
				newTable.style.display = 'block';
			}
			tii_stopDefaultAction (event);
		}		
		
		tii_addEventHandler (tabAnchor, 'click', changeTab, false);
		tii_addEventHandler (tabAnchor, 'keypress', changeTab, false);
	}
}

/* Sets the bottom critic grader to scroll to the top critic grader without using href="#grader" */
function ew_setBottomCriticGrader ()
{
	var commentForm = document.getElementById ('commentform');
	if (commentForm)
	{
		var anchors = commentForm.getElementsByTagName ('a');
		var anchorsLength = anchors.length;
		for (var i = 0; i < anchorsLength; i++)
		{
			var keyevent = ew_issafari || ew_isie ? 'keydown' : 'keypress';
			var anchor = anchors [i];
			if (anchor.href = '#grader')
			{
				anchor.href = 'javascript:{}';
				function setScrollIntoView (event)
				{
					if (event.type == keyevent && event.keyCode != 13)
					{
						return false;
					}
					var grader = document.getElementById ('grader');
					if (grader)
					{
						grader.scrollIntoView (true);
						document.documentElement.scrollTop = document.documentElement.scrollTop - 8;
					}
				}
				tii_addEventHandler (anchor, 'click', setScrollIntoView, false);
				tii_addEventHandler (anchor, keyevent, setScrollIntoView, false);
			}
		}
	}
}
		
/* Copies the contents of an iframe in the Popwatch page to the parent document */
function ew_copyPopwatchIframeContents (childRoot, iframeId, iframeIdOther)
{
	var root = parent.document.getElementById ('navcol');
	var isie = ew_isie;
	if (root)
	{
		tii_dom_removeWhitespaceTextNodes (root);
		var clonedChild = childRoot.cloneNode (true);
		var children = new Array ();
		var childrenIndex = 0;
		for (var i = 0; i < root.childNodes.length; i++)
		{
			var rootChild = root.childNodes.item (i);
			if (rootChild)
			{
				if (iframeIdOther == '')
				{
					if (isie && rootChild.id == iframeId)
					{
						root.removeChild (rootChild);
						root.innerHTML = clonedChild.outerHTML + root.innerHTML;
						return true;
					}
				}
				else if (isie)
				{
					if (rootChild.id == iframeId)
					{
						children [childrenIndex] = clonedChild;
						childrenIndex++;
						root.removeChild (rootChild);
						i--;
					}
					else if (rootChild.id == iframeIdOther)
					{
						children [childrenIndex] = rootChild.cloneNode (true);
						childrenIndex++;
						root.removeChild (rootChild);
						i--;
					}
				}
				if (!isie && rootChild.id == iframeId)
				{
					root.replaceChild (clonedChild, rootChild);
				}
			}
		}
		if (isie)
		{ 
			var allHTML = root.innerHTML;
			for (var j = childrenIndex - 1; j >= 0; j--)
			{
				allHTML = children [j].outerHTML + allHTML;
			}
			root.innerHTML = allHTML;
		}
	}
}

/* Sets the display/collapse toggling navarrows */
function ew_setNavArrows (isie, issafari)
{
	function toggleDisplay (event)
	{
		if ((event.type == 'keydown' || event.type == 'keypress') && event.keyCode != 13)
		{
			return false;
		}
		var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
		var displayDiv = eventSource.parentNode.parentNode;
		var displayDivClass = displayDiv.className;
		if (displayDivClass.match ('navhide'))
		{
			displayDivClass = displayDivClass.replace(/navhide/gi, 'navshow');
		}
		else
		{
			displayDivClass = displayDivClass.replace(/navshow/gi, 'navhide');
		}
		displayDiv.className = displayDivClass;
		tii_stopDefaultAction (event);
	}
		
	var navArrows = document.getElementsByName ('navarrow');
	var navArrowsLength = navArrows.length;
	for (var i = 0; i < navArrowsLength; i++)
	{
		var navArrow = navArrows [i];
		if (issafari)
		{
			navArrow.href = 'javascript:{}';
		}
		tii_addEventHandler (navArrow, 'click', function (event)
			{
				toggleDisplay (event);
			}, false);
		var keyevent = issafari || isie ? 'keydown' : 'keypress';
		tii_addEventHandler (navArrow, keyevent, function (event)
			{
				toggleDisplay (event);
			}, false);
	}
}

/* Sets the custom selectboxes */
function ew_setSelectBoxes (isie, issafari)
{
	function processAnchorEvent (event)
	{
		if ((event.type == 'keydown' || event.type == 'keypress') && event.keyCode != 13)
		{
			return false;
		}
		var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
		if (eventSource.className == 'current')
		{
			var optionsDiv = eventSource.parentNode.getElementsByTagName ('div').item (0);
			if (optionsDiv.className == 'hidechoices')
			{
				optionsDiv.className = 'showchoices';
			}
			else
			{
				optionsDiv.className = 'hidechoices';
			}
			tii_stopDefaultAction (event);
		}
		else
		{
			eventSource.parentNode.className = 'hidechoices';
		}
	}
	
	var selectBoxAnchors = document.getElementsByName ('selectBox');
	var selectBoxAnchorsLength = selectBoxAnchors.length;
	for (var i = 0; i < selectBoxAnchorsLength; i++)
	{
		var selectBox = selectBoxAnchors [i].parentNode;
		var anchorList = selectBox.getElementsByTagName ('a');
		var anchorListLength = anchorList.length;
		for (var j = 0; j < anchorListLength; j++)
		{
			var anchor = anchorList [j];
			if (anchor.className != 'selectBox')
			{
				tii_addEventHandler (anchor, 'click', function (event)
					{
						processAnchorEvent (event);
					}, false);
				var keyevent = issafari || isie ? 'keydown' : 'keypress';
				tii_addEventHandler (anchor, keyevent, function (event)
					{
						processAnchorEvent (event);
					}, false);
			}
		}		
	}
}

/* Sets the redirect for the default TV subchannel page */
function ew_setTVSubchannelRedirect (hrefArray)
{
	var today = new Date ();
	var currentDay = today.getDay ();
	var currentDayIndex = currentDay - 1 < 0? 6 : currentDay - 1;
	if (hrefArray)
	{
//		location.href = hrefArray [currentDayIndex];
		location.replace(hrefArray [currentDayIndex]);
	}
}

/* Calls ew_setTVListings after a brief delay to let the whole section load first */
function ew_setTVListingsInit ()
{
	var delay = setTimeout (function ()
	{
		ew_setTVListings.apply (this, new Array (ew_isie, ew_issafari));
	}, 100);
}

/* Sets the behaviors for the pages with TV tabs */
function ew_setTVListings (isie, issafari)
{
	/* Get the placeholder for the date tabs */
	var datetabs = document.getElementById ('datetabs');
	if (datetabs == null || datetabs.className == 'subchannel')
	{
		return;
	}

	/* Determine if the page is the home page */
	var isHomePage = datetabs.className == 'home'? true : false;

	/* Deactivate any active days */
	var daysUl = datetabs.getElementsByTagName ('ul').item (0);
	tii_dom_removeWhitespaceTextNodes (daysUl);
	var days = daysUl.childNodes;
	var daysLength = days.length;
	for (var i = 0; i < daysLength; i++)
	{
		var dayClassName = days [i].className;
		if (dayClassName.indexOf ('on') > -1)
		{
			days [i].className = dayClassName.replace(/ ?on/g, '');
		}
		
		/* Hide all tabs if home page */
		if (isHomePage)
		{
			days [i].style.display = 'none';
		}
	}
	
	/* Get the current day and activate it */	
	var today = new Date ();
	var currentDay = today.getDay ();
	var currentDayIndex = currentDay - 1 < 0? 6 : currentDay - 1;
	days [currentDayIndex].className += (days [currentDayIndex].className == '' ? '' : ' ') + 'on';

	/* Display three tabs if home page */
	if (isHomePage)
	{
		var effectiveDayIndex = currentDayIndex < 4? currentDayIndex : 4;
		for (var j = effectiveDayIndex; j < effectiveDayIndex + 3; j++)
		{
			days [j].style.display = 'block';
		}
	}

	/* Get the placeholder for the tv channel listings */
	var tvchannellistings = document.getElementById ('tvchannellistings');
	if (tvchannellistings == null)
	{
		return;
	}
	
	/* Hide all day listings */
	tii_dom_removeWhitespaceTextNodes (tvchannellistings);
	var dayListings = tvchannellistings.childNodes;
	var dayListingsLength = dayListings.length;
	for (var i = 0; i < dayListingsLength; i++)
	{
		var dayListing = dayListings.item (i);
		dayListing.className = dayListing.className.replace(/show/gi, '');
		dayListing.className += (dayListing.className == '' ? '' : ' ') + 'hide';
		dayListing.style.display = 'none';
	}
	
	/* Activate the current day listing */
	var currentDayListing = dayListings.item (currentDayIndex);
	currentDayListing.className = currentDayListing.className.replace(/hide/gi, '');
	currentDayListing.className += (currentDayListing.className == '' ? '' : ' ') + 'show';
	currentDayListing.style.display = 'block';
	
	/* Deactivate the hyperlinks for the day tabs */
	function processEvent (event)
	{
		if ((event.type == 'keydown' || event.type == 'keypress') && event.keyCode != 13)
		{
			return false;
		}
		var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
		while (eventSource.nodeName.toUpperCase () != 'A')
		{
			eventSource = eventSource.parentNode;
		}
		if (eventSource.nodeName.toUpperCase () != 'A')
		{
			return;
		}
		if (datetabs.className != 'subchannel')
		{
			tii_stopDefaultAction (event);
			if (issafari)
			{
				eventSource.href = 'javascript:{}';
			}
		}

		var parent = eventSource.parentNode.parentNode;
		tii_dom_removeWhitespaceTextNodes (parent);
		var parentChildren = parent.childNodes;
		var parentChildrenLength = parentChildren.length;
		var currentIndex = 0;
		for (var i = 0; i < parentChildrenLength; i++)
		{
			if (parentChildren.item (i).getElementsByTagName ('a').item (0) == eventSource)
			{
				currentIndex = i;
			}
		}
		for (var i = 0; i < dayListingsLength; i++)
		{
			var dayListing = dayListings.item (i);
			dayListing.className = dayListing.className.replace(/show/gi, '');
			dayListing.className += (dayListing.className == '' ? '' : ' ') + 'hide';
			dayListing.style.display = 'none';
		}
		var currentDayListing = dayListings.item (currentIndex);
		currentDayListing.className = currentDayListing.className.replace(/hide/gi, '');
		currentDayListing.className += (currentDayListing.className == '' ? '' : ' ') + 'show';
		currentDayListing.style.display = 'block';
		
		for (var i = 0; i < daysLength; i++)
		{
			var dayClassName = days [i].className;
			if (dayClassName.indexOf ('on') > -1)
			{
				days [i].className = dayClassName.replace(/ ?on/g, '');
			}
		}
		days [currentIndex].className += (days [currentIndex].className == '' ? '' : ' ') + 'on';
	}
	
	for (var i = 0; i < daysLength; i++)
	{
		var dayLink = days [i].getElementsByTagName ('a').item (0);
		if (dayLink)
		{
			tii_addEventHandler (dayLink, 'click', 
				function (event)
				{
					processEvent (event);
				}, false);
			var keyevent = issafari || isie ? 'keydown' : 'keypress';
			tii_addEventHandler (dayLink, keyevent, 
				function (event)
				{
					processEvent (event);
				}, false);
		}
	}
}

/* Sets the mouseover background color change for the touts that need it 
	<a name="thovref"></a> needs to be added as a child of the div that contains the touts */
function ew_setToutHovers ()
{
	var toutRefs = document.getElementsByName ('thovref');
	var toutRefsLength = toutRefs.length;
	for (var i = 0; i < toutRefsLength; i++)
	{
		var divRef = toutRefs [i].parentNode;
		if (divRef != null && divRef.tagName != null && divRef.tagName.toUpperCase () == 'DIV')
		{
			ew_attachToutListeners (divRef, 'div');
			ew_attachToutListeners (divRef, 'li');
		}
	}
}

/* 20080811 Updated to support parent "UL" */
function ew_setToutHovers () {
  var toutRefs = document.getElementsByName ('thovref');
  var toutRefsLength = toutRefs.length;
  for (var i = 0; i < toutRefsLength; i++) {
    var divRef = toutRefs [i].parentNode;
    if (divRef != null && divRef.tagName != null && (divRef.tagName.toUpperCase
() == 'DIV' || divRef.tagName.toUpperCase () == 'UL')) {
      ew_attachToutListeners (divRef, 'div');
      ew_attachToutListeners (divRef, 'li');
    }
  }
}









/* Attaches the mouseover and mouseout event listeners to the tout */
var ew_attachTL_eventSource;

function ew_attachToutListeners (divRef, tagName)
{
	var touts = divRef.getElementsByTagName (tagName);
	var toutsLength = touts.length;
	for (var j = 0; j < toutsLength; j++)
	{
		var closeTime;
		var tout = touts [j];
		var changeBackground = 
			function (event)
			{
				var eventSource = ew_getTitledSource (event, 'touthover');
				if (!eventSource)
				{
					return false;
				}
				if (ew_attachTL_eventSource == eventSource)
				{
					clearTimeout (closeTime);
				}
				ew_toutHover (eventSource, true);
			};
		var restoreBackground = 
			function (event)

			{
				var eventSource = ew_getTitledSource (event, 'touthover');
				ew_attachTL_eventSource = eventSource;
				closeTime = setTimeout (
					function ()
					{
						ew_toutHover (eventSource, false);
					}, 1);
			};
		
		if (tout.className.indexOf ('touthover') > -1)
		{
			tii_addEventHandler (tout, 'mouseover', changeBackground, false);
			tii_addEventHandler (tout, 'mouseout', restoreBackground, false);
			tii_addEventHandler (tout, 'focus', changeBackground, false);
			tii_addEventHandler (tout, 'blur', restoreBackground, false);
		}
	}
}

function ew_getTitledSource (event, title)
{
	var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
	while (eventSource != null && eventSource.className.indexOf (title) < 0)
	{
		eventSource = eventSource.parentNode;
	}
	return eventSource;
}

/* Tout Rollover Color */
function ew_toutHover (obj, highlighted)
{ 
	if (highlighted)
	{
		obj.style.backgroundColor = '#fff32b';
	}
	else
	{
		obj.style.backgroundColor = '';
	}
}

/* Sets critics grade dropdown */
function ew_setCriticGradeBox ()
{
	var critGrade = document.getElementById ('criticgrade');
	if (critGrade == null)
	{
		return;
	}
	var criticBox = critGrade.parentNode.nextSibling;
	while (criticBox.id != 'criticavg')
	{
		criticBox = criticBox.nextSibling;
	}
	
	var showPopup = 
		function ()
		{
			clearTimeout (closeTime);
			critGrade.className += (critGrade.className == '' ? '' : ' ') + 'active';
			criticBox.style.display = 'block';
		};
	var hidePopup =
		function ()
		{
			closeTime = setTimeout (
				function ()
				{
					critGrade.className = critGrade.className.replace(/ ?active/g, '');
					criticBox.style.display = 'none';
				}, 50);
		};

	var closeTime;
	var anchor = critGrade.getElementsByTagName ('a').item (0);
	if (anchor != null)
	{
		tii_addEventHandler (anchor, 'focus', showPopup, false);
		tii_addEventHandler (anchor, 'blur', hidePopup, false);
	}
	tii_addEventHandler (critGrade, 'mouseover', showPopup, false);
	tii_addEventHandler (critGrade, 'mouseout', hidePopup, false);
	tii_addEventHandler (criticBox, 'mouseover', 
		function (event)
		{
			clearTimeout (closeTime);
		}, false);
	tii_addEventHandler (criticBox, 'mouseout', hidePopup, false);
}

/* Sets up image gallery */
function ew_setImageGallery (issafari)
{
	var embedGal = document.getElementById ('embedgal');
	if (embedGal == null)
	{
		return;
	}
	
	var egal1 = document.getElementById ('egal1');
	var egal2 = document.getElementById ('egal2');
	var egal3 = document.getElementById ('egal3');
	var anchors = embedGal.getElementsByTagName ('a');
	var anchorsLength = anchors.length;
	var pattern = /.*#/;
	for (var i = 0; i < anchorsLength; i++)
	{
		var anchor = anchors [i];
		if (issafari && pattern.test (anchor.href))
		{
			anchor.href = 'javascript:{}';
		}
		var newSlideId = anchor.className;
		if (newSlideId == 'egal1' || newSlideId == 'egal2' || newSlideId == 'egal3')
		{
			function changeSlide (event)
			{
				if (event.type == 'keypress' && event.keyCode != 13)
				{
					return false;
				}
				var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;				
				var newSlideId = eventSource.className;
				if (typeof newSlideId == 'undefined' || newSlideId == '')
				{
					newSlideId = eventSource.parentNode.className;
				}
				if (egal1 != null)
				{
					egal1.style.display = 'none';
				}
				if (egal2 != null)
				{
					egal2.style.display = 'none';
				}
				if (egal3 != null)
				{
					egal3.style.display = 'none';
				}
				var newSlide = document.getElementById (newSlideId);
				newSlide.style.display = 'block';
				var newSlideAnchor = newSlide.getElementsByTagName ('a').item (0);
				if (typeof newSlideAnchor != 'undefined')
				{
					var focusAnchor;
					if (newSlideId == 'egal1')
					{
						var ul = newSlideAnchor.parentNode.parentNode;
						tii_dom_removeWhitespaceTextNodes (ul);
						focusAnchor = ul.lastChild.getElementsByTagName ('a').item (0);							
					}
					else
					{
						focusAnchor = newSlideAnchor;
					}
					focusAnchor.focus ();
				}
				tii_stopDefaultAction (event);
			}		
				
			tii_addEventHandler (anchors [i], 'click', changeSlide, false);
			tii_addEventHandler (anchors [i], 'keypress', changeSlide, false);
		}
	}
}

/* Sets up the author byline rollovers */
function ew_setBylineRollovers (isie)
{
	var closeTime;
	var bioPopup = document.getElementById ('biopopup');
	if (bioPopup != null)
	{
		var anchor = bioPopup.getElementsByTagName ('a').item (0);
		var anchorWidth = anchor.offsetWidth;
		var box = bioPopup.getElementsByTagName ('div').item (0);
		if (typeof box == 'undefined' || box.className != 'popcont')
		{
			return false;
		}
		var gradeDiv = bioPopup.previousSibling;
		while (gradeDiv != null)
		{
			if (gradeDiv.nodeType == 3)
			{
				gradeDiv = gradeDiv.previousSibling;
			}
			if (gradeDiv != null && gradeDiv.className != null && gradeDiv.className == 'grade')
			{
				break;
			}
		}
		var divOffsetLeft;
		var contentDiv = document.getElementById ('content');
		if (!isie)
		{
			divOffsetLeft = (gradeDiv != null)? gradeDiv.offsetWidth + 10 : 0;
		}
		else
		{
			divOffsetLeft = 0;
		}
		
			var showPopup = function  ()
			{
				clearTimeout (closeTime);
				if (contentDiv != null)
				{
					contentDiv.style.zIndex = 9999;
				}
				var offsetRef = box.parentNode.parentNode;
				box.style.display = 'block';
				box.style.left = (divOffsetLeft + anchorWidth - 41) + 'px';
				switch (offsetRef.id)
				{
					case 'reviewbyline':
						box.style.top = (24 - box.offsetHeight) + 'px';
						break;
					case 'articlebyline':
						box.style.top = (19 - box.offsetHeight) + 'px';
						break;
					case 'contentgalbyline':
						box.style.top = (9 - box.offsetHeight) + 'px';
						break;
					default:
						box.style.top = (0 - box.offsetHeight) + 'px';
						break;
				}
			};
			
			var hidePopup = function ()
			{
				closeTime = setTimeout (
					function ()
					{
						if (contentDiv != null)
						{
							contentDiv.style.zIndex = 9990;
						}
						box.style.left = '-41px';
						box.style.display = 'none';
					}, 50);
			};

		tii_addEventHandler (anchor, 'mouseover', showPopup, false);			
		tii_addEventHandler (anchor, 'mouseout', hidePopup, false);		
		tii_addEventHandler (anchor, 'focus', showPopup, false);			
		tii_addEventHandler (anchor, 'blur', hidePopup, false);
		tii_addEventHandler (box, 'mouseover', showPopup, false);			
		tii_addEventHandler (box, 'mouseout', hidePopup, false);		
	}
}

/* Sets the keyup event listeners for ew_displayCharacterCount */
var ew_scc_maxChars = 0;

function ew_setCharacterCounter () {
	var comment = document.getElementById('scribblecomment');
	if (comment == null) {
		comment = document.getElementById('comment');
	}
	if (comment == null) {
		return;
	}
	
	var commentCount = document.getElementById ('commentCount');
	if (commentCount == null) {
		return;
	}
	
	if (ew_scc_maxChars == 0) {
		ew_scc_maxChars = commentCount.value;
	}
	ew_displayCharacterCount (comment, commentCount);
	tii_addEventHandler (comment, 'keyup', function (event) {
		ew_displayCharacterCount (comment, commentCount);
	}, false);
}

/* Counts the number of characters remaining in a text field (textObj) and writes the output to another text field (countObj) */
function ew_displayCharacterCount (textObj, countObj, maxChars) {
	if (ew_scc_maxChars == '' || ew_scc_maxChars == 0)
	{
		ew_scc_maxChars = 420;
	}
	var strLen = textObj.value.length;
	if (strLen > ew_scc_maxChars)
	{
		strLen = ew_scc_maxChars;
		textObj.value = textObj.value.substring (0, strLen);
	}
	countObj.value = ew_scc_maxChars - strLen;
}

/* Counts the number of words remaining in a text field (textObj) and writes the output to another text field (countObj) */
function ew_getWordCount (textObj, countObj, maxWordsInt)
{
	var textStr = textObj.value.replace (/^[^a-zA-Z'0-9]+/, '') + ' ';
	textStr = textStr.replace (/[^a-zA-Z'0-9]+/g, ' ');
	var wordArr = textStr.split (' ');
	var wordsInt = (textStr == ' ') ? 0 : wordArr.length - 1;
	countObj.value = maxWordsInt - wordsInt;
}

/* Scrolls the container to the point where the element comes into view */
function ew_scrollElIntoView ()
{
	if (typeof elementToScrollTo != 'undefined')
	{
		var element = document.getElementById (elementToScrollTo);
		if (element != null)
		{
			element.scrollIntoView (false);

		}
	}
}

function ew_queryVariableExists( variable ) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for ( var i=0; i < vars.length; i++ ) {
		var pair = vars[i].split("=");
		if ( pair[0] == variable ) {
			return 1
		}
	}
	return 0;
}

function blurSrchTxt() {
	if (document.getElementById("searchbox").value == "") {
		document.getElementById("searchbox").value = "Search...";
	}
}
function focusSrchTxt() {
	if (document.getElementById("searchbox").value == "Search...") {
		document.getElementById("searchbox").value = "";
	}
}
function validateSrch() {
	focusSrchTxt();
	return true;
}

/* form validation for email */
function isValidEmail(str) {
	var filter  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})$/;
	return (filter.test(str));
}

function validateEmail(form) {
	var error = "";
	if (!isValidEmail(form.email.value)){
		error += "Please enter a valid e-mail address.";
	}
	if (error != "") {
		alert(error);
		return false;
	}
	return true;
}


/***** TII Global Functions *****/
/* Gets the total offset position of the element, assuming none of its ancestors have a float of left or right.
   Direction is 'x' for horizontal, and 'y' for vertical */
function tii_getTotalOffsetPosition (element, direction)
{
  var pos = direction == 'x' ? element.offsetLeft : element.offsetTop;
  var tmp = element.offsetParent;
  while (tmp != null)
  {
    pos += direction == 'x' ? tmp.offsetLeft : tmp.offsetTop;
    tmp = tmp.offsetParent;
  }
  return pos;
}

/* Stops the default action for the event, such as jumping to an anchor when clicking on a hyperlink */
function tii_stopDefaultAction (event)
{
	event.returnValue = false;
	if (typeof event.preventDefault != 'undefined')
	{
		event.preventDefault ();
	}
}

