jQuery.fn.Turin_Video = function(options){
  var options = jQuery.extend({
   tumb_Height: 100,
   tumb_Width:  100,
   VideoBlock: "#video_block",
   VideoWrap:  "#video_menu-wrap", /*ul*/
   VideoItem:  "video_menu-item",  /*li*/
   HiddenItem: "video_menu-item_hide", /*hidden li*/
   Timer: 500,
   tumb_pad: 10,
   nav_Left: ".video_nav-left",
   nav_Right: ".video_nav-right",
   nav_Active: "nav_active",
   style_chose: "video_menu-item_chose"
   },options);

   return this.each(function(event) {
       var isIE = true; /*Проверка на msIE*/
       isIE = jQuery.browser.msie;

       var id = this.id;
       var Menu       = jQuery("#"+id);
       var Block      = jQuery(options.VideoBlock);
       var Tumb_block = jQuery(options.VideoWrap);
       var Tumb       = jQuery(options.VideoWrap+" ."+options.VideoItem);
       var A          = Tumb.children("a");
       var first_Item = jQuery(options.VideoWrap+" ."+options.VideoItem+":first");
       var last_Item  = jQuery(options.VideoWrap+" ."+options.VideoItem+":last");
       var nav_Left   = jQuery(options.nav_Left);
       var nav_Right  = jQuery(options.nav_Right);

       var max_count= Math.round(Menu.width()/(options.tumb_Width+2*options.tumb_pad));
       var count    = Tumb.length;
       if(count > max_count-1){/*если кол-во больше вместимого*/
            nav_Left.addClass(options.nav_Active);
            nav_Right.addClass(options.nav_Active);
       } else { /*Если кол-во вмещаемое*/ }

/*Insert href="#video-N"*/
       var show_Item = first_Item;
       A.each(function(i) {
            jQuery(this).attr("href", "#video_"+i);
            if(location.hash == "#video_"+i){
              show_Item = jQuery(this).parent();
            }
       });
/*other*/

       LoadInfo(show_Item);


       nav_Right.click(function(){if(!isAnimated() && nav_Right.hasClass(options.nav_Active)){Move_right();}});
       nav_Left.click(function(){if(!isAnimated() && nav_Left.hasClass(options.nav_Active)){Move_left();}});
       Tumb.live("click",function(e){Item = jQuery(e.target);while(!Item.hasClass(options.VideoItem)){Item = Item.parent();}LoadInfo(Item);/* return false;*/});


        function LoadInfo(e){
          var Item = e;
          Tumb = jQuery(options.VideoWrap+" ."+options.VideoItem);
          /*styles*/
          Tumb.removeClass(options.style_chose);
          Item.addClass(options.style_chose);
          /*set to block*/
          var name = Item.children("a").children("span").text();
          jQuery(options.VideoBlock+" .video_block-name").html(name);
          var txt  = Item.children("div:last").html();
          jQuery(options.VideoBlock+" .video_block-txt").html(txt);
/*        var code = Item.children("div:first").html();
          jQuery(options.VideoBlock+" .video_block-code").html(code);*/
          var code = Item.children("div:first");
          jQuery(options.VideoBlock+" .video_block-code").html("");
          code.clone().prependTo(options.VideoBlock+" .video_block-code");
          jQuery(options.VideoBlock+" .video_block-code").children("div").show();
        }

        function Move_left(){
            Tumb = jQuery(options.VideoWrap+" ."+options.VideoItem);
            nav_Left.removeClass(options.nav_Active);
            last_Item = GetLast();
            var Temp = last_Item.html();
            if_chosen = (last_Item.hasClass(options.style_chose)) ? options.style_chose : "";
            Temp = "<li class=\""+options.HiddenItem+" "+if_chosen+"\">"+Temp+"</li>";
            if(isAnimated()) return null;
            Tumb_block.prepend(Temp);
            first_Item = GetFirstHidden();
            first_Item.switchClass(options.HiddenItem, options.VideoItem, options.Timer);
            last_Item.switchClass(options.VideoItem, options.HiddenItem, options.Timer, function(){
                last_Item.remove();
                nav_Left.addClass(options.nav_Active);
            });
        }

        function Move_right(){
            Tumb = jQuery(options.VideoWrap+" ."+options.VideoItem);
            nav_Right.removeClass(options.nav_Active);
            first_Item = GetFirst();
            var Temp = first_Item.html();
            if_chosen = (first_Item.hasClass(options.style_chose)) ? options.style_chose : "";
            Temp = "<li class=\""+options.HiddenItem+" "+if_chosen+"\">"+Temp+"</li>";
            if(isAnimated()) return null;
            Tumb_block.append(Temp);
            last_Item = GetLastHidden();
            last_Item.switchClass(options.HiddenItem, options.VideoItem, options.Timer);
            first_Item.switchClass(options.VideoItem, options.HiddenItem, options.Timer, function(){
                first_Item.remove();
                nav_Right.addClass(options.nav_Active);
            });
        }




        function GetFirst(){return jQuery(options.VideoWrap+" ."+options.VideoItem+":first");}
        function GetLast() {return jQuery(options.VideoWrap+" ."+options.VideoItem+":last"); }
        function GetFirstHidden(){return jQuery(options.VideoWrap+" ."+options.HiddenItem+":first");}
        function GetLastHidden() {return jQuery(options.VideoWrap+" ."+options.HiddenItem+":last"); }
        function isAnimated(){return (jQuery(options.VideoWrap+" ."+options.VideoItem+":animated").length > 0 || jQuery(options.VideoWrap+" ."+options.HiddenItem+":animated").length > 0);}
   });
   };
