var max = 2-1; var min = 0; var curr = 0; function GetXmlHttpObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function showNews(id) { document.getElementById("newsscroller").innerHTML = "Loading"; var xmlHttp = GetXmlHttpObject(); var url = "shownews.php?id=" + id; xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4) { document.getElementById("newsscroller").innerHTML = xmlHttp.responseText; } } if(max == curr) { removeRight(); placeLeft(); } else if(min == curr) { placeRight(); removeLeft(); } else { placeRight(); placeLeft(); } xmlHttp.send(null); } var timer; var resumeTimer; function loadFirst() { showNews(curr); clearInterval(timer); placeRight(); //timer = setInterval ( "autoScroll()", 10000); } function autoScroll() { clearInterval ( resumeTimer ); if(curr < max) { curr = curr + 1; } else { curr = min; } showNews(curr); } function placeLeft() { var elem = document.getElementById("newsleft"); elem.innerHTML = "Prev"; } function removeLeft() { var elem = document.getElementById("newsleft"); elem.innerHTML = ""; } function placeRight() { var elem = document.getElementById("newsright"); elem.innerHTML = "Next"; } function removeRight() { var elem = document.getElementById("newsright"); elem.innerHTML = ""; } function goNext() { clearInterval ( timer ); clearInterval(resumeTimer); resumeTimer = setInterval("loadFirst()", 15000); if((curr + 1) <= max) { curr = curr + 1; } else { curr = min; } showNews(curr); } function goLast() { clearInterval ( timer ); clearInterval(resumeTimer); if((curr - 1) >= min) { curr = curr - 1; } else { curr = max; } showNews(curr); }