/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: James Crooke :: http://www.cj-design.com */

var list; // global list variable cache
var tickerObj; // global tickerObj cache
var hex = 255;
var pausenow=false;
var count=0;
var interval=6;
var fadeSpeed = 40; // fade speed, the lower the speed the faster the fade.  40 is normal.

function fadeText(divId) { 
  if(tickerObj)
  {
    if(hex>0) {
      hex-=5; // increase color darkness
      tickerObj.style.color="rgb("+hex+","+hex+","+hex+")";
      tickerObj.childNodes[0].style.color="rgb("+hex+","+hex+","+hex+")";
      setTimeout("fadeText('" + divId + "')", fadeSpeed); 
      
    } else
      hex=255; //reset hex value
  }
}

function initialiseList(divId) { 
  tickerObj = document.getElementById(divId);
  if(!tickerObj)
    reportError("Could not find a div element with id \"" + divId + "\"");
  list = tickerObj.childNodes;
  if(list.length <= 0)
    reportError("The div element \"" + divId + "\" does not have any children");
  for (var i=0; i<list.length; i++) {
    var node = list[i];
    if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
              tickerObj.removeChild(node);
  }
  run(divId, 0);
}

function run(divId, count) {
	
	if(!pausenow){ 
		for (var i=0; i<list.length; i++){
			if(i==count)
	 			list[i].style.display = "block";
	 		else list[i].style.display = "none";
	 	}
	  fadeText(divId);
	  count++;
	  if(count == list.length)
	    count = 0;
	  window.setTimeout("run('" + divId + "', " + count+ ")", interval*1000);
	}
}

function reportError(error) {
  alert("The script could not run because you have errors:\n\n" + error);
  return false;
}

function PauseTicker(){	
	
	if(pausenow){	
		pausenow=false;
		document.ticker.ticker_pause.value='Pause';
		document.ticker.ticker_pause.src='http://www.enneagraminstitute.com/images/pause_button.gif';
		if(count == list.length-1){
   		count=0;
   	}	else	{
   		count++
   	}
   	run('tic',count);	
		
    	
	} else {
		pausenow=true;
    	document.ticker.ticker_pause.value='Resume';
    	document.ticker.ticker_pause.src='http://www.enneagraminstitute.com/images/resume_button.gif';
	}
}

function MoveTicker(direction){
	pausenow=true;
	document.ticker.ticker_pause.src='http://www.enneagraminstitute.com/images/resume_button.gif';
	document.ticker.ticker_pause.value='Resume';
	if(direction=='forward'){
		if(count == list.length-1)
			count=0; 
		else count++;
	} else {
		if(count==0)
			count = list.length-1;
		else count--;
	} 
		
	for (var i=0; i<list.length; i++){
			if(i==count)
	 			list[i].style.display = "block";
	 		else list[i].style.display = "none";
	 	}
}