/* Attaching event handlers to elements */
var clickToggle = true;
tii_addEventHandlerOnElementLoad ('bubbleLink', 'mouseover', function (event){displayBubble(event);}, false);
tii_addEventHandlerOnElementLoad ('bubbleLink', 'mouseout', function (event){hideBubble(event);}, false);
tii_addEventHandlerOnElementLoad ('bubbleLink', 'keypress' , function (event){displayBubble(event);}, false);
tii_addEventHandlerOnElementLoad ('bubbleLink', 'blur', function (event){hideBubble(event);}, false);

/* Thought Bubble for The Ag */
function displayBubble(event){

	bubLink = document.getElementById('bubbleLink');
	bub = document.getElementById('bubble');
	var bubPos = new Array(2);
	bubPos = findPos(bubLink);

	/*  Check for IE */
	if (tii_isie)
	{
		bub.style.left = (parseInt(bubPos[0]) - 162).toString() + 'px';
		bub.style.top = (parseInt(bubPos[1]) +  25).toString() + 'px';
	}
	else
	{
		bub.style.left = (parseInt(bubPos[0]) - 176).toString() + 'px';
		bub.style.top = (parseInt(bubPos[1]) +  26).toString() + 'px';
	}

	/* Display the bubble */
	bub.style.display = 'block';
	clickToggle = false;
}

/* Hides the bubble */
function hideBubble(event){
/*	alert ('test');*/
	var bub = document.getElementById('bubble');
	bub.style.display = 'none';
	clickToggle = true;
}

/* Finds the position of an element on the page */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

/* Begin TimeStamp function */
function renderTimestamp(year,month,day,hour,minutes,seconds)
{
    var aYear = new String(year);
    var aMonth = new String(month);
    var aDay = new String(day);


	/* Daylight Savings */
	if (parseInt(hour) > 0) {
    		var aHour = new String(hour-1);
    		hour=parseInt(hour)-1;
	} else if (parseInt(hour) == 0) {
		// 0 means 12 pm or 24
		// Here the day also increases by one.
		// So reducing hour by one (making it 23) AND day by one

    		var aHour = new String(23);
    		hour=23;

		var aDay = new String(day-1);
		day = parseInt(day)-1;

	} else {

		var aHour = new String(hour);
	}
	/* Daylight Savings */

    var aMinutes = new String(minutes);
    var aSeconds = new String(seconds);
    articleUTC = Date.UTC(aYear, aMonth, aDay, aHour, aMinutes, aSeconds);


    /* this is EST timezone offset of 5 hours = 300 minutes with DL savings
    all Time articles are published in EST */
    articleTZOffsetMS = 300 * 60 * 1000 ;
    articleCorrectedMS = articleUTC + articleTZOffsetMS;

    localDate = new Date();
    localYear = localDate.getFullYear();
    localMonth = localDate.getMonth();
    localDay = localDate.getDate();
    localHour = localDate.getHours();
    localMinutes = localDate.getMinutes();
    localSeconds = localDate.getSeconds();
    localTZOffset = localDate.getTimezoneOffset();
    //localTZOffsetMS = localTZOffset * 1000* 60;

    localTZOffsetMS = 300 * 1000* 60;
    localUTC = Date.UTC(localYear, localMonth, localDay, localHour, localMinutes, localSeconds);

    localCorrectedMS = localUTC + localTZOffsetMS;


    // calculate how many minutes between article utc and user utc
    minuteDifferential = (localCorrectedMS - articleCorrectedMS)/(1000 * 60);
    ageInMinutes = Math.round(minuteDifferential);



 if (ageInMinutes < 0) { ageInMinutes = 0;}

    if ( ageInMinutes < 15 ) {
        document.write("<span>UPDATED:</span> "+ ageInMinutes +" minutes ago");
    } else {
        if (hour >= 12) {
            if (hour != 12) {aHour = aHour - 12;}
            ampm = "PM";
        } else {
            ampm = "AM";
        }
        if (aMinutes < 10) {aMinutes = "0" + aMinutes}
        document.write("<span>UPDATED:</span> "+ aHour+":" + aMinutes + ampm + " ET");
    }
}
/* End TimeStamp function */
/* Begin Main story module */
var currPic=0;
var timer1, timer2;
var paused = true;
var opacity = 100;
var msDivs = new Array(5);
var msButtons = new Array(5);
var msWrap;
var button;
var position;
var currPosition;

