var arrNewsItems = new Array();

	arrNewsItems.push(new Array('March 02 to 07 - Annual Dallas Rhinoplasty - Dallas - US'));
	
	arrNewsItems.push(new Array('April 19 to 25 - ASAPS Annual Meeting - New York - US'));

	arrNewsItems.push(new Array('June 26 to 30 - IPRAS World Congress - Berlin - Germany'));

	arrNewsItems.push(new Array('August - Jornada Carioca de Cirurgia Plástica - Rio - Brazil'));

	arrNewsItems.push(new Array('November 15 - Congresso Brasileiro - Curitiba - Brazil'));


var intTickSpeed = 5000;
var intCursorRate = 10;
var intCursorSpeed = 30;
var intTickPos = 0;
var intCursorPosition = 0;
var tickLocked = false;
var fadeTimerID;
var autoTimerID = 0;
var intMaxCursorPosition;

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("tick").onmouseover = stopTicker;
  document.getElementById("tick").onmouseout = resumeTicker;
  setArticle(0);
  playTicker();
}

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 setArticle(intPos) {
  if (arrNewsItems[intPos]!=null) {
	  tickLocked = true;
	  intCursorPosition = document.getElementById("tick").offsetLeft;
	  setCursorPosition(intCursorPosition);
	  strResults = arrNewsItems[intPos][0];
	  document.getElementById("tick").innerHTML = strResults;
	  intMaxCursorPosition = document.getElementById("tick").offsetLeft + document.getElementById("tick").offsetWidth;
	  tickLocked = false;
	  showCursor();
	  fadeIn();
  }
}

function fadeIn() {
  if (intCursorPosition <= intMaxCursorPosition) {
    intCursorPosition += intCursorRate;
    setCursorPosition(intCursorPosition);
    fadeTimerID = self.setTimeout("fadeIn()", intCursorSpeed);
  } else {
    clearTimeout(fadeTimerID);
    hideCursor();
  }
}

function hideCursor() {
	document.getElementById("cursor").className = "hidden";
}

function showCursor() {
	document.getElementById("cursor").className = "";
}

function setCursorPosition(intCursorPosition) {
	document.getElementById("cursor").style.cssText = "left: " + intCursorPosition + "px;";
	document.getElementById("cursor").style.width = 550-intCursorPosition;
}

function playTicker() {
  if (autoTimerID != 0) {
  	nextArticle();
  }
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}

function stopTicker() {
  clearTimeout(autoTimerID);
}

function resumeTicker() {
  clearTimeout(autoTimerID);
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}

function delayTicker() {
  clearTimeout(autoTimerID);
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed * 2);
}

window.onload = function() {
initButtons();
}