function get_rss_feed() {
  //clear the content in the div for the next feed.
  $("#jfeed").empty();
 
  //use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
  $.get('/feeds/eb_peak_specific.xml', function(d) {
 
    //find each 'item' in the file and parse it
    $(d).find('item').eq(0).each(function() {
 
      //name the current found item this for this particular loop run
      var $item = $(this);
      // grab the post title
      var title = $item.find('title').text();
      // grab the post's URL
      var link = $item.find('link').text();
      // next, the description
      var description = $item.find('description').text();
      //description = description.truncate({max_length: 200});
      //don't forget the pubdate
      var pubDate = $item.find('pubDate').text();
 
      // now create a var 'html' to store the markup we're using to output the feed to the browser window
      var html = "<div class=\"entry\"><h2 class=\"postTitle\">" + title + "<\/h2>";      
      html += "<div class=\"description\">" + description + "</div>";
      html += "<a class='more-blue' href=\"" + link + "\" target=\"_blank\">visit energy bulletin<\/a><\/div>";
 
      //put that feed content on the screen!
      $('#jfeed').append($(html));  
      $('#jfeed .description').truncate({max_length: 160})
      //$("#jfeed a:last").attr("class", "more-blue");
    });
  });
 
};

function formatText(index, panel) {
    return index + "";
}

function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);    
}