function initPageComponents() {
 /*  Used to load all components on the page */
 for(i=0,j=1;i<noofevents;i++,j++) {
   msDivs[i] = document.getElementById('mainStory'+j);
 }

 for(i=0,j=1;i<noofevents;i++,j++) {
   msButtons[i] = document.getElementById('a'+j);
 }



 msWrap = document.getElementById('mainStoryWrap');
 initPausePlayEvents();
 var breakingNews = document.getElementById('breakingNewsImg');
 if (breakingNews == null)
 {
  paused = false;
  timer1=setTimeout('timedStory()',5000);
 }
   doImageSwap();
}

function initPausePlayEvents() {
 /* add Event Handlers for the Photo Module */
 if (!document.getElementById || !document.getElementsByTagName) {
  return true;
 }
 /* checks for Javascript operability  */

 /*  get all the links in the photo module  */
 var topStories = document.getElementById('topStories');
 var links = topStories.getElementsByTagName('a');

 for (i=0;i < links.length; i++) {
  if (links.item(i).id.substring(0,1) == 'a'){
   //filter the links for those that have a class name beginnig with 'a'
   //add the doNumber event handler for the number links
   links.item(i).href='javascript:{}';
   tii_addEventHandler (links [i], 'click', function (event)
   {
    doNumber (event);
   }, false);
  }
 }

 var playLink = document.getElementById('playLink');

 //add the doButton event handler for the play pause button
 tii_addEventHandler ( playLink , 'click', function (event)
 {
  doButton (event);
 }, false);
}

/* helper function to deal specifically with images and the cross-browser differences in opacity handling */
function fader(opac) {
 if (msWrap.style.MozOpacity!=null) {
  /* Mozilla's pre-CSS3 proprietary rule */
  msWrap.style.MozOpacity = (opac/100) - .001;
 } else if (msWrap.style.opac!=null) {
  /* CSS3 compatible */
  msWrap.style.opacity = (opac/100) - .001;
 } else if (msWrap.style.filter!=null) {
  /* IE's proprietary filter */
 if (opac==100){
  msWrap.style.filter = "none;";
 } else {
  msWrap.style.filter = "alpha(opacity="+opac+");";
      }
 }
}

function change(num, step) {
 /*fadeOut*/
 if (step == 1) {
  opacity -= 10;
  if (opacity > 0) {
   fader(opacity);
   timer2=setTimeout('change(' + num + ', 1)',50);
  }
  else {
   change(num, 2);
  }
 }
 /*change picture*/
 else if (step == 2) {
  currPic = num;

 for(i=0;i<noofevents;i++) {
   msDivs[i].style.display = (num == i ? "block" : "none");
 }

 for(i=0;i<noofevents;i++) {
   msButtons[i].className = (num == i ? "on" : "off");
 }

  change(num, 3);
 }
 /*fadeIn*/
 else if (step == 3) {
  opacity += 10;
  if (opacity <= 100) {
   fader(opacity);
   timer2=setTimeout('change(' + num + ', 3)',50);
  }
 }
}

/* change picture, wait 5 seconds, repeat */
function timedStory() {
 if (currPic<((noofevents/1)-1))
 currPic++;
 else currPic=0;
 change(currPic, 1);
 timer1=setTimeout('timedStory()',5000);
/* }else{
	 currPic=0;
	clearTimeout(timer1);
	change(currPic,1);
	paused = true;
	doImageSwap();
 }*/
}

/* executed when the play pause button is selected */
function doButton(event) {
 paused = !paused;
 doImageSwap();
 if (paused) {
  /* stop the image loop */
  clearTimeout(timer1);
 }
 else {
  /* restart the image loop */
  timedStory();
 }
}


