

function type()
{

  if (document.getElementById)
  {
	
			
	    var dest=document.getElementById('scroller-v');
		   if (dest)
		   {
		      dest.innerHTML='<a href=\"' + newsURL[i] + '\" id=\"newsTickerIndex\" class=\"' + i + ' \">' + newsTitle[i].substr(0, currentChar)  + '</a>';
		      currentChar++
			      if (currentChar>newsTitle[i].length)
			      {
			        currentChar=1;
					
						if(i<newsURL.length-1)
						{
							i = i + 1;
							text = newsTitle[i];
						}
						else
						{
							i = 0;
							text = newsTitle[i];
						}
					
					timeOut = setTimeout("type()", 3000); // setTimeout("type()", 3000);
				
					
			      }
			      else
			      {
				  	timeOut = setTimeout("type()", delay);
				
				  }
				  
		    } // if (dest)
			
	
		

  } // if(document.getElementById)
  
}


function displayItem()
{
document.getElementById('scroller-v').innerHTML = '<a href=\"' + newsURL[i] + '\" id=\"newsTickerIndex\" class=\"' + i + ' \">' + newsTitle[i]  + '</a>';
}


function getCurrentIndex()
{
return parseInt(document.getElementById('newsTickerIndex').className);
}

function changePlayButton(doPlay)
{
if(doPlay==1)
{
pausebutton.firstChild.data='<img src=\"http://www.compareandsave.com/images/template/tick-play.gif\" />';

pausebutton.onclick=function()
{play(1);}
}
else
{
pausebutton.firstChild.data='<img src=\"http://www.compareandsave.com/images/template/tick-pause.gif\" />';
pausebutton.onclick=function()
{pause();}
}


}

function pause()
{
i = getCurrentIndex();
displayItem();
stop();
changePlayButton(1);
currentChar=1;
incrementIndex();
}

function play(resume)
{
changePlayButton(0);
if(resume)
{
timeOut = setTimeout("type()", 1);
}
else
{
timeOut = setTimeout("type()", 3000);
}
}

function stop()
{
clearTimeout(timeOut);
}

function incrementIndex()
{
if(i < newsTitle.length - 1)
	{
		i = i + 1;
	}
	
	else
	{
		i = 0;
	}
	
}

function goForward() 
{
i = getCurrentIndex();
	stop();
	
incrementIndex();
	
	currentChar=1;
	text = newsTitle[i];
	changePlayButton(0);
	type();


}

function goBack() 
{
 i = getCurrentIndex();
	stop();
	
	if(i!=0)
	{
		i = i - 1;
	}
	
	else
	{
		i = (newsTitle.length - 1);
	}
	
	
	currentChar=1;
	text = newsTitle[i];
	changePlayButton(0);
	type();

}

window.onload = function() {


newsURL=new Array(5);
newsTitle=new Array(5);

newsURL[0] = "http://www.compareandsave.com/news/car-insurers-tougher-on-mobile-phone-offenders/";
newsTitle[0] = "Car insurers tougher on mobile phone offenders";

newsURL[1] = "http://www.compareandsave.com/news/abbey-cuts-some-mortgage-rates/";
newsTitle[1] = "Abbey cuts some mortgage rates";

newsURL[2] = "http://www.compareandsave.com/news/first-time-buyer-rescue-plan/";
newsTitle[2] = "First-time buyer ‘rescue plan’";

newsURL[3] = "http://www.compareandsave.com/news/120-for-basic-rate-taxpayers/";
newsTitle[3] = "£120 for basic rate taxpayers";

newsURL[4] = "http://www.compareandsave.com/news/british-gas-prices-may-increase-again/";
newsTitle[4] = "British Gas prices may increase again";


delay=50;
currentChar=1;
text = newsTitle[0];
i=0;
destination="scroller-v";

pausebutton = document.getElementById('pause');
forwardbutton = document.getElementById('goForward');
backbutton = document.getElementById('goBack');

pausebutton.style.cursor='pointer';
forwardbutton.style.cursor='pointer';
backbutton.style.cursor='pointer';

pausebutton.onclick=function()
{pause();}

forwardbutton.onclick=function()
{goForward();}

backbutton.onclick=function()
{goBack();}

type();

}


