//links - Add your link and copy in the array


var arrNewsItems = new Array();
arrNewsItems.push(new Array('URGENT APPEAL to help ShelterBox responding to the destruction in Haiti, by raising funds', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('Click Here to view our latest News', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('ShelterBox - Tom Henderson OBE !', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('Annual Triggshire Christmas Concert', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('Thanks for Life - End Polio Now Programme - India', 'http://www.rotaryclubwadebridge.org/w_ss_india.cfm'));

arrNewsItems.push(new Array('Shelterbox - Emergency Pacific Appeal', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('Shelterbox - aid en-route to storm-ravaged El Salvador', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('More Donations to local Charities', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('News of our Memory Cafe', 'http://www.rotaryclubwadebridge.org/sje3.cfm?sje=2'));

arrNewsItems.push(new Array('Presentation to Wadebridge Youth Project', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array('Rotary Club of Wadebridge Presentation to local Army Cadet Force', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));

arrNewsItems.push(new Array("The latest Wheels News - one of the great attractions in Cornwall, held every year", 'http://www.rotaryclubwadebridge.org/sje2.cfm?sje=7'));

arrNewsItems.push(new Array('Our Club President welcomes you', 'http://www.rotaryclubwadebridge.org/presi.cfm'));

arrNewsItems.push(new Array('Car Boots every Saturday at 4 p.m. (weather permitting) at The Royal Cornwall Showground', 'http://www.rotaryclubwadebridge.org/dbpage.cfm?sje=26'));


var intTickSpeed = 9000;
var intTickPos = 0;
var tickLocked = false;
var fadeTimerID;
var autoTimerID = 0;
var intTypeSpeed = 20;
var intCurrentPos = 0;
var currentText = '';
var currentLink = '';
var strText = '';
var isFirstPass = true;


// Buttons - Please don't edit below 

function initButtons() {
  var kids = document.getElementsByTagName('img');
  for (var i=0; i < kids.length; i++) {
    kids[i].onclick = buttonClick;
    kids[i].onmousedown = buttonDown;
    kids[i].onmouseup = buttonUp;
    kids[i].oncontextmenu = buttonMenu;
  }
  //document.getElementById("tickContentLink").onmouseover = stopTicker;
  //document.getElementById("tickContentLink").onmouseout = resumeTicker;
	getLinkElems();
	playFirstTicker();
}
function buttonMenu(e) {
	return false;
}
function buttonDown(e) {
	if (!e) var e = window.event;
	if ((tickLocked == false) && (e.button != 2)) {
		document.getElementById(this.id).style.cssText = "margin: 2px 0px 0px 2px;";
	}
}
function buttonUp(e) {
	if (!e) var e = window.event;
	if ((tickLocked == false) && (e.button != 2)) {
		document.getElementById(this.id).style.cssText = "";
	}
}
function buttonClick(e) {
  delayTicker();
  if (this.id == "back") {
    prevArticle();
  } else if (this.id == "next") {
    nextArticle();
  }
}
function prevArticle() {
  if (tickLocked == false) {
	  if (intTickPos == 0) {
	    intTickPos = arrNewsItems.length-1;
	  } else {
	    intTickPos--;
		}
		setArticle(intTickPos);
	}
}
function nextArticle() {
	if (tickLocked == false) {
	  if (intTickPos == arrNewsItems.length-1) {
	    intTickPos = 0;
	  } else {
	    intTickPos++;
		}
		setArticle(intTickPos);
	}
}
function typeText() {
	if(intCurrentPos < currentText.length) {
		strText += currentText.charAt(intCurrentPos);
		setSpan(strText,currentLink);
		intCurrentPos++;		
	} else if (intCurrentPos == currentText.length) {
		strText += currentText.charAt(intCurrentPos);
		setSpan(strText,currentLink);
		clearInterval(typeInterval);
		hideCursor();
	} else if (intCurrentPos > currentText.length){
		setSpan(strText,currentLink);
		clearInterval(typeInterval);
		hideCursor();
	}
}
function setSpan(strText, strLink) {
	var tickElem = document.getElementById("tick");
		var tickFirstChild =  tickElem.firstChild;
		var tickLinkElem = document.createElement("a");
		tickLinkElem.setAttribute('href', strLink);
    tickLinkElem.setAttribute('target', '_top');
		//tickLinkElem.setAttribute('id', 'tickContentLink');
		tickText = document.createTextNode(strText);
		tickLinkElem.appendChild(tickText);
		tickElem.replaceChild(tickLinkElem,tickFirstChild);
		getLinkElems();
}
function getLinkElems() {
	var tickerElem = document.getElementById("tick"); 
	var tickerAElem = tickerElem.getElementsByTagName("a"); 
	for (var i=0; i < tickerAElem.length; i++) {
    tickerAElem[i].onmouseover = stopTicker;
   	tickerAElem[i].onmouseout = resumeTicker;
  }
}

function setArticle(intPos) {
	if(arrNewsItems[intPos]!=null) {
		tickLocked = true;
		intCurrentPos = 0;
		strText = '';
		setSpan('', '#');
		showCursor();
		currentText = arrNewsItems[intPos][0];
		currentLink = arrNewsItems[intPos][1];
		typeInterval = setInterval( "typeText()", intTypeSpeed);
		tickLocked = false;
  }
}
function playTicker() {
  isInFirstTimeout = false;
	if (autoTimerID != 0) {
		clearInterval(typeInterval);
		nextArticle();
  }
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}
function playFirstTicker() {
	if(isFirstPass == true) {
		hideCursor();
		setSpan(arrNewsItems[0][0],arrNewsItems[0][1]);
		isFirstPass = false;
		typeInterval = setInterval('',0);
		isInFirstTimeout = true;
		autoTimerID = self.setTimeout("playFirstTicker()", intTickSpeed);
	}
	else if(isFirstPass == false) {
		clearTimeout(autoTimerID);
		isInFirstTimeout = false;
		setArticle(intTickPos);
		playTicker();
	}
}
function stopTicker() {
	clearTimeout(autoTimerID);
}
function resumeTicker() {
	clearTimeout(autoTimerID);
	autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}
function delayTicker() {
  clearTimeout(autoTimerID);
	clearInterval(typeInterval);
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed * 2);
}
function hideCursor() {
	document.getElementById("cursor").className = "hidden";
}

function showCursor() {
	document.getElementById("cursor").className = "";
}
initButtons();