/***** 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.'; 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"); 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); /* Start the setMover function on window load */ tii_callFunctionOnWindowLoad (setMover); /* Begin Date function */ 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); } } /* End Date function */ /* Begin Clear field function */ /* 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; } } /* End Clear field function */ /* Links the elements of the select tag to their specific URLs */ /* Begin Go To Specials function */ function gotoSpecials() { document.location.href = document.frmSpecials.selSpecials.options[document.frmSpecials.selSpecials.selectedIndex].value; } /* Begin Go To Specials function */ /* Belt animation */ var moveTouts; /* This function 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 = 90; } 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 && toutCount < 5) { toutTracker = toutTracker - beltToutWidth; var clonedTout = beltTouts.item (beltToutsLength - 1).cloneNode (true); mover.insertBefore (clonedTout, mover.firstChild); mover.style.left = (parseInt (mover.style.left) - beltToutWidth) + 'px'; toutCount++; } } if (directionChange < 0) { if (Math.floor (toutTracker / beltToutWidth) > 0) { toutTracker = toutTracker - beltToutWidth; var clonedTout = beltTouts.item (toutCount).cloneNode (true); mover.appendChild (clonedTout); toutCount++; } } } moveTouts = setInterval (function () { widthTraversed = widthTraversed + directionChangeMultiplier; toutTracker = toutTracker + directionChangeMultiplier; mover.style.left = (parseInt (mover.style.left) + directionChange * directionChangeMultiplier) + 'px'; recirculateTouts (); if (widthTraversed >= visibleWidth) { /* Stop the animation */ clearInterval (moveTouts); /* Set the active button */ if (dotNumber == 1) { dotNumber = 2; } else { dotNumber = 1; } var dot = document.getElementById ('dots') if (!tii_isie){ dot.style.background= 'url(http://img.timeinc.net/time/i/dots' + dotNumber + '.gif) 0px 0px no-repeat'; }else{ dot.style.backgroundPositionY = (dotNumber*13 -26) + ' px'; } /* Clear the unneeded touts */ for (var i = 0; i < toutsPerShow; i++) { if (directionChange > 0) { mover.removeChild (mover.lastChild); } else if (directionChange < 0) { mover.removeChild (mover.firstChild); } } /* Reinitialize the variables */ mover.style.left = '0px'; beltTouts = mover.childNodes; widthTraversed = 0; toutCount = 0; toutTracker = 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); } /***** 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 (); } } /* Create a new element node with attributes */ 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; } /* Removes all the unwanted whitespace text nodes from inside the tree (including tabs, spaces, and line breaks between list items) */ 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); } } } /***** ^^^ TII Global Functions Placed in >TII>Shared>JavaScript>TII LIB - JavaScript Event Listeners ^^^ *****/ /* Adds a function for the window load event */ 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 (); }; } } } /* Calls functionToCall as soon as the targetElement is loaded, even if the document hasn't completely loaded yet. Place the parameter list for functionToCall in order after tii_callFunctionOnElementLoad (targetId, functionToCall), e.g., tii_callFunctionOnElementLoad (targetId, functionToCall, parameter1, parameter 2, parameter 3, ...) */ 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); } } /* Attaches an event handling function to the targetElement as soon as the targetElement is loaded (even if the document hasn't completely loaded yet). */ 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); } } /* Attaches an event handling function to the targetElement. Examples of eventType values are 'mouseover' and 'keyup', as opposed to 'onmouseover' and 'onkeyup'. bubbleEventUpDOMTree is a boolean variable specifying whether the event should activate the event listeners of all the ancestors of the element (up to the window object) */ 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; } /* Removes an event handling function from the targetElement. Examples of eventType values are 'mouseover' and 'keyup', as opposed to 'onmouseover' and 'onkeyup'. bubbleEventUpDOMTree is a boolean variable specifying whether the event should activate the event listeners of all the ancestors of the element (up to the window object) ***NOTE: This function does not support removing anonymous functions; a reference to the added function is needed */ 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; } /* 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); var aHour = new String(hour); 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 all Time articles are published in EST */ articleTZOffsetMS = 240 * 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("UPDATED: "+ 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(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(7); var msButtons = new Array(7); var msWrap; var button; var position; var currPosition; function initPageComponents() { /* Used to load all components on the page */ msDivs[0] = document.getElementById('mainStory1'); msDivs[1] = document.getElementById('mainStory2'); msDivs[2] = document.getElementById('mainStory3'); msDivs[3] = document.getElementById('mainStory4'); msDivs[4] = document.getElementById('mainStory5'); msDivs[5] = document.getElementById('mainStory6'); msDivs[6] = document.getElementById('mainStory7'); msButtons[0] = document.getElementById('a1'); msButtons[1] = document.getElementById('a2'); msButtons[2] = document.getElementById('a3'); msButtons[3] = document.getElementById('a4'); msButtons[4] = document.getElementById('a5'); msButtons[5] = document.getElementById('a6'); msButtons[6] = document.getElementById('a7'); msWrap = document.getElementById('mainStoryWrap'); initPausePlayEvents(); var breakingNews = document.getElementById('breakingNewsImg'); if (breakingNews == null) { paused = false; timer1=setTimeout('timedStory()',7000); } 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; msDivs[0].style.display = (num == 0 ? "block" : "none"); msDivs[1].style.display = (num == 1 ? "block" : "none"); msDivs[2].style.display = (num == 2 ? "block" : "none"); msDivs[3].style.display = (num == 3 ? "block" : "none"); msDivs[4].style.display = (num == 4 ? "block" : "none"); msDivs[5].style.display = (num == 5 ? "block" : "none"); msDivs[6].style.display = (num == 6 ? "block" : "none"); msButtons[0].className = (num == 0 ? "on" : "off"); msButtons[1].className = (num == 1 ? "on" : "off"); msButtons[2].className = (num == 2 ? "on" : "off"); msButtons[3].className = (num == 3 ? "on" : "off"); msButtons[4].className = (num == 4 ? "on" : "off"); msButtons[5].className = (num == 5 ? "on" : "off"); msButtons[6].className = (num == 6 ? "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<6){ currPic++; change(currPic, 1); timer1=setTimeout('timedStory()',7000); }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,2) - 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 ? "/mghome/images/btn_play.gif" : "/mghome/images/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(/mghome/images/btn_playpause.gif)"; position = paused ? "-16 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 */ tii_callFunctionOnElementLoad('playLink', initPageComponents); function Popup(para) { TheNewWin = window.open("/GhanaHome/media/radio/radionew.asp?radio="+para, "popupwin30", "toolbar=0,scrollbars=0,resizable=0,HEIGHT=600,WIDTH=550,location=0,statusbar=0,menubar=0,resizable=0"); TheNewWin.resizeTo(550,600); }