/*executed when a number link is selected */
function doNumber (event) {
 var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
 /*  get the number portion of the class name of the event source */
 currPic = eventSource.id.substring(1,3) - 1;
 paused = true;
 doImageSwap();
 clearTimeout(timer1);
 clearTimeout(timer2);
 change(currPic, 1);

}

/* swap the play pause button image */
function doImageSwap() {
		 var button = document.getElementById('playLink');
		 if (!tii_isie){
		  var imageFile = paused ? "_images/slider/btn_play.gif" : "_images/slider/btn_pause.gif";
		  button.style.background= "url("+imageFile+") 0px 0px no-repeat";
		 }else{
		  /*  Use an image sprite to deplete the image flickering in IE */
		  button.style.backgroundImage= "url(_images/slider/btn_playpause.gif)";
		  position = paused ? "-20 px" : "0 px";  /* change the image source */
		  try {
			  document.execCommand('BackgroundImageCache', false, true);
			} catch(e) {}

			  /* if paused and play is not displayed */
			  if (paused == true && currPosition != "-16 px"){
				  button.style.backgroundPositionY=position;
			  }
			  /* if playing and paused is not displayed */
			  if (paused != true && currPosition != "0 px"){
				  button.style.backgroundPositionY=position;
			 }
		 currPosition = position;
		 }
}
/* End Main story module */

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 (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;
}
var tii_pnav_branch;
var tii_pnav_previousLink;
var tii_pnav_previousLinkTracker;
var tii_pnav_dontResetCurrentLink = false;

function tii_pnav_initializeDropdownMenu (primaryNavId, hideOrShowMenuFunction, changeStateFunction)
{
  var isopera = typeof window.opera != 'undefined';
  var isie = typeof document.all != 'undefined'
    && !isopera && navigator.vendor != 'KDE';
  var issafari = navigator.vendor == 'Apple Computer, Inc.';

  if (typeof document.getElementById == 'undefined'
      || (issafari && typeof window.XMLHttpRequest == 'undefined')
      || (isie && typeof document.uniqueID == 'undefined'))
  {
    return;
  }
  
  var tree = document.getElementById (primaryNavId);
  if (tree)
  {
    tii_pnav_branch = tree;
    var items = tree.getElementsByTagName('li');
    for (var i = 0; i < items.length; i++)
    {
      tii_pnav_setDropdownTrigger (tree, items[i], primaryNavId, isie, hideOrShowMenuFunction, changeStateFunction);
    }

    if (!isopera)
    {
      tii_dom_removeWhitespaceTextNodes (tree);

      var keyevent = issafari || isie ? 'keydown' : 'keypress';
      tii_addEventHandler(document, keyevent, function(e)
      {
        var target = typeof e.target != 'undefined'
            ? e.target : e.srcElement;
        if (tree.contains(target) && target.getAttribute('href'))
        {
		  /*
		  	 keycode 27 = escape key
		  			 37 = left arrow key
		  			 38 = up arrow key
		  			 39 = right arrow key
		  			 40 = down arrow key
		  */
          if (/^(27|37|38|39|40)$/.test(e.keyCode.toString()))
          {
            tii_pnav_setArrowKeyNavigation(tree, target, e.keyCode, isie, hideOrShowMenuFunction, changeStateFunction);

            if (typeof e.preventDefault != 'undefined')
            {
              e.preventDefault();
            }
            return false;
          }
        }
        return true;

      }, false);
    }
	
    if (!isie)
    {
      tree.contains = function (node)
      {
        if (node == null) { return false; }
        if (node == this) { return true; }
        else { return this.contains (node.parentNode); }
      };
    }
  }
}

