jQuery(function() {
  jQuery.extend({
    settings: { imagesTotal: parseInt(jQuery('.house_pic').attr('total')), imagesCurrent: 1 }
  });
  imagesNav();
})

imagesNav = function() {
  if (jQuery.settings['imagesTotal'] > 1) {
    jQuery('.house_pic .prev').hide().click(function() { prevImage() });
    jQuery('.house_pic .next').click(function() { nextImage() });
  }
}

nextImage = function() {
  jQuery('.house_pic img:visible').fadeOut('normal', function() {
    jQuery.settings['imagesCurrent'] += 1;
    jQuery('.house_pic .image-'+ jQuery.settings['imagesCurrent']).fadeIn('normal');
    jQuery('.house_pic .prev:hidden').show();
    if (jQuery.settings['imagesCurrent'] == jQuery.settings['imagesTotal']) {
      jQuery('.house_pic .next:visible').hide();
      jQuery('.house_pic .prev:hidden').show();
    }
    jQuery('.house_pic .counter').html(jQuery.settings['imagesCurrent'] +' van '+ jQuery.settings['imagesTotal']);
  });
}

prevImage = function() {
  jQuery('.house_pic img:visible').fadeOut('normal', function() {
    jQuery.settings['imagesCurrent'] -= 1;
    jQuery('.house_pic .image-'+ jQuery.settings['imagesCurrent']).fadeIn('normal');
    jQuery('.house_pic .prev:hidden').show();
    if (jQuery.settings['imagesCurrent'] == 1) {
      jQuery('.house_pic .prev:visible').hide();
      jQuery('.house_pic .next:hidden').show();
    }
    jQuery('.house_pic .counter').html(jQuery.settings['imagesCurrent'] +' van '+ jQuery.settings['imagesTotal'])
  });
}
