function set_current_section() {

 if ($('#patent').length == 0) {
   $('#footer').append('<div id="patent" class="span-16" style="text-align:center;color:rgb(223, 223, 223);font-size:10px;">NetCosts® Protected by U.S. Patent No. 7,873,541.</div>');
 };
  current_section   = null;
  valid_locations   = ["products", "industries", "about", "contact"];
  current_location  = location.toString();

  for (i in valid_locations) {
    if (current_location.match(valid_locations[i])) {
      current_section = valid_locations[i];
    };
  };

  if (current_section != null) {
    $('#menu li.' + current_section + ' a').addClass('selected');
  };

}

function set_background_height() {
  background_image_height = 342;
  multiples               = Math.floor($('#content').height()/background_image_height);
  background_height       = background_image_height * multiples;
  $('.background').height(background_height);
  $('.background').css('top',$('#header').height());
}

function show_background() {
  $('.background').fadeIn('slow');
}

function display_product_details(to_display_id) {
  var currently_displayed_id = ('#' + $('.currently_showing').attr('id'));
  if ($('.currently_showing').length == 0) {
    $(to_display_id).show();
    $(to_display_id).addClass('currently_showing');
  } else if (to_display_id != currently_displayed_id) {
    $(currently_displayed_id).fadeOut('slow', function(){
      $(currently_displayed_id).removeClass('currently_showing');
      $(to_display_id).fadeIn('slow');
      $(to_display_id).addClass('currently_showing');
    });
  };
}

function check_for_category_exception(item) {
  return item;
}

function get_details_id_from_event_target(event) {
  var target = event.currentTarget.href.match(/#.{1,}/g)[0];
  target     = target.replace('#', '');
  target     = target.replace('-', '_');
  target     = '#details_' + target;
  target     = check_for_category_exception(target)
  return target;
}

function get_details_id_from_element_href(element) {
  var target = element.href.match(/#.{1,}/g)[0];
  target     = target.replace('#', '');
  target     = target.replace(/-/g, '_');
  target     = '#details_' + target;
  target     = check_for_category_exception(target)
  return target;
}

function get_details_id_from_hash(hash) {
  var target = hash;
  target     = target.replace('-', '_');
  target     = '#details_' + target;
  target     = check_for_category_exception(target)
  return target;
}

function select_menu_item(menu_item) {
  $(menu_item).addClass("selected");
}

function remove_selected_menu_item(menu_items) {
  menu_items.removeClass("selected");
}

function toggle_menu_item_selected_state(menu_items, selected_menu_item) {
  remove_selected_menu_item(menu_items);
  select_menu_item(selected_menu_item);
}

function setup_menu_items_click(menu_items) {
  menu_items.click(function(){
    toggle_menu_item_selected_state(menu_items, this);
  });
}

function setup_product_click(products) {
  products.click(function(){
    target = get_details_id_from_element_href(this);
    display_product_details(target);
  });
}