function tii_pnav_setDropdownTrigger (tree, li, navid, isie, hideOrShowMenuFunction, changeStateFunction)
{
  var opentime, closetime;
  var a = li.getElementsByTagName('a')[0];
  var menu = li.getElementsByTagName('ul').length > 0
      ? li.getElementsByTagName('ul')[0] : li.parentNode.parentNode.id == navid
	  ? li : null;
  var issub = li.parentNode.id == navid;
  
  tii_addEventHandler(a, 'focus', function(e)
  {
    clearTimeout(closetime);
	tii_pnav_resetPreviousLink (a, isie, hideOrShowMenuFunction, changeStateFunction);
    if (menu)
    {
	  changeStateFunction.call (this, a.parentNode, false, 2);
      tii_pnav_makeMenuVisible (menu, issub, li, a, isie, hideOrShowMenuFunction, changeStateFunction);
    }
	else
	{
		var liGrandPar = li.parentNode.parentNode;
		changeStateFunction.call (this, a.parentNode, true, 2);
		changeStateFunction.call (this, liGrandPar, false, 1);
		var currentLi = a.parentNode;
		var currentPrimaryLi = tii_pnav_getPrimaryLi (a);
		var currentUl = currentLi.parentNode;
		var currentPrimaryA = currentPrimaryLi.firstChild;
		if (currentLi != currentPrimaryLi && currentUl.className == '')
		{
			tii_pnav_makeMenuVisible (currentUl, issub, currentPrimaryLi, currentPrimaryA, isie, hideOrShowMenuFunction, changeStateFunction);
			changeStateFunction.call (this, currentPrimaryLi, false, 1);
		}
	}
  }, false);

  tii_addEventHandler(a, 'blur', function(e)
  {
 	  if (a.className.indexOf ('lastpnitem') > -1 && tii_pnav_previousLinkTracker != null &&
	  	  tii_pnav_previousLinkTracker.className.indexOf ('lastpnitem') < 0)
      {
		  if (!tii_pnav_dontResetCurrentLink)
		  {
			  tii_pnav_resetCurrentLink (a, hideOrShowMenuFunction, changeStateFunction);
		  }
      }
  }, false);
  
  tii_addEventHandler(li, 'mouseover', function(e)
  {
    if (tii_pnav_isUnwantedTextEvent ()) { return; }
    clearTimeout(closetime);
    if (tii_pnav_branch == li) { tii_pnav_branch = null; }

    var target = typeof e.target != 'undefined' ? e.target : window.event.srcElement;
    while (target.nodeName.toUpperCase() != 'LI')
    {
      target = target.parentNode;
    }
    if (target != li) { return; }

	tii_pnav_resetPreviousLink (a, isie, hideOrShowMenuFunction, changeStateFunction);

    if (menu)
    {
	  changeStateFunction.call (this, a.parentNode, false, 2);
      opentime = window.setTimeout(function()
      {
        tii_pnav_makeMenuVisible (menu, issub, li, a, isie, hideOrShowMenuFunction, changeStateFunction);
      }, 1);
    }
	else
	{
		changeStateFunction.call (this, li.parentNode.parentNode, false, 1);
	}
  }, false);

  tii_addEventHandler(li, 'mouseout', function(e)
  {
    if (tii_pnav_isUnwantedTextEvent ()) { return; }

    var related = typeof e.relatedTarget != 'undefined' ? e.relatedTarget : window.event.toElement;
    if (!li.contains(related))
    {
      clearTimeout (opentime);
      tii_pnav_branch = li;
      if (menu)
      {
		changeStateFunction.call (this, a.parentNode, false, 0);
        closetime = window.setTimeout (function ()
        {
		  tii_pnav_resetCurrentLink (a, hideOrShowMenuFunction, changeStateFunction);
        }, 1);
      }
	  else
	  {
		changeStateFunction.call (this, a.parentNode, true, 0);
	  }	  
    }
  }, false);

  if (!isie)
  {
    li.contains = function(node)
    {
      if (node == null) { return false; }
      if (node == this) { return true; }
      else { return this.contains(node.parentNode); }
    };
  }
}

