$(document).ready(function() {
  
  // adding hover state for item
  $('.g_results_item_border').hover(function() {
    $(this).addClass('g_results_item_border_hover').find('.g_results_item_more_button').addClass('g_more_hover');    
  }, function() {
    $(this).removeClass('g_results_item_border_hover').find('.g_results_item_more_button').removeClass('g_more_hover');
  });
  
  // adding more info toggle
  $('.g_results_item_more_button').click(function() {moreInfoToggle($(this).parent().parent());});
  
  // inserting split in paging and removing margin on first element
  $('.g_results_paging a').not('.last').after('|');
  $('.g_results_paging a:first-child').css('margin-left','0');
  
  // attaching area narrowing foldout
  $('.g_results_area ul li a').click(function() {
    $(this).blur();
    $(this).siblings('ul').slideToggle('slow');
    return false;
  });

  // attaching area narrowing click on checkbox'
  $('.g_results_area ul li input').click(function() {
    if ($(this).siblings('a').attr('href')) {
      window.location = $(this).siblings('a').attr('href');
    }    
  });

  // hiding specialities above the count of 4 and creating a show link  
  $('.g_list_list_special').each(function(index) {
    if ($('li', this).size() > 4) {
      $('li', this).each(function(index) {if (index > 3) {$(this).addClass('g_hide_text')}});
      $(this).after('<a href="#"  style="color:#000;text-decoration:underline">Lęs mere</a>')
      $(this).siblings('a').click(function() {
        $('li', $(this).parent()).each(function(index) {
          $(this).removeClass('g_hide_text');
        });
        $(this).remove();
        return false;
      });
    };    
  });

  // hiding industries above the count of 10 and creating a show link  
  $('.g_results_industries ul').each(function(index) {
    if ($('li', this).size() > 10) {
      $('li', this).each(function(index) {if (index > 9) {$(this).hide()}});
      $(this).after('<p style="margin:10px 0"><a href="#" style="color:#000;text-decoration:underline">Se flere brancher</a></p>')
      $(this).siblings('p').click(function() {
        $('li', $(this).parent()).each(function(index) {
          $(this).show();
        });
        $(this).remove();
        return false;
      });
    };    
  });

  // calculate the size of the shortnav bar and appending start and end graphics
  $('.g_list_shortnav ul').each(function(index) {
    var barWidth = 20 // total width of end-graphics
    $('li', this).each(function(index) {
      barWidth += $(this).outerWidth();
    });
    $(this).parent()
      .prepend('<img src="../images/g_search_result_item_bar_left.gif" style="float:left" alt="" />')
      .append('<img src="../images/g_search_result_item_bar_right.gif" style="float:left" alt="" />')
      .width(barWidth);
      
  });
  
  // attaching target search form input description
  $('.g_target_search_form .input_text').blur(function() {
    if ($(this).val() == '') {
        $(this).val($(this).attr('title')).addClass('light');
    }    
  });

  $('.g_target_search_form .input_text').focus(function() {
    if ($(this).val() == $(this).attr('title')) {
        $(this).val('').removeClass('light');
    }    
  });
    
  $('.g_target_search_form .input_text').addClass('light').blur();


    // attachng profil links hover on search result
    
    $('.g_list_result').each(function() {    
        $(this).hover(function() {
            $('.g_list_result_links', this).css('visibility', 'visible');
        },function() {
            $('.g_list_result_links', this).css('visibility', 'hidden');    
         });
    });
});

