var freePressBar = {

  init: function(proxy){

    if (proxy) {
      $.get(proxy,function(data){

        $('head').append('<link rel="stylesheet" href="http://tools.freepress.net/fp-bar/fp-bar.css" type="text/css" media="screen" charset="utf-8">'); 

        $('body').append(data); 

        $('html').addClass('fp-bar');
        
        function hideDropdowns() {
          for (var i = 0; i < $('.free_press_bar_nav_link').length; i++) {
            content_to_position = '#' + $('.free_press_bar_nav_link').parent().get(i).id + '_content';
            if ($(content_to_position).css('top') == '31px') {
              var height = $(content_to_position).height();
              $(content_to_position).animate({'top': -(height+18)}, 200);
            }
            $('#free_press_bar_overlay').css('display', 'none');    
          };
        }

        $('.free_press_bar_nav_link').click( function (e) {
          e.preventDefault();
          var content_to_show = '#' + $(this).parent().get(0).id + '_content';
          position = $(content_to_show).css('top');
          if ($(content_to_show).css('top') != '31px') {
            hideDropdowns();
            $(content_to_show).animate({'top': '31px'}, 200);
            $('#free_press_bar_overlay').css('display', 'block');    
          } else {
            hideDropdowns();
          }
        });

        $('.free_press_close_dropdown').click( function () {
          hideDropdowns();
        });

        $('#free_press_bar_overlay').bind("click", function () {
          hideDropdowns();
        });

      });

    };
  }
  
};