function gup(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

$(document).ready(function() {

  var seq = 1;
  var thisURLf = location.href;
  
  $('#nav li.nv').each(function (i) {
  
    $(this).addClass('n'+seq);    
    if ($(this).hasClass('n1')){ $(this).addClass('n-first'); }    
    seq++;
    
  });
  
  $('#nav li.nv a').each(function (i){
  
    if(thisURLf.match($(this).attr('href'))){
      
      var lParent1 = $(this).parent();
      var lParent2 = $(this).parent().parent();
      if (lParent1.hasClass('nv')){
        lParent1.addClass('selected');
      } else if (lParent2.hasClass('nv')) {
        lParent2.addClass('selected');
      }   
    } 
    
    else if(thisURLf.match('/fellows/')
            || thisURLf.match('/person/')) {
      $('li.n1').addClass('selected'); } 
    
    else if(thisURLf.match('/speakers/') 
            || thisURLf.match('/speaker-list/')
            || thisURLf.match('/request-a-speaker/')) {
      $('li.n2').addClass('selected'); } 
    
    else if(thisURLf.match('/publications/')
            || thisURLf.match('/blog-post/')
            || thisURLf.match('/article/')
            || thisURLf.match('/newsletter/')
            || thisURLf.match('/report/')
            || thisURLf.match('/book/')
            || thisURLf.match('/book-archive/')
            || thisURLf.match('/stories/')
            || thisURLf.match('/reader/')) {
      $('li.n3').addClass('selected'); } 
    
    else if(thisURLf.match('/issues/')) {
      $('li.n4').addClass('selected'); } 
    
    else if(thisURLf.match('/media-library/') 
            || thisURLf.match('/video/')) {
      $('li.n5').addClass('selected'); } 
    
    else if(thisURLf.match('/event/') 
            || thisURLf.match('/calendar/')) {
      $('li.n6').addClass('selected'); } 
    
    else if(thisURLf.match('/supporters/') 
            || thisURLf.match('/story/') 
            || thisURLf.match('/submit-a-story')
            || thisURLf.match('/support/')
            || thisURLf.match('/donate/')) {
      $('li.n7').addClass('selected'); } 
    
     else if(thisURLf.match('/press/') 
            || thisURLf.match('/appearance/')
            || thisURLf.match('/press-coverage/')
            || thisURLf.match('/press-releases/')) {
      $('li.n8').addClass('selected'); } 
    
     else if(thisURLf.match('/about/')) {
      $('li.n9').addClass('selected'); } 
    
  });
  
// Form
    // set focus
    $('input.initial_focus').focus();
    // On submit disable its submit button

  $('#comment_form').submit(function(){
      $('input[type=submit]', this).attr('disabled', 'disabled');
      $('input[type=submit]', this).attr('value', 'Please wait...');
    });
    $('#comment_form').ajaxForm({
     dataType: 'json',
     success: function(data, code, set) {
       if (data.status == 'ok') {
        set.clearForm();
        $('#comment_errors').html("<h2>Thanks for your comment. It is now in moderation and will be reviewed shortly. We appreciate your contribution to the dialogue. </h2>");
        $('#comment_form_wrapper').hide();
        $('a[href$=#comments]').text(""+data.count+" comments");
        var c = '<h3>'+data.params.subject+'</h3><p>From: '+data.params.name+', Just Posted</p><p>'+data.params.body+'</p>';
        var l = $('#comments > p:first');
        if (l === undefined || l.length == 0)
          $('#comments').prepend(c);
        else
          l.after(c);
       } else {
        $('#comment_form input[type=submit]').removeAttr('disabled').attr('value', 'Submit');
        $('#comment_errors').html("<div><h2>Please correct the following problems</h2><p>" + data.message + "</p></div>");
       }
     }
   });
   
   
 // PCI Main
   
   get_rss_feed();
    equalHeight($('.span-5 .s-content'));
    $('.span-5 .s-content .more-block').css({ 'bottom':'18px', 'position':'absolute', 'width':'260px' });
    $('ul.sf-menu').superfish({ autoArrows:false });

    $("input.clearMe").click(function () {
      $(this).attr("value", "").removeClass("clearMe").unbind("click");
    });
  
    $("#category, #person").change(function () {
      var nURL = $(this).attr("value");
      if (nURL != ""){
        document.location.href = nURL;
      }
    });
    
    $('.anythingSlider').anythingSlider({
            easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 7000,                    // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 600,             // How long the slide transition takes
            hashTags: true,                 // Should links change the hashtag in the URL?
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            startText: "play",             // Start text
            stopText: "pause",               // Stop text
            navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
        });      
    
    if (isFellows == "fellows" || isFellows == "speaker-list"){
    $("#people-list h4 a").each( function(){
        var thisText = $(this).text().split(" ");
        var thisClass = thisText[thisText.length-1].charAt(0).toLowerCase();                                  
        $(this).parent().parent().addClass(thisClass);
    });
    
    var arr = new Array();
        
        $('#people-list li').attr("title", function () {
            var title = $(this).children("h4").text();
            title = title.split(" ").reverse();
            arr.push(title);
          return title;
        });
            
        arr = arr.sort();
        
        jQuery.each(arr, function() {
            var cont = $("li[title='" + this + "']");
            $("li[title='" + this + "']").remove();
              $('#people-list ul').append(cont);
        });
        
       var alpha = "abcdefghijklmnopqrstuvwxyz";
       for(var i=0; i<alpha.length; i++)
       {
          var nextChar = alpha.charAt(i);
          var items = $("."+nextChar);
          
          if (items.length > 0){
              $("#people-list-hidden").append("<h3 id=\""+ nextChar +"\">"
                                              + nextChar.toUpperCase()
                                              + "</h3><ul class=\""+ nextChar +"\"></ul>");
              
              $("ul." + nextChar).append($("li." + nextChar));
              
              if ($("#people-nav ul").length == 0){
                  $("#people-nav").append("<ul></ul>");
              }
              if (nextChar == "a") {
                $("#people-nav ul").append("<li class=\"first\"><a href='#"+ nextChar +"'>"
                                           + nextChar.toUpperCase() +"</a></li>");  
              } else if ( nextChar == "z" ) {
                $("#people-nav ul").append("<li class=\"last\"><a href='#"+ nextChar +"'>"
                                           + nextChar.toUpperCase() +"</a></li>");
              } else {
              $("#people-nav ul").append("<li><a href=\"#"+ nextChar +"\">"+ nextChar.toUpperCase() +"</a></li>"); }
             
          } else {
                if (nextChar == "a") {
                  if ($("#people-nav ul").length == 0){
                    $("#people-nav").append("<ul></ul>");
                  }
                $("#people-nav ul").append("<li class=\"first\">" + nextChar.toUpperCase() + "</li>");                
              } else if ( nextChar == "z" ) {
                $("#people-nav ul").append("<li class=\"last\">" + nextChar.toUpperCase() + "</li>");
              } else {
              $("#people-nav ul").append("<li>" + nextChar.toUpperCase() + "</li>"); }
          }
       }
        $("#people-list").remove();
    }
   
   if(isFellows == "request-a-speaker"){
     var speaker = gup('speaker');
     speaker = speaker.split('-');
     var sName = speaker[1] + ' ' + speaker[2];
     sName = sName.toLowerCase();
     $("#speaker-form_dymd_people option").each(function(i){
       if($(this).html().toLowerCase() == sName) {
           $(this).attr("selected", "selected");
       }
     });
   }
   
});