function tii_pnav_setArrowKeyNavigation (tree, link, keycode, isie, hideOrShowMenuFunction, changeStateFunction)
{
  var currentPrimaryLi = tii_pnav_getPrimaryLi (link);
  var openClosedPrimary = false;
 
  if (link.parentNode != currentPrimaryLi && link.parentNode.parentNode.className == '')
  {
	  link = currentPrimaryLi.firstChild;
	  openClosedPrimary = true;
  }

  var li = link.parentNode;
  var menu = li.getElementsByTagName('ul').length > 0
      ? li.getElementsByTagName('ul')[0] : null;
  var parent = li.parentNode;
  var isTopLevel = parent.parentNode == tree;

  if (menu)
  {
	  changeStateFunction.call (this, li, false, 0);
  }
  else
  {
	  changeStateFunction.call (this, li, true, 0);
  }

  if (link.className.indexOf ('lastpnitem') > -1)
  {
	  tii_pnav_dontResetCurrentLink = true;
  }
  else
  {
	  tii_pnav_dontResetCurrentLink = false;
  }
  
  switch (keycode)
  {
	case 27:
	  tii_pnav_dontResetCurrentLink = false;
	  tii_pnav_resetCurrentLink (link, hideOrShowMenuFunction, changeStateFunction);
	  break;
	  
    case 37:
	  if (menu || isTopLevel)
	  {
		  tii_pnav_moveToPrevious (li);
	  }
	  else
	  {
		  tii_pnav_moveToPrevious (parent.parentNode);
	  }
      break;

    case 38:
	  if (menu || isTopLevel)
	  {
		changeStateFunction.call (this, link.parentNode, false, 2);
	  }
	  else
	  {
    	  if (li == li.parentNode.firstChild)
	      {
    	    parent.parentNode.firstChild.focus ();
	      }
		  else
		  {
		    tii_pnav_moveToPrevious (li);
		  }
	  }
      break;

    case 39:
	  if (menu || isTopLevel)
	  {
		  tii_pnav_moveToNext (li);
	  }
	  else
	  {
		  tii_pnav_moveToNext (parent.parentNode);
	  }
      break;
	  
    case 40:
	  tii_pnav_dontResetCurrentLink = false;
	  if (menu && openClosedPrimary)
	  {
		openClosedPrimary = false;
		menu.parentNode.firstChild.focus ();
	  }
      if (menu || isTopLevel)
      {
        menu.firstChild.firstChild.focus ();
      }
	  else
	  {
		tii_pnav_moveToNext (li);
	  }
      break;
  }  
}

function tii_pnav_makeMenuVisible (menu, issub, li, a, isie, hideOrShowMenuFunction, changeStateFunction)
{
  if (typeof li.offsetLeft == 'undefined')
  {
	  return;
  }

  changeStateFunction.call (this, a.parentNode, false, 2);

  hideOrShowMenuFunction (menu, false, li);
  menu.style.top = a.offsetHeight + 'px';
}

function tii_pnav_resetPreviousLink (a, isie, hideOrShowMenuFunction, changeStateFunction)
{
	if (tii_pnav_previousLink)
	{
		var prevLi = tii_pnav_previousLink.parentNode;
		var currentLi = a.parentNode;
		var prevPrimaryLi = tii_pnav_getPrimaryLi (tii_pnav_previousLink);
		var currentPrimaryLi = tii_pnav_getPrimaryLi (a);
		
		if (prevLi != prevPrimaryLi)
		{
			changeStateFunction.call (this, prevLi, true, 0);
		}
		
		var hideMenu = prevPrimaryLi != currentPrimaryLi || a == null;
		
		if (hideMenu || (prevLi != prevPrimaryLi && currentLi == currentPrimaryLi))
		{
			changeStateFunction.call (this, prevPrimaryLi, false, 0);

			if (hideMenu)
			{
				var ul = prevPrimaryLi.getElementsByTagName('ul').item (0);
				if (ul)
				{
					hideOrShowMenuFunction (ul, true, null);
				}
			}
		}		
	}
	tii_pnav_previousLinkTracker = tii_pnav_previousLink;
	tii_pnav_previousLink = a;
}

function tii_pnav_resetCurrentLink (a, hideOrShowMenuFunction, changeStateFunction)
{
	var currentLi = a.parentNode;
	var currentPrimaryLi = tii_pnav_getPrimaryLi (a);
	changeStateFunction.call (this, currentPrimaryLi, false, 0);
	if (currentLi != currentPrimaryLi)
	{
		changeStateFunction.call (this, currentLi, true, 0);
	}
	
	var ul = currentPrimaryLi.getElementsByTagName('ul').item (0);
	if (ul)
	{
        closetime = window.setTimeout(function()
      		{
				hideOrShowMenuFunction (ul, true, null);
	        }, 1);
	}	
}

