jQuery.fn.galex = function(){
  var options = jQuery.extend({
    nextBtn:'nextBtn',
	prevBtn:'prevBtn',
    nextBtnTxt:'',
	prevBtnTxt:'',
	active_img:6
  },options);
  return this.each(function() {
	 
	 var width_main_container = 0;
	 
	 /************** ПЕРЕМЕННЫЙ ОПЦИЙ ****************/
	 var nextBtn_v = options.nextBtn;
	 var prevBtn_v = options.prevBtn
	 var nextBtn_txt_v = options.nextBtnTxt;
	 var prevBtn_txt_v = options.prevBtnTxt;
	 var active_img = options.active_img;
	 /************** КНОПКИ ЛЕВО И ПРАВО *************/
	 var next = '#'+nextBtn_v;
	 var prev = '#'+prevBtn_v;
	 
	 $(this).append('<a href="#" id="'+nextBtn_v+'">'+nextBtn_txt_v+'</a><a href="#" id="'+prevBtn_v+'">'+prevBtn_txt_v+'</a>');
	 $(this).append('<div id="img_small_right"><ul></ul></div>').append('<div id="img_small_left"><ul></ul></div>');
	 
	 var total_width = 0;
	 
	 $(this).find('.gal_ex li').each(function(index, element) {
      var gal_html = $(this).html();
      $('#img_small_right ul, #img_small_left ul').append('<li>'+gal_html+'</li>');
	   
	  total_width = total_width + $(this).outerWidth(true);
     });
	 
	 $(this).find('.gal_ex').css('width',total_width);
	 
	 var width_total_right = 0;
	 var width_1_li = $('#img_small_right ul li:first').outerWidth(true);
	 $('#img_small_right ul li').each(function(index, element) {
         width_total_right = width_total_right + $(this).outerWidth(true);
     });
	 
     $('#img_small_right ul').css('left', width_total_right - width_1_li);
	 
	 
      
     /************* Обработчик клика на Влево и Вправо *************/
	 var step_big = $(this).find('.big_images_container').outerWidth(true);
	 var count = $(this).find('.gal_ex li').length;
	 var j=2;
	 
	 $(next).click(function(){
      if(j<=count){
	  j++;	  
	  $('.exercises_carusel .gal_ex').animate({left:'-='+step_big});
	  $('#img_small_right ul,#img_small_left ul').animate({left:'-='+width_1_li});
	  }
	  
	  return false;
	 });
	 
	 
	 $(prev).click(function(){
      if(j>=3){
	  j--;	  
	  $('.exercises_carusel .gal_ex').animate({left:'+='+step_big});
	  $('#img_small_right ul,#img_small_left ul').animate({left:'+='+width_1_li});
	  
	  }
	   
	  return false;
	 });
	 
 });
};
