var delay = 0; /* seconds before the ticker starts ticking */
var speed = 90 /* speed of ticker, smaller is faster */
var speed1 = 90
var speed2 = 90

var position = 0;
var position1 = 0;
var position2 = 0;
var ticking, ticking1;

function scrolldiv(divname,ulname) {

  /* add fade bars */
  
  var ticker = document.getElementById(divname);
  var ticker_top = document.createElement("div");
  ticker_top.className = "ticker_top";
  var ticker_bottom = document.createElement("div");
  ticker_bottom.className = "ticker_bottom";
  ticker.appendChild(ticker_top);
  ticker.appendChild(ticker_bottom);

  /* kill a horrible flickering select bug in Fx1.0 */
  selects = document.getElementsByTagName("select");
  for (i=0;i<selects.length;i++) {
    addEvent(selects[i], 'focus', tick_pause);
    addEvent(selects[i], 'blur', tick);
  }

  /* clone the list to get rid of whitespace near the end of the tick cycle */
  list = document.getElementById(ulname);
  cloned_list_elements = list.cloneNode(true).getElementsByTagName("li");
  cloned_length = cloned_list_elements.length;
  for (i=0;i<cloned_length;i++) {
    list.appendChild(cloned_list_elements[0]);
  }
/**
  ticker_links = document.getElementById(ulname).getElementsByTagName("a");
  for (i=0;i<ticker_links.length;i++) {
    addEvent(ticker_links[i], 'mouseover', tick_pause);
    addEvent(ticker_links[i], 'mouseout', tick);
  } 
***/
 // alert(list.id);
 // ticking = window.setTimeout("tick('" + list.id + "')", (delay * 200));
}
function init()
{
	/***
	scrolldiv(document.getElementById("ticker"),document.getElementById("ticker_list") );
	//alert(document.getElementById("ticker_list1") + " Mamatha");
	scrolldiv(document.getElementById("ticker1"),document.getElementById("ticker_list1"));
	***/
	scrolldiv("ticker", "ticker_list");
	//alert(document.getElementById("ticker_list1") + " Mamatha");
	scrolldiv("ticker1", "ticker_list1");
	
	ticking = window.setTimeout("tick('ticker_list')", (delay * 200));
	ticking1 = window.setTimeout("tick('ticker_list1')", (delay * 200));
	//ticking2 = window.setTimeout("tick('ticker_list2')", (delay * 200));
}

function tick(ulname) {
  //clearTimeout(ticking); /* incase two timeouts have managed to start somehow */  
  list = document.getElementById(ulname);
  list_items = list.getElementsByTagName("li");
 if (ulname == "ticker_list")
	 {
	  if ( (list.offsetHeight / 2) < -position ) {
		/* reset the position and the scrolling of the document incase someones tabbed through */
	     position = 0;
		 document.getElementById(list.id).scrollTop = 0;
		 document.getElementById(list.id).scrollTop = 0;
	     ticking = window.setTimeout("tick('" + ulname + "')", 0);
		 }
	 else

	  {
	    list.style.top = position+"px";
	    position--;
		ticking = window.setTimeout("tick('" + ulname + "')", speed);
	  }
	 }
  else if  (ulname == "ticker_list1")
    {
	 if ( (list.offsetHeight / 2) < -position1 ) {
		/* reset the position and the scrolling of the document incase someones tabbed through */
	     position1 = 0;
		 document.getElementById(list.id).scrollTop = 0;
		 document.getElementById(list.id).scrollTop = 0;
	      ticking1 = window.setTimeout("tick('" + ulname + "')", 0);
		 }
	 else

	  {
	    list.style.top = position1+"px";
	    position1--;
		 ticking1 = window.setTimeout("tick('" + ulname + "')", speed1);
	  }
 } 
else
    {
	 if ( (list.offsetHeight / 2) < -position2 ) {
		/* reset the position and the scrolling of the document incase someones tabbed through */
	     position2 = 0;
		 document.getElementById(list.id).scrollTop = 0;
		 document.getElementById(list.id).scrollTop = 0;
	      ticking2 = window.setTimeout("tick('" + ulname + "')", 0);
		 }
	 else

	  {
	    list.style.top = position2+"px";
	    position2--;
		 ticking2 = window.setTimeout("tick('" + ulname + "')", speed2);
	  }
 } 
}
function tick_pause(ulId) {
	//alert(ulId);
	if (ulId == "ticker_list")
	{
		clearTimeout(ticking);
	}
	else if (ulId == "ticker_list1")
	{
		clearTimeout(ticking1);
	}
	else
	{
		clearTimeout(ticking2);
	}
//  clearTimeout(ticking);
}

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  }
  if (obj.addEventListener) {
    obj.addEventListener( type, fn, false );
  }
  else { }
}

addEvent(window, 'load', init);