function tii_pnav_getPrimaryLi (a)
{
	if (a.parentNode.parentNode.parentNode.nodeName.toUpperCase ()== 'DIV')
	{
		return a.parentNode;
	}
	else
	{
		return a.parentNode.parentNode.parentNode;
	}
}

function tii_pnav_moveToPrevious (li)
{
      var previous = li.previousSibling;
      if (!previous)
      {
        previous = li.parentNode.childNodes
            [li.parentNode.childNodes.length - 1];
      }
      previous.firstChild.focus ();
}

function tii_pnav_moveToNext (li)
{
    var next = li.nextSibling;
    if (!next)
    {
      next = li.parentNode.childNodes.item (0);
    }
    next.firstChild.focus ();
};

function tii_pnav_isUnwantedTextEvent ()
{
  return (navigator.vendor == 'Apple Computer, Inc.'
      && (event.target == event.relatedTarget.parentNode
      || (event.eventPhase == 3
      && event.target.parentNode == event.relatedTarget)));
}
/* end of merging js file 03017200.js*/
/* start of AC_RunActiveContent.js*/
//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
/* end of merging the js file AC_RunActiveContent.js */
/* start of global.js*/
// Copyright 2007 Time.com

tii_addEventHandlerOnElementLoad ('query', 'click', function (event){
			var qBox = typeof event.target != 'undefined' ? event.target : window.event.srcElement;				
			qBox.style.color = '#000';
																 }, false);
var keyevent = tii_issafari || tii_isie ? 'keydown' : 'keypress';
tii_addEventHandlerOnElementLoad ('query', keyevent, 
		function (event){
			var qBox = typeof event.target != 'undefined' ? event.target : window.event.srcElement;				
			qBox.style.color = '#000';
			}, false);

/*Initializes the primary navigation menu 125 milliseconds after the 'topnav' div is loaded  */
tii_callFunctionOnElementLoad ('nav', function ()
{
	var delay = setTimeout (ew_initializeNav, 5);
});

// Start the setMover on window load
tii_callFunctionOnWindowLoad (function ()
{
	setMover ();
});

// Most Popular Event handlers
tii_addEventHandlerOnElementLoad ('tabChange1', 'click', function (event){tabChange(1);}, false);
tii_addEventHandlerOnElementLoad ('tabChange2', 'click', function (event){tabChange(2);}, false);
tii_addEventHandlerOnElementLoad ('tabChange3', 'click', function (event){tabChange(3);}, false);
tii_addEventHandlerOnElementLoad ('tabChange4', 'click', function (event){tabChange(4);}, false);
tii_addEventHandlerOnElementLoad ('tabChange5', 'click', function (event){tabChange(5);}, false);

var keyevent = tii_issafari || tii_isie ? 'keydown' : 'keypress';
tii_addEventHandlerOnElementLoad ('tabChange1', keyevent , function (event){tabChange(1);}, false);
tii_addEventHandlerOnElementLoad ('tabChange2', keyevent , function (event){tabChange(2);}, false);
tii_addEventHandlerOnElementLoad ('tabChange3', keyevent , function (event){tabChange(3);}, false);
tii_addEventHandlerOnElementLoad ('tabChange4', keyevent , function (event){tabChange(4);}, false);
tii_addEventHandlerOnElementLoad ('tabChange5', keyevent , function (event){tabChange(5);}, false);

// Date
var arrayDayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var arrayMonthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); 

function getDateCurrent () {
    var today = new Date() 
    var day = (today.getDay());	
		
    var monthName_List = new Date()
    monthNumber = (today.getMonth());
	
    dayNumber=today.getDate();
    if(dayNumber < 10){
        dayNumber="0" + dayNumber;
    } 
    var yearNumber = today.getYear();
    if(yearNumber < 1000) {
        yearNumber+=1900;
    }
	if (document.getElementById('print'))
	{
	document.write(arrayMonthNames[monthNumber] + " " + dayNumber + ", " + yearNumber);
	}
	else
	{
    document.write(arrayDayNames[day] + ", " + arrayMonthNames[monthNumber] + " " + dayNumber + ", " + yearNumber);	
	}
} 

