<!--
/*              Utility functions                    */

function addEvent(obj, eventType, fn){
  /* adds an eventListener for browsers which support it
     Written by Scott Andrew: nice one, Scott */
     
  if( eventType === "load" ) {
  	//hack me
  	loadEventList.addLoadEvent(fn);
  	return true;
  }     
     
  if (obj.addEventListener){
    obj.addEventListener(eventType, fn, false);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+eventType, fn);
    return r;
  } else {
	return false;
  }
}

var loadEventList = [];
loadEventList.addLoadEvent = function( fn ) {
	loadEventList[ loadEventList.length ] = fn;
}

loadEventList.fireLoadEvents = function() {
	for(var i=0; i<loadEventList.length; i++) {
		loadEventList[i]();
	}
}

/* the following is a hack to replicate DOMContentLoaded in browsers
   other than Firefox.  It is basically copied from
   http://dean.edwards.name/weblog/2006/06/again/
*/
if(/WebKit/i.test(navigator.userAgent)) { // Safari
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			clearInterval(_timer);
			loadEventList.fireLoadEvents(); // call the onload handler
		}
	}, 100);
} else if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", loadEventList.fireLoadEvents, false);
} else {
  // IE HACK
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id='__ie_onload' defer='defer' src='javascript:void(0)'><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
	if (this.readyState == "complete") {
		loadEventList.fireLoadEvents(); // call the onload handler
	}
};
/*@end @*/
}





addEvent(window, "load", ticker); 

function ticker()
{
	if(!document.getElementById) {
		return;
	}
	
	var headlines=document.getElementById('ticker').getElementsByTagName('li');
	var links=document.getElementById('ticker').getElementsByTagName('a');
	if(headlines.length == 0 ) {
		return;
	}
	
/*	var pause= document.getElementById('ticker-pause');
	var forward= document.getElementById('ticker-forward');
	var back= document.getElementById('ticker-back'); */
	var timeOut, startTimeOut;
	var count=0;
	var currentHeadline='';
	var linkedList=[];
	var nextLetter=0;
/*    pause.onclick=function (){tickerPause(0)}
    forward.onclick=function (){tickerPause(1)}
    back.onclick=function (){tickerPause(-1)} */
    
    startTicking();
    
	if(headlines.length>1) document.getElementById('newsticker').style.display="block";


	
	function startTicking()  {
        nextLetter=''
	    currentHeadline=guTickerLinkText[count];
		timeOut = setInterval (tick, 50);
	}
	
	function tick()  {	
        if (currentHeadline.length>=nextLetter) {
            nextLetter++;
            setInnerText(currentHeadline.substring(0,nextLetter));
            if(nextLetter==1) {
                showHeadline(count)
            }
        }else{
            nextLetter=0;
            clearInterval(timeOut);
            startTimeOut=window.setTimeout(pauseThenTick, 2000);
        }
	}
		
function pauseThenTick () {
            clearTimeout(startTimeOut);
   			hideHeadline(count);
		    if(count<headlines.length-1) {
		        count++;
            }else{
                count=0;
            }
		    startTicking();
		}

    function tickerPause(direction)  {
        hideHeadline(count);
	    restorTrail();
    	if(direction==0 && timeOut!=false) {
			clearInterval(timeOut);
			clearTimeout(startTimeOut);
		    timeOut=false;
		    showHeadline(count);
		} else {
			clearInterval(timeOut);
			clearTimeout(startTimeOut);
            if(direction==0) count++;
            count = getMovedIndex(count,direction);
           	startTicking();
		}
    }
    
    function restorTrail(){
		   setInnerText(guTickerLinkText[count]);
	}
    
   
    
    function setInnerText (value) {
        if(guTickerAnchor[count]!='') {
            links[count].innerHTML=value;
        }else{
            headlines[count].innerHTML=value;
        }    
    }
    
    
    
    function hideHeadline(index) {
    	headlines[index].className='news-ticker-element-hidden';
	}
	
    function showHeadline(index) {
    	headlines[index].className='news-ticker-element-visible';
    }
    
    function getMovedIndex(currentIndex, direction) {
        var nextIndex=currentIndex+direction;
        if(nextIndex>=headlines.length) {   
            nextIndex=0;
		}else if(nextIndex<0) {
            nextIndex=headlines.length-1;
		}  
		return nextIndex;  
    }
}
//-->