$(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();
      $('#text').hide();

      $.post(path + 'ajax.php', {p: 'load_item_data', id: id}, function(h) {
        document.title = h.title + ' - ' + lang[lge][h.type] + ' - daniela baráčková';
        $('#text').html(h.description).fadeIn();
        $('#item').html(h.item);

        // bind colorbox
        $('#item a').colorbox({
          transition: 'fade',
          opacity: '0.85',
        current: '{current}/{total}',
        previous: lang[lge].previous,
        next: lang[lge].next,
        close: lang[lge].close,
        loop: false
        });

        $('#item a.cbox_video').each(function() {
          var dim = $(this).attr('dim').split('|');
          
          $(this).colorbox({
            transition: 'fade',
            opacity: '0.85',
        		current: '{current}/{total}',
        		previous: lang[lge].previous,
        		next: lang[lge].next,
        		close: lang[lge].close,
        		loop: false,
        		iframe: true,
            width: dim[0],
            height: dim[1]
          });
        });
        
        // 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;
    }
  });
});

