jQuery.fn.lzslider = function(options){
	  var options = jQuery.extend({
	    countItems:8,//количество видимых слайдов
            countItemsChange:"",
            widthSlide:"",//длина прокрутки
            width:""//длина видимой части слайда
	  },options);
    return this.each(function() {
        var count_visible_items =parseInt(options.countItems);
        var parent = this;


        // длина прокрутки
         var width_slide_temp =jQuery(this).find(".slide-item:eq(0)").innerWidth();
         
        if (options.widthSlide !=""){
             width_slide  = options.widthSlide;
        } else if (options.countItemsChange !="") {
             width_slide =parseInt(width_slide_temp*options.countItemsChange);
        } else {
             width_slide =  width_slide_temp*count_visible_items;
        }
        //количество слайдов
        var length =  jQuery(this).find(".slide-item").length;

        //длина всех слайдов
            var width_bounding=0;
        //длина слайдера
        var width_slider;

        if (options.width !=""){
            width_slider = parseInt(options.width);
        } else {
           width_slider = width_slide_temp*count_visible_items;
        }

         jQuery(this).find(".bounding-box").css("width",width_slider);
         jQuery(this).find(".slider-lz").css("width",width_slider);




        $(".arrow-prev").hide();

       jQuery(window).load( function(){
                        for(var i=0; i< length; i++){
                            width_bounding = width_bounding + jQuery(parent).find(".slide-item").eq(i).outerWidth();
                        }

                        jQuery(parent).find(".slider-wrapper-long").css("width",width_bounding)
                      if(width_slider >=  width_bounding){
                            jQuery(parent).find(".arrow-next").hide();
                       }

           }
        );
                         



        //NEXT

        jQuery(parent).find(".arrow-next").click(function(){

            jQuery(parent).find(".arrow-prev").show();

            if (options.countItemsChange != ""){
                width_slide = jQuery(parent).find(".slide-item:eq(0)").innerWidth();
            }
            width_bounding = width_bounding-width_slide;

            if ( width_bounding <= width_slider ){
                jQuery(this).hide();
            }

            jQuery(parent).find(".slider-wrapper-long").animate({"left": "-="+width_slide}, "slow");

         });


         //PREV

         jQuery(parent).find(".arrow-prev").click(function(){

            jQuery(parent).find(".arrow-next").show();

            if (options.countItemsChange != ""){
                width_slide = jQuery(parent).find(".slide-item:eq(0)").innerWidth();
            }

            var left = parseInt(jQuery(parent).find(".slider-wrapper-long").css("left"));

            if (left+width_slide >=  0){
                jQuery(this).hide();
            }
            width_bounding = width_bounding+width_slide;

            jQuery(parent).find(".slider-wrapper-long").animate({"left": "+="+width_slide}, "slow");

         });

    });
};

