var slideSpeed = 2;
var slideStep = 1;
var newsBoxPadding = 3;

function startRequest()
{
  url = "http://localhost/news.php";
  startGETRequest(url, onComplete, onEnd);
}

function onEnd()
{
}

function startNewsShow()
{
  var div = document.getElementById("newsBoxDiv");

  yPos = parseInt(div.style.top);
  yPos -= slideStep;
  height = parseInt(div.offsetHeight);
  if(yPos < -height){
    yPos = parseInt(div.parentNode.offsetHeight);
  }
  div.style.top = yPos + "px";
}

function onComplete(text, xml)
{
  if(text == "error") return;

  var newsBox = document.getElementById("newsBox");
  var div = document.createElement("div");
  div.id = "newsBoxDiv";
  div.className = "newsBoxDiv";
  newsBox.appendChild(div);

  div.style.width = (div.parentNode.clientWidth - 
                     2 * newsBoxPadding) + "px";
  div.style.top = div.parentNode.offsetHeight + "px";


  items = text.split("\n\n");

  for(i = 0; i < items.length; i++){
    elements = items[i].split("\n");
    
    var pTitle = document.createElement("p");
    pTitle.className = "pTitle";
    pTitle.innerHTML = elements[0];
    div.appendChild(pTitle);

    var pDescription = document.createElement("p");
    pDescription.className = "pDescription";
    pDescription.innerHTML = elements[1];
    div.appendChild(pDescription);

    var pLink = document.createElement("a");
    pLink.className = "pLink";
    pLink.innerHTML = "Wiêcej";
    pLink.href = elements[2];
    div.appendChild(pLink);

    div.appendChild(document.createElement("br"));
    div.appendChild(document.createElement("br"));
  }
  setInterval("startNewsShow();", slideSpeed);
}
