//HIDE TOPLIST
var t;

if (document.getElementById('toplist')) {
    document.getElementById('toplist').style.visibility = "hidden";
}



$(document).ready(function () {
 
  $.post('/images/design/javascript/feedproxy.asp?feed=http://www.naturoghelse.dk/shop/top5forside-308c1.rss&number=5&random=false', function (d) {
  
    var categoryName = $(d).find('items').attr("name");
    var count = 0;
    $(d).find('item').each(function () {
      var $item = $(this);
      var title = $item.find('title').text();
      var link = $item.find('link').text();
      var html = '<div class="rssTitle">' + title + '</div>';
      html += '<div class="rssLink">' + link + '</div>';
      $('#myContent').append($(html));
      count++;

       if (count == 5) {
      sortTop5();
        }
    });
  }, 'xml');
});

function sortTop5() {

    if (document.getElementById('toplist')) {

        document.getElementById('toplist').style.visibility = "visible";
        var goRSStransform = false;

        var myContent = document.getElementById('myContent');
        var allDIV = myContent.getElementsByTagName('DIV');
        var titleRSS = [];
        var linkRSS = [];
        var allAtags = document.getElementById('toplist').getElementsByTagName('A');
        var count = 0;

            for (var i = 0; i < allDIV.length; i++) {
                if (allDIV[i].className == "rssTitle") {
                    titleRSS.push(allDIV[i].innerHTML);
                }
                if (allDIV[i].className == "rssLink") {
                    linkRSS.push(allDIV[i].innerHTML);
                }
            }

            for (var x = 0; x < allAtags.length; x++) {
                if (allAtags[x].className == "newestA") {
                    allAtags[x].href = linkRSS[count];
                    allAtags[x].innerHTML = titleRSS[count];
                    count++;
                }
            }

            myContent.innerHTML = "";
            
        
    }
}
        
        
        
