var xmlHttp
var xmlDoc
var xMax 
var x

//----------------------------
var scrollercontent
var scrollerwidth = '500px';
var scrollerheight = '50px';
var flag = true;
var scrollerspeed=1 
scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS 
var mainScrollerDiv
var scrollerDiv1
var scrollerDiv2
var scrollerDiv3

var startPoint 
var lastIndex

var pauseit=1 // Change nothing below! 
scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS 
var copyspeed=scrollerspeed
var iedom=document.all||document.getElementById 
var actualheight='' 
var cross_scroller, ns_scroller 
var pausespeed=(pauseit==0)? copyspeed: 0 

var usrAgt = navigator.userAgent.toLowerCase();
var interval;
if (usrAgt.indexOf("firefox") != -1)
{ interval = 32; }
else if (usrAgt.indexOf("msie") != -1)
{ interval = 26; }
else if (usrAgt.indexOf("netscape") != -1)
{ interval = 24; }
else if (usrAgt.indexOf("opera") != -1)
{ interval = 24; }
else if (usrAgt.indexOf("mozilla/5.0") != -1)
{ interval = 24; }
///alert(interval);


//----------------------------

function LoadTickerData()
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../includes/rotateNews.asp";
//url=url+"?q="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	// assign returned xml doc
	// then node
	// then node count
	xmlDoc=xmlHttp.responseXML.documentElement;
	root = xmlDoc.getElementsByTagName('article');
	xMax =  root.length;
	//alert(xMax);
	populate();
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function goShow()
{
	document.getElementById("maqNews").innerHTML=root[0].childNodes[0].childNodes[0].nodeValue;
}


function scrollscroller()
	{ 
		if (iedom)
			{ 
				if (parseInt(scrollerDiv3.style.left) <= 0 && flag == true) 
				{
					flag = false;
					//scrollerDiv1.style.left = parseInt(scrollerDiv3.style.left) +  parseInt(scrollerDiv3.style.width) + 'px';
					scrollerDiv1.style.left=parseInt(scrollerDiv3.style.left) + parseInt(scrollerDiv3.style.width) + 50 +  'px';
					scrollerDiv2.style.left=parseInt(scrollerDiv1.style.left) + parseInt(scrollerDiv1.style.width) + 50 +  'px';
					//check array content
					if (lastIndex + 1 ==  scrollercontent.length)
					{lastIndex = -1;}
					lastIndex = lastIndex + 1;
					//alert(lastIndex + ' <- for 1')						
					scrollerDiv1.innerHTML=scrollercontent[lastIndex];  
					
					if (lastIndex + 1 ==  scrollercontent.length)
					{lastIndex = -1;}
					lastIndex = lastIndex + 1;
					///alert(lastIndex + ' <- for 2')
					scrollerDiv2.innerHTML=scrollercontent[lastIndex];  
				}
				
				if (parseInt(scrollerDiv3.style.left) + parseInt(scrollerDiv3.style.width) <0 ) 
				{
					//scrollerDiv3.style.left = parseInt(scrollerDiv1.style.left) +  parseInt(scrollerDiv1.style.width) + 'px';
					scrollerDiv3.style.left=parseInt(scrollerDiv2.style.left) + parseInt(scrollerDiv2.style.width) + 50 +  'px';
					//check array content
					if (lastIndex + 1 ==  scrollercontent.length)
					{lastIndex = -1;}
					lastIndex = lastIndex + 1;
					scrollerDiv3.innerHTML=scrollercontent[lastIndex];  
				}
				
				if (parseInt(scrollerDiv2.style.left) + parseInt(scrollerDiv2.style.width) ==0 ) 
				{
					//scrollerDiv3.style.left = parseInt(scrollerDiv1.style.left) +  parseInt(scrollerDiv1.style.width) + 'px';
					flag = true;  
				}
				
				
				scrollerDiv1.style.left=parseInt(scrollerDiv1.style.left)-copyspeed+"px" ;
				scrollerDiv2.style.left=parseInt(scrollerDiv2.style.left)-copyspeed+"px" ;
				scrollerDiv3.style.left=parseInt(scrollerDiv3.style.left)-copyspeed+"px" ;	
			}
	 }
	 
		 
function populate()
{ 

	scrollercontent=new Array(xMax)
	//alert (xMax);
	for (i = 0; i< xMax ; i++)
	{
			
			scrollercontent[i] = root[i].childNodes[0].childNodes[0].nodeValue;
	}
	
	var mainScrollerDiv =  document.getElementById? document.getElementById("mainScrollerDiv") : document.all.mainScrollerDiv;
	startPoint = mainScrollerDiv.style.width;
	
	scrollerDiv1=document.getElementById? document.getElementById("scrollerDiv1") : document.all.scrollerDiv1
	scrollerDiv2=document.getElementById? document.getElementById("scrollerDiv2") : document.all.scrollerDiv1
	scrollerDiv3=document.getElementById? document.getElementById("scrollerDiv3") : document.all.scrollerDiv1
			
			//prepare content
	if(scrollercontent.length >= 3)
	{
		scrollerDiv1.innerHTML=scrollercontent[0];
		//scrollerDiv1.style.width = scrollercontent[0].length + 'px';
		scrollerDiv2.innerHTML=scrollercontent[1]; 
		//scrollerDiv2.style.width = scrollercontent[1].length + 'px';			
		scrollerDiv3.innerHTML=scrollercontent[2];  
		//scrollerDiv3.style.width = scrollercontent[2].length + 'px';			
		lastIndex = 2;
	}
			//prepare start point
	scrollerDiv1.style.left=parseInt(startPoint) + 'px'; 
	scrollerDiv2.style.left=parseInt(scrollerDiv1.style.left) + 500 + 50 +  'px';
	scrollerDiv3.style.left=parseInt(scrollerDiv2.style.left) + 500 + 50 +  'px';
	//alert(scrollerDiv1.style.left);
	//alert(scrollerDiv2.style.left);
	//alert(scrollerDiv3.style.left);
	
	
	lefttime=setInterval("scrollscroller()",interval) 
}		 