$(document).ready(function(){

//ADJUSTING HEIGHT
$('#content_1, #content_3').height($('#content_2').height());    

//MENU CLASS
$('#navigation li a[href^="'+page+'"]').addClass('active');

//SLIDESHOW
     var total = $("#img_box img").length;


     $("#imglink1 img").css({
         "border-color": "#666",
         "top": "-5px"
     });

     $(".thumblink").click(function() {
         var imgnumber = parseInt($(this).attr('id').replace("imglink", ""));
         var move = -($("#img"+imgnumber).width() * (imgnumber - 1));

         $("#img_box").animate({
             left: move
         }, 500);

         $("#imgthumb_box").find("img").removeAttr("style");
         $(this).find("img").css({
             "border-color": "#666",
             "top": "-5px",
             "border-top-width": "-5px"
         });
         return false;
     });

     $("#navigate a").click(function() {
         var imgwidth = $("#img1").width();
         var box_left = $("#img_box").css("left");
         var el_id = $(this).attr("id");
         var move, imgnumber;

         if (box_left == 'auto') {
             box_left = 0;
         } else {
             box_left = parseInt(box_left.replace("px", ""));
         }

         // Если нажата кнопка для перехода на предыдущее изображение
         if (el_id == 'linkprev') {
             if ((box_left - imgwidth) == -(imgwidth)) {
                 move = -(imgwidth * (total - 1));
             } else {
                 move = box_left + imgwidth;
             }

             imgnumber = -(box_left / imgwidth);
             if (imgnumber == 0) {
                 imgnumber = total;
             }
         } else if (el_id == 'linknext') {
             // Если изображение последнее, то переходим на первую картинку
             if (-(box_left) == (imgwidth * (total - 1))) {
                 move = 0;
             } else {
                 move = box_left - imgwidth;
             }

             imgnumber = Math.abs((box_left / imgwidth)) + 2;
             if (imgnumber == (total + 1)) {
                 imgnumber = 1;
             }
         } else if (el_id == 'linkfirst') {
             move = 0;
             imgnumber = 1;
         } else if (el_id == 'linklast') {
             move = -(imgwidth * (total - 1));
             imgnumber = total;
         }

         // Стили для выбранной картинки
         $("#imgthumb_box").find("img").removeAttr("style");
         $("#imglink"+imgnumber).find("img").css({
             "border-color": "#666",
             "top": "-5px",
             "border-top-width": "-5px"
         });

         $("#navigate a").hide();
         $("#navigate span").show();

         $("#img_box").animate({
             left: move+'px'
         }, 400, function() {
             $("#navigate a").show();
             $("#navigate span").hide();
         });

         return false;
     });

//GALLERY
	$('.thumbs').piroBox({
			border: 10,
			borderColor : '#222', 
			mySpeed: 500, 
			bg_alpha: 0.5,
			cap_op_start : 0.4,
			cap_op_end: 0.8,
			pathLoader : '#000 url(css_pirobox/ajax-loader.gif) center center no-repeat;', 
			gallery : '.gallery_in li a', 
			gallery_li : '.gallery_in li', 
			next_class : '.next_in',
			previous_class : '.previous_in'
	});	
     
 });

