// for printing different parts of the page
function printPage(type) {
  $('#print-css').attr('href','/css/print-' + type + '.css');
  window.print();
}

// onload function
$(document).ready(function(){
  
  // ids for 1st menu levels on index page
  $('#menu.index-menu li:eq(0)').attr('id','brown').next().attr('id','darkblue').next().attr('id','blue');
  
  // sliding menu
  $('#menu.index-menu > ul > li').hover(function(){
    $(this).children('ul').show();
  },function(){
    $(this).children('ul').hide();
  });
  
  // if there are images with class="image-with-border"
  if ($('.image-with-border').length) {
    
    // border wrap for images
    $('.image-with-border').each(function(){
     /* $(this).parent().append('<div class="image-with-border-block"><div class="image-top-border"></div><div class="image-top-border position-right"></div><img src="'+ $(this).attr('src') +'" class="image-with-border" alt="" /><div class="image-bottom-border"></div><div class="image-bottom-border position-right"></div></div>\n').end().remove();*/
    });
    
    // image numeration on some pages
    var photo_number = 1;
    $('#content > .image-with-border-block').each(function(){
      $(this).prepend('<p class="photo-number">' + (photo_number++) + '</p>');
    });
    
  }
  
  // image for loading
  loading_image = '/images/skeleton/loading.gif';
  $('#image').attr('src',loading_image);
  
  // image zoom open
  $('.image-with-border').click(function(){
    $('#image-zoom').show();
    var loader = new Image();
    loader.onload = function(){
      $('#image-loading').hide();
      $('#image').removeClass('loading').attr('src',loader.src);
      $('#image-print').show();
    };
    loader.src = $(this).attr('src').replace('-thumb','');
  });
  
  // image zoom close
  var hide_image = true;
  $('#image-zoom, #print').click(function(){
    if ($(this).attr('id') == 'print') hide_image = false;
    if (hide_image) {
      $('#image-zoom').hide();
      $('#image-print').hide();
      $('#image-loading').show();
      $('#image').addClass('loading').attr('src',loading_image);
    }
    if ($(this).attr('id') == 'image-zoom') hide_image = true;
  });
  
  // for catalog pages with tables
  $('#images-right').prepend('<col /><col class="image-width" />');
  $('#images-middle').prepend('<col /><col class="image-width" /><col />');
  $('#images-right, #images-middle').attr({
    'class': 'reset',
    'cellpadding': 0
  });
  
});
