document.observe('dom:loaded', function () {
  // add dropdown actions
  var top_nav_lis = $$('#top_nav .nav_li');
  if (top_nav_lis) {
    top_nav_lis.each(function(el) {
      var child_menu = el.select('ul');
      if (child_menu.length) {
        child_menu = child_menu[0];
        el.observe('mouseover', function(e) {
          var child_menu = this.select('ul')[0];
          child_menu.addClassName('selected');
        });
        el.observe('mouseout', function(e) {
          var child_menu = this.select('ul')[0];
          child_menu.removeClassName('selected');
        });
        child_menu.observe('mouseover', function(e) {
          this.addClassName('selected');
          this.up(0).select('a')[0].addClassName('selected');
        });
        child_menu.observe('mouseout', function(e) {
          this.removeClassName('selected');
          this.up(0).select('a')[0].removeClassName('selected');
        });
      }
    });
  }

  var header_nav_lis = $$('#header_nav .nav_li');
  if (header_nav_lis) {
    header_nav_lis.each(function(el) {
      var child_menu = el.select('ul');
      if (child_menu.length) {
        child_menu = child_menu[0];
        el.observe('mouseover', function(e) {
          var child_menu = this.select('ul')[0];
          child_menu.addClassName('selected');
        });
        el.observe('mouseout', function(e) {
          var child_menu = this.select('ul')[0];
          child_menu.removeClassName('selected');
        });
        child_menu.observe('mouseover', function(e) {
          this.addClassName('selected');
          this.up(0).select('a')[0].addClassName('selected');
        });
        child_menu.observe('mouseout', function(e) {
          this.removeClassName('selected');
          this.up(0).select('a')[0].removeClassName('selected');
        });
      }
    });
  }

  if ($('benefits_dropdown')) {
    var verticalAccordion = new accordion('benefits_dropdown', {
      classNames : {
        toggle : 'benefits_toggle',
        toggleActive : 'benefits_toggle_active',
        content : 'benefits_text'
      },
      afterFinish : function() {
        // find the element that has just opened and scroll the window to it
        var el = $$('#benefits_dropdown .benefits_toggle_active')[0];
        if (el) {
          el.scrollTo();
        }
      }
    });

    var hash = unescape(self.document.location.hash.substring(1));
    if (hash) {
      var el = $(hash);
      var idx = $$('#benefits_dropdown .benefits_toggle').indexOf(el);
      verticalAccordion.activate($$('#benefits_dropdown .benefits_toggle')[idx]);
    }
  }

/*
  if ($$('.page_resources')) {
    // for each list
    $$('.category_div').each(function(item, index) {
      var max_height = 0;
      // find all the elements within this item
      var children = item.select('.resource_div');
      // find the maximum height
      children.each(function(child, index) {
        var child_height = child.getHeight();
        if (child_height > max_height) {
          max_height = child_height;
        }
      });
      // set the height for all items in the list
      children.each(function(child, index) {
        child.setStyle({height: max_height+'px'});
      });
    });
  }
*/
  subject_input = $('Form_ContactForm_Subject');
  if (subject_input) {
    subject = queryString('subject');
    if (subject.length) {
      subject_input.value = decodeURIComponent(subject);
    }
  }

});

function queryString(parameter) {
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;

  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return false; //Here determine return if no parameter is found
  }
}
