$(document).ready(function() {
  $('#listing a').click(function(e) {
    var href = $(this).attr('href');
    var item = href.split('/').pop();
    var id = item.match(/^[0-9]+/);

    if (id) {
      e.preventDefault();
      $('#item a').each(function() {
        if ($(this).hasClass('cbox_hidden') === false) {
          var title = $(this).attr('href').split('/').pop();
          $(this).addClass('cbox_hidden').text(title);
          $('#text').hide();
        }
      });

      $.post(path + 'ajax.php', {p: 'load_item_data', id: id}, function(h) {
        document.title = h.title + ' - ' + lang[lge].paintings + ' - daniela baráčková';
        
        $('#text').html(h.description).fadeIn();
        $('#item_' + h.id).html('Loading...').removeClass('cbox_hidden');
        $img = $('<img />');
        $img.attr({ 
          src: path + 'upload/photo/paintings/list/' + h.preview,
          alt: h.title
        })
        if (h.border) {$img.addClass('border');}
        
        $img.load(function() {
          $('#item_' + h.id).html($img);
        });

        // remove slider
        $('#content').css('overflow', 'auto');
        $('#text').css('marginTop', 0);
        $('#content + #slider').remove();
        // add slider if needed
        outer = $('#content').height();
        inner = $('#text').height();
        if (inner > outer) {slider(lang, $('#content'), $('#text'), 'NULL');}
      }, 'json');
    } else {
      return;
    }
  });
});