// Clear field: Clears input text on focus and resets to default text if no text is entered
function clearField(status) 
{
	var srch = document.getElementById('query');
		if ((srch.value == srch.defaultValue) && (status == 'on'))
		{
			srch.value = '';
		}
		if ((srch.value == '') && (status == 'off'))
		{
			srch.value = srch.defaultValue;
		}
} 

/* Top Nav Drop-down */
function ew_initializeNav ()
{
	tii_pnav_initializeDropdownMenu.apply (this, new Array ('nav', ew_pnav_hideOrShowMenuFunction, ew_pnav_changeStateFunction));
} 
							   
/* Hide/show Menu */
function ew_pnav_hideOrShowMenuFunction (menu, hideElseShow, menuParent)
{
		menu.style.left = (hideElseShow ? '-999' : (menuParent.offsetLeft)) + 'px';
} 

/* Change/Clear Status */
function ew_pnav_changeStateFunction (element, isADropdownItem, state)
{
	if (isADropdownItem)
	{
		switch (state)
		{
			case 0:
				element.className = '';
				break;
			case 1:
				element.className = 'active';
				break;
		}
	}
	else
	{
		var anchor = element.getElementsByTagName ('a').item (0);
		var li = anchor.parentNode;
		
		switch (state)
		{
			case 0:
				li.className = li.className.replace(/primactive/gi, '');
				break;
			case 1:
				li.className += (li.className == '' ? '' : ' ') + 'primactive';
				break;
		}
	}
}

// Go To Specials: Links the elements of the select tag to their specific URLs
	function gotoSpecials() 
	{
	document.location.href = document.frmSpecials.selSpecials.options[document.frmSpecials.selSpecials.selectedIndex].value;
	}


// Belt

var moveTouts;

// Sets the belt mover
function setMover ()
{
	var toutsPerShow = 5;
	var moveDelay = 1;
	var widthTraversed = 0;
	var toutTracker = 0;
	var toutCount = 0;
	var directionChangeMultiplier;
	if (tii_isie)
	{
		directionChangeMultiplier = 20;
	}
	else
	{
		directionChangeMultiplier = 40;
	}

	var dotNumber = 2;
	
	var mover = document.getElementById ('mover');
	if (!mover)
	{
		return false;
	}
	mover.style.left = '0px';
	
	// The next line assumes that all the child nodes of mover are touts
	tii_dom_removeWhitespaceTextNodes (mover);
	var beltTouts = mover.childNodes;
	var beltToutsLength = beltTouts.length;
	var beltToutWidth;
	if (beltToutsLength > 0)
	{
		beltToutWidth = beltTouts.item (0).offsetWidth;
	}
	else 
	{
		return false;
	}
	var visibleWidth = toutsPerShow * beltToutWidth;
	
	function moveBelt (event, directionChange)
	{
		if ((event.type == keyevent && event.keyCode != 13) || widthTraversed > 0)
		{
			return false;
		}
		
		function recirculateTouts ()
		{
			if (directionChange > 0)
			{
				if (Math.ceil (toutTracker / beltToutWidth) > 0 )
				{
					toutTracker = toutTracker - beltToutWidth;
					var clonedTout = beltTouts.item (beltToutsLength - 1).cloneNode (true);
					mover.insertBefore (clonedTout, mover.firstChild);
					mover.removeChild(beltTouts.item (beltToutsLength));
					toutCount++;
		}
			}
			if (directionChange < 0)
			{
				if (Math.floor (toutTracker / beltToutWidth) > 0)
				{
					toutTracker = toutTracker - beltToutWidth;
					var clonedTout = mover.childNodes[0].cloneNode (true);
					mover.appendChild (clonedTout);
					mover.removeChild (mover.childNodes[0]);
					mover.style.left = '0 px';
					toutCount++;
				}
			}
		}
		
		moveTouts = setInterval (function () 
		{
			widthTraversed = widthTraversed + directionChangeMultiplier;
			toutTracker = toutTracker + directionChangeMultiplier;
			
			recirculateTouts ();
			if (toutCount >= toutsPerShow)
			{
				// Stop animation 
				clearInterval (moveTouts);
				
				// Set active button 
				if (dotNumber == 1)
				{
					dotNumber = 2;
				}
				else
				{
					dotNumber = 1;
				}
				
				var dot = document.getElementById ('dots')				
				if (!tii_isie){
					dot.style.background= 'url(' + dotNumber + '.gif) 0px 0px no-repeat';
				}else{
					dot.style.backgroundPositionY =  (dotNumber*13 -26) + ' px';
				}

				// Reinitialize variables 
				mover.style.left = '0px';
				beltTouts = mover.childNodes;
				widthTraversed = 0;
				toutCount = 0;
			}
		}, moveDelay);
		
		tii_stopDefaultAction (event);
	}
	
	var leftArrow = document.getElementById ('leftArrow');
	var rightArrow = document.getElementById ('rightArrow');
	if (!leftArrow || !rightArrow)
	{
		return false;
	}
	leftArrow.href = 'javascript:{}';
	rightArrow.href = 'javascript:{}';
	var keyevent = tii_issafari || tii_isie ? 'keydown' : 'keypress';
	tii_addEventHandler (leftArrow, 'click', function (event) { moveBelt (event, 1)}, false);
	tii_addEventHandler (leftArrow, keyevent, function (event) { moveBelt (event, 1)}, false);
	tii_addEventHandler (rightArrow, 'click', function (event) { moveBelt (event, -1)}, false);
	tii_addEventHandler (rightArrow, keyevent, function (event) { moveBelt (event, -1)}, false);
}


