﻿function moreInfo(url, elem) {
  url = url + '?type=ajax';
  $(elem).prev().load(url, function() {
    $(elem).prev().slideDown('normal');
  });
  $(elem).next().css('display', 'block');
  $(elem).css("display", "none");
}

function lessInfo(elem) {
  $(elem).prev().prev().slideUp('normal', function() {
    $(elem).prev().prev().html('');
    $(elem).prev().css("display", "block");
    $(elem).css("display", "none");
  });
}

$(document).ready(function() {
  $('.persontag > a, .jobtag > a').each(function() {
    $(this).attr('title', 'Visa alla jobb med taggen ' + $(this).text());
  });

  $('.more').live('click', function() {
    var url = $(this).attr('href');
    moreInfo(url, this);
    return false;
  });

  $('.less').live('click', function() {
    lessInfo(this);
    return false;
  });


  $('#next').css('display', 'none');

  var pageNo = 0;
  var isSearching = false;
  var last = false;
  if (typeof nextPageUrl != 'undefined') {
    $(window).scroll(function() {
      if (!last && $(window).scrollTop() > $(document).height() - ($(window).height() + 64)) {
        if (!isSearching) {
          isSearching = true;
          $('#contentall').append($('<div />').load(nextPageUrl.replace(/-1/gi, ++pageNo) + (nextPageUrl.indexOf('?') < 0 ? '?' : '&') + 'type=ajax', function(responseText) {
            $('#bigloader').remove();
            isSearching = false;
            if (responseText == '') {
              last = true;
            }
            else {
              $('#contentall').append($('<div />').attr('id', 'bigloader'));
            //  $('#contentall').append($('<div />').attr('id', 'bigloader'));
            }
          }));
        }
      }
    });
  }
});
