
$(document).ready(function() {
/*alert($('#parametros').text());*/
  $('#news-feed').each(function() {
    var $container = $(this);
//    /*alert($container.text);*/
//    $container.empty();

    var fadeHeight = $container.height() / 4;
    
    for (var yPos = 0; yPos < fadeHeight; yPos += 2) {
      $('<div></div>').css({
        opacity: yPos / fadeHeight,
        top: $container.height() - fadeHeight + yPos
      }).addClass('fade-slice').appendTo($container);
    }

//    var $loadingIndicator = $('<img/>')
//      .attr({
//        'src': '/imag/loading.gif', 
//        'alt': 'Loading. Please wait.'
//      })
//      .addClass('news-wait')
//      .appendTo($container);
// coloqué el valor del parámetro en un span hidden: #parametros
//    $.get('/m_clasi/clasi_rss.aspx','idr='+($('#parametros').text()), function(data) {
//      $loadingIndicator.remove();
//      $('rss item', data).each(function() {
//        var $link = $('<a></a>')
//          .attr('href', $('link', this).text())
//          .text($('title', this).text());
//          
//  if ($('description', this).text().indexOf("Certifica")===-1){
//        var $headline = $('<h4></h4>').append($link);
//       var str_fecha=$('pubDate', this).text();
//       // ahora proceso los datos como string:
//        var pubMonth = str_fecha.slice(5,7);
//        var pubDay = str_fecha.slice(8,10); 
//        var pubYear = str_fecha.slice(0,4);
//        var pubHora=str_fecha.slice(11,13);
//        var pubMin=str_fecha.slice(14,16);
//      
//        var $publication = $('<div></div>')
//          .addClass('publication-date')
//          .text(pubDay + '/' + pubMonth + '/' + pubYear /*+ ' ' + pubHora + ':' + pubMin*/);
//    
//        var $summary = $('<div></div>')
//          .addClass('summary')
//          .html($('description', this).text());
//        
//        $('<div></div>')
//          .addClass('headline')
//          .append($headline, $publication, $summary)
//          .appendTo($container);
//      }

//      });
      
      var currentHeadline = 0, oldHeadline = 0;
      var hiddenPosition = $container.height() + 10;
      $('div.headline').eq(currentHeadline).css('top', 0);
      var headlineCount = $('div.headline').length;
      var pause;
      var rotateInProgress = false;

      var headlineRotate = function() {
        if (!rotateInProgress) {
          rotateInProgress = true;
          pause = false;
          currentHeadline = (oldHeadline + 1)
            % headlineCount;
          $('div.headline').eq(oldHeadline).animate(
            {top: -hiddenPosition}, 'slow', function() {
              $(this).css('top', hiddenPosition);
            });
          $('div.headline').eq(currentHeadline).animate(
            {top: 0}, 'slow', function() {
              rotateInProgress = false;
              if (!pause) {
                pause = setTimeout(headlineRotate, 5000);
              }
            });
          oldHeadline = currentHeadline;
        }
      };
      if (!pause) {
        pause = setTimeout(headlineRotate, 5000);
      }
      
      $container.hover(function() {
        clearTimeout(pause);
        pause = false;
      }, function() {
        if (!pause) {
          pause = setTimeout(headlineRotate, 250);
        }
      });
    });
  

});



