jQuery(function() {

    jQuery.getFeed({
        //url: 'proxy.php?url=http://buisconsultancy.nl/cats/rss/',
        url: '/cats-plugged/proxy.php?url=http://buisconsultancy.nl/cats-plugged/last_candidates/last_candidates.php',
        success: function(feed) {

            
            var html = '';
            counter = 0
            for(var i = 0; i < feed.items.length; i++) {
            
                var item = feed.items[i];
                
                if (counter == 0) {
                  html += '<div class="headline">';
                }
                if (counter < 3 ) {
                html += '<a href="'
                + item.link
                + '">'
                + item.title
                + '</a>';
                  
                html += '<p>'
                + item.description
                + '</p>';
                counter += 1;
                } else {
                  html += '</div>';
                  counter = 0;
                }
            }
            
            if ((counter > 0) && (counter <= 3)) {
              html += '</div>';
            }            
            
            jQuery('#scrollup').append(html);

            var headline_count;
            var headline_interval;
            var old_headline = 0;
            var current_headline = 0;
            var rotation_interval = 2500;
            
            $(document).ready(function(){
              headline_count = $("div.headline").size();
              $("div.headline:eq("+current_headline+")").css('top', '5px');
              headline_interval = setInterval(headline_rotate, rotation_interval);
              $('#scrollup').hover(function() {
            	clearInterval(headline_interval);
              }, function() {
            	headline_interval = setInterval(headline_rotate, rotation_interval);
            	headline_rotate();
              });
            });
            function headline_rotate() {
              current_headline = (old_headline + 1) % headline_count;
              $("div.headline:eq(" + old_headline + ")")
            	.animate({top: -205},"slow", function() {
            	  $(this).css('top', '210px');
            	});
              $("div.headline:eq(" + current_headline + ")")
            	.animate({top: 5},"slow");
              old_headline = current_headline;
            }
        }    
    });
});
