﻿function rss_ticker(url) {
  // Create ticker div
  document.write('<div id="ticker" onmouseout="startit();" onmouseover="stop();">Učitavam oglase...</div>');

  // Create XMLHttpRequest object
  try {
   xh = new ActiveXObject('Msxml2.XMLHTTP');
  }
  catch(e) {
    try {
      xh = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch(oc) {
      xh = null;
    }
  }
  if(!xh && typeof XMLHttpRequest != 'undefined') xh = new XMLHttpRequest();

  // Get the RSS feed
  xh.open('GET', url, true);
  xh.onreadystatechange = function() {
    if (xh.readyState == 4) {
      parse_data(xh.responseText);
    }
  }
  xh.send(null);
}

// Parse the RSS feed and write to the ticker div
function parse_data(data) {
  var pos = 0;
  var ticker = document.getElementById('ticker');
  ticker.innerHTML = '';
  while((pos = data.indexOf('<item>', pos+1)) != -1) {
    title_b = data.indexOf('<title>', pos);
    title_e = data.indexOf('</title>', pos);
    title_s = data.substr(title_b+7, title_e-title_b-7);

    link_b = data.indexOf('<link>', pos);
    link_e = data.indexOf('</link>', pos);
    link_s = data.substr(link_b+6, link_e-link_b-6);

    ticker.innerHTML += '<a href="'+link_s+'" target="_blank">'+title_s+'</a><br /><br />';
  }
}