// Quigo 
function tiiQuigoSetEnabled(b) {
	_tiiQuigoEnabled = b;
}

function tiiQuigoIsEnabled() {
	if (typeof(_tiiQuigoEnabled) == "boolean") {
		return _tiiQuigoEnabled;
	}
	return true;
}

function tiiQuigoWriteAd(pid, placementId, zw, zh, ps) {
	if (tiiQuigoIsEnabled()) {
		qas_writeAd(placementId, pid, ps, zw, zh, '');
	}
}

// Most Popular & Tools Module in Global Biz
function tabChange(num) {
	tList = "tab"+num;
	tContent = "tabContent"+num;
	var ref = document.getElementById(tList).parentNode;
	if (ref.id == "mostPopular")
	{
		var j=1;
		var k=3;
	}
	else
	{
		var j=3;
		var k=6;		
		//var k=7;
	}
	for (var i=j; i<k; i++) {
		document.getElementById("tab"+i).className = "";
		document.getElementById("tabContent"+i).className = "off";
	}
	document.getElementById(tList).className = "on";
	document.getElementById(tContent).className = "";
}


function tabCloudChange(num) {
	document.getElementById("tabCloud1").className = (num<=3) ? "on" : "";
	document.getElementById("tabCloud2").className = (num>=4) ? "on" : "";
	document.getElementById("tabCloudContent1").className = (num==1) ? "" : "off";
	document.getElementById("tabCloudContent2").className = (num==2) ? "" : "off";
	document.getElementById("tabCloudContent3").className = (num==3) ? "" : "off";
	document.getElementById("tabCloudContent4").className = (num==4) ? "" : "off";
}

// Ad Tag Migration
//var adConfig = new TiiAdConfig("3475.tim"); 
//adConfig.setCmSitename("cm.tim");
//adConfig.setBehaviorTracking(true);

//For Tacoda
var tcdacmd="dt";
/* end of global.js */

/* start of time_init.js*/
/* Initialization and Unobtrusive Javascript Calls */
tii_callFunctionOnElementLoad('playLink', initPageComponents);
/* end of time_init.js*/

/* start of tii_browser_sniffing.js */

/***** TII Global Browser Sniffing Variables *****/

var tii_isopera = typeof window.opera != 'undefined';

var tii_isie = typeof document.all != 'undefined'

   	&& !tii_isopera && navigator.vendor != 'KDE';

var tii_issafari = navigator.vendor == 'Apple Computer, Inc.';
/* end of tii_browser_sniffing.js */
