$.fn.droppy=function(d){d=$.extend({speed:250},d||{});this.each(function(){var c=this,zIndex=1000;function getSubnav(a){if(a.nodeName.toLowerCase()=='li'){var b=$('> ul',a);return b.length?b[0]:null}else{return a}}function getActuator(a){if(a.nodeName.toLowerCase()=='ul'){return $(a).parents('li')[0]}else{return a}}function hide(){var a=getSubnav(this);if(!a)return;$.data(a,'cancelHide',false);setTimeout(function(){if(!$.data(a,'cancelHide')){$(a).slideUp(d.speed)}},500)}function show(){var a=getSubnav(this);if(!a)return;$.data(a,'cancelHide',true);$(a).css({zIndex:zIndex++}).slideDown(d.speed);if(this.nodeName.toLowerCase()=='ul'){var b=getActuator(this);$(b).addClass('hover');$('> a',b).addClass('hover')}}$('ul, li',this).hover(show,hide);$('li',this).hover(function(){$(this).addClass('hover');$('> a',this).addClass('hover')},function(){$(this).removeClass('hover');$('> a',this).removeClass('hover')})})};
(function($){$.event.special.mousewheel={setup:function(){var b=$.event.special.mousewheel.handler;if($.browser.mozilla)$(this).bind('mousemove.mousewheel',function(a){$.data(this,'mwcursorposdata',{pageX:a.pageX,pageY:a.pageY,clientX:a.clientX,clientY:a.clientY})});if(this.addEventListener)this.addEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),b,false);else this.onmousewheel=b},teardown:function(){var a=$.event.special.mousewheel.handler;$(this).unbind('mousemove.mousewheel');if(this.removeEventListener)this.removeEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),a,false);else this.onmousewheel=function(){};$.removeData(this,'mwcursorposdata')},handler:function(a){var b=Array.prototype.slice.call(arguments,1);a=$.event.fix(a||window.event);$.extend(a,$.data(this,'mwcursorposdata')||{});var c=0,returnValue=true;if(a.wheelDelta)c=a.wheelDelta/120;if(a.detail)c=-a.detail/3;a.data=a.data||{};a.type="mousewheel";b.unshift(c);b.unshift(a);return $.event.handle.apply(this,b)}};$.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);
(function(A){A.jScrollPane={active:[]};A.fn.jScrollPane=function(C){C=A.extend({},A.fn.jScrollPane.defaults,C);var B=function(){return false};return this.each(function(){var O=A(this);O.css("overflow","hidden");var X=this;if(A(this).parent().is(".jScrollPaneContainer")){var Ac=C.maintainPosition?O.position().top:0;var L=A(this).parent();var d=L.innerWidth();var Ad=L.outerHeight();var M=Ad;A(">.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown",L).remove();O.css({top:0})}else{var Ac=0;this.originalPadding=O.css("paddingTop")+" "+O.css("paddingRight")+" "+O.css("paddingBottom")+" "+O.css("paddingLeft");this.originalSidePaddingTotal=(parseInt(O.css("paddingLeft"))||0)+(parseInt(O.css("paddingRight"))||0);var d=O.innerWidth();var Ad=O.innerHeight();var M=Ad;O.wrap(A("<div></div>").attr({className:"jScrollPaneContainer"}).css({height:Ad+"px",width:d+"px"}));A(document).bind("emchange",function(Ae,Af,p){O.jScrollPane(C)})}if(C.reinitialiseOnImageLoad){var N=A.data(X,"jScrollPaneImagesToLoad")||A("img",O);var G=[];if(N.length){N.each(function(p,Ae){A(this).bind("load",function(){if(A.inArray(p,G)==-1){G.push(Ae);N=A.grep(N,function(Ag,Af){return Ag!=Ae});A.data(X,"jScrollPaneImagesToLoad",N);C.reinitialiseOnImageLoad=false;O.jScrollPane(C)}}).each(function(Af,Ag){if(this.complete||this.complete===undefined){this.src=this.src}})})}}var o=this.originalSidePaddingTotal;var l={height:"auto",width:d-C.scrollbarWidth-C.scrollbarMargin-o+"px"};if(C.scrollbarOnLeft){l.paddingLeft=C.scrollbarMargin+C.scrollbarWidth+"px"}else{l.paddingRight=C.scrollbarMargin+"px"}O.css(l);var m=O.outerHeight();var i=Ad/m;if(i<0.99){var H=O.parent();H.append(A("<div></div>").attr({className:"jScrollPaneTrack"}).css({width:C.scrollbarWidth+"px"}).append(A("<div></div>").attr({className:"jScrollPaneDrag"}).css({width:C.scrollbarWidth+"px"}).append(A("<div></div>").attr({className:"jScrollPaneDragTop"}).css({width:C.scrollbarWidth+"px"}),A("<div></div>").attr({className:"jScrollPaneDragBottom"}).css({width:C.scrollbarWidth+"px"}))));var z=A(">.jScrollPaneTrack",H);var P=A(">.jScrollPaneTrack .jScrollPaneDrag",H);if(C.showArrows){var g;var Ab;var S;var r;var j=function(){if(r>4||r%4==0){y(u+Ab*b)}r++};var K=function(p){A("html").unbind("mouseup",K);g.removeClass("jScrollActiveArrowButton");clearInterval(S)};var Z=function(){A("html").bind("mouseup",K);g.addClass("jScrollActiveArrowButton");r=0;j();S=setInterval(j,100)};H.append(A("<a></a>").attr({href:"javascript:;",className:"jScrollArrowUp"}).css({width:C.scrollbarWidth+"px"}).html("Scroll up").bind("mousedown",function(){g=A(this);Ab=-1;Z();this.blur();return false}).bind("click",B),A("<a></a>").attr({href:"javascript:;",className:"jScrollArrowDown"}).css({width:C.scrollbarWidth+"px"}).html("Scroll down").bind("mousedown",function(){g=A(this);Ab=1;Z();this.blur();return false}).bind("click",B));var Q=A(">.jScrollArrowUp",H);var J=A(">.jScrollArrowDown",H);if(C.arrowSize){M=Ad-C.arrowSize-C.arrowSize;z.css({height:M+"px",top:C.arrowSize+"px"})}else{var s=Q.height();C.arrowSize=s;M=Ad-s-J.height();z.css({height:M+"px",top:s+"px"})}}var w=A(this).css({position:"absolute",overflow:"visible"});var D;var Y;var b;var u=0;var V=i*Ad/2;var a=function(Ae,Ag){var Af=Ag=="X"?"Left":"Top";return Ae["page"+Ag]||(Ae["client"+Ag]+(document.documentElement["scroll"+Af]||document.body["scroll"+Af]))||0};var f=function(){return false};var v=function(){n();D=P.offset(false);D.top-=u;Y=M-P[0].offsetHeight;b=2*C.wheelSpeed*Y/m};var E=function(p){v();V=a(p,"Y")-u-D.top;A("html").bind("mouseup",T).bind("mousemove",h);if(A.browser.msie){A("html").bind("dragstart",f).bind("selectstart",f)}return false};var T=function(){A("html").unbind("mouseup",T).unbind("mousemove",h);V=i*Ad/2;if(A.browser.msie){A("html").unbind("dragstart",f).unbind("selectstart",f)}};var y=function(Ae){Ae=Ae<0?0:(Ae>Y?Y:Ae);u=Ae;P.css({top:Ae+"px"});var Af=Ae/Y;w.css({top:((Ad-m)*Af)+"px"});O.trigger("scroll");if(C.showArrows){Q[Ae==0?"addClass":"removeClass"]("disabled");J[Ae==Y?"addClass":"removeClass"]("disabled")}};var h=function(p){y(a(p,"Y")-D.top-V)};var q=Math.max(Math.min(i*(Ad-C.arrowSize*2),C.dragMaxHeight),C.dragMinHeight);P.css({height:q+"px"}).bind("mousedown",E);var k;var R;var I;var t=function(){if(R>8||R%4==0){y((u-((u-I)/2)))}R++};var Aa=function(){clearInterval(k);A("html").unbind("mouseup",Aa).unbind("mousemove",e)};var e=function(p){I=a(p,"Y")-D.top-V};var U=function(p){v();e(p);R=0;A("html").bind("mouseup",Aa).bind("mousemove",e);k=setInterval(t,100);t()};z.bind("mousedown",U);H.bind("mousewheel",function(Ae,Ag){v();n();var Af=u;y(u-Ag*b);var p=Af!=u;return !p});var F;var W;function c(){var p=(F-u)/C.animateStep;if(p>1||p<-1){y(u+p)}else{y(F);n()}}var n=function(){if(W){clearInterval(W);delete F}};var x=function(Af,p){if(typeof Af=="string"){$e=A(Af,O);if(!$e.length){return}Af=$e.offset().top-O.offset().top}H.scrollTop(0);n();var Ae=-Af/(Ad-m)*Y;if(p||!C.animateTo){y(Ae)}else{F=Ae;W=setInterval(c,C.animateInterval)}};O[0].scrollTo=x;O[0].scrollBy=function(Ae){var p=-parseInt(w.css("top"))||0;x(p+Ae)};v();x(-Ac,true);A("*",this).bind("focus",function(Ah){var Ag=A(this);var Aj=0;while(Ag[0]!=O[0]){Aj+=Ag.position().top;Ag=Ag.offsetParent()}var p=-parseInt(w.css("top"))||0;var Ai=p+Ad;var Af=Aj>p&&Aj<Ai;if(!Af){var Ae=Aj-C.scrollbarMargin;if(Aj>p){Ae+=A(this).height()+15+C.scrollbarMargin-Ad}x(Ae)}});if(location.hash){x(location.hash)}A(document).bind("click",function(Ae){$target=A(Ae.target);if($target.is("a")){var p=$target.attr("href");if(p.substr(0,1)=="#"){x(p)}}});A.jScrollPane.active.push(O[0])}else{O.css({height:Ad+"px",width:d-this.originalSidePaddingTotal+"px",padding:this.originalPadding});O.parent().unbind("mousewheel")}})};A.fn.jScrollPane.defaults={scrollbarWidth:15,scrollbarMargin:5,wheelSpeed:18,showArrows:false,arrowSize:0,animateTo:false,dragMinHeight:1,dragMaxHeight:99999,animateInterval:100,animateStep:3,maintainPosition:true,scrollbarOnLeft:false,reinitialiseOnImageLoad:false};A(window).bind("unload",function(){var C=A.jScrollPane.active;for(var B=0;B<C.length;B++){C[B].scrollTo=C[B].scrollBy=null}})})(jQuery);

SlideshowModel = {
    queue: [],
    options: {'box':'', 'slider':'', 'host':'', 'play': '', 'index': ''},
    size: 0,
    buff: null,
    current: 0,
    loaded: -1,
    action: false,
    show: true,
    time: 500,
    timer: 5000,
    loading: false,
    // Init
    init: function(queue, host, box, slider, index, c_play, c_next, c_priv, c_up, c_down) {
        if (queue.length >= 1) {
            // Formation queue
            // First photo
            SlideshowModel.queue.push({'id':queue[0][0],'type':'i','src':queue[0][1]});
            // Thumbs
            for (var i = 0; i < queue.length; i++) {
                SlideshowModel.queue.push({'id':queue[i][0],'type':'t','src':'s-'+queue[i][1]});
            }
            // Other photos
            for (i = 1; i < queue.length; i++) {
                SlideshowModel.queue.push({'id':queue[i][0],'type':'i','src':queue[i][1]});
            }
            SlideshowModel.size = queue.length;
        }

        //если количество фото <=12, то скрываем стрелки вверх/вниз
        if (SlideshowModel.size <= 12)
        {
          $('#'+c_up).css('visibility', 'hidden');
          $('#'+c_down).css('visibility', 'hidden');
        }
        SlideshowModel.buff = 0;
        SlideshowModel.options.box = box;
        SlideshowModel.options.host = host;
        SlideshowModel.options.play = c_play;
        SlideshowModel.options.index = index;
        SlideshowModel.options.slider = slider;

        $('#floater').hover(function() {
            $('#photo-left').removeClass('none');
            $('#photo-right').removeClass('none');
        }, function() {
            $('#photo-left').addClass('none');
            $('#photo-right').addClass('none');
        });

        $('#'+c_play).click(function() {return SlideshowModel.play();});
        $('#'+c_priv).click(function() {return SlideshowModel.privImage(true);});
        $('#'+c_next).click(function() {return SlideshowModel.nextImage(true);});
        $('#'+c_up).click(function() {return SlideshowModel.up();});
        $('#'+c_down).click(function() {return SlideshowModel.down();});
        $('#photo-left').click(function() {return SlideshowModel.privImage(true);})
        $('#photo-right').click(function() {return SlideshowModel.nextImage(true);})

        // Strt loader
        $(document).everyTime('25ms', 'slideshow-load-queue', function() {
            SlideshowModel.loadQueue();
        });
    },
    loadQueue: function() {
        // If queue not empty
        if (SlideshowModel.queue.length > 0) {
            if (SlideshowModel.loading == false) {
                // Set loading flag
                SlideshowModel.loading = true;
                var el = SlideshowModel.queue.shift();
                var img = new Image();
                // Element is thumb
                if (el.type == 't') {
                    $(img).bind("load", function() {
                        var tbox = $('#t'+el.id);
                        var abox = $('<a href="#"></a>').append($(this));
                        tbox.find('.img').remove().end().append(abox);
                        if (el.id == 0) {
                            tbox.addClass('active');
                        }
                        // Thumb click event
                        $(abox).click(function() {
                            var id = parseInt($(this).parent().attr('id').replace('t',''));
                            SlideshowModel.thumbClick(id, true);
                            return false;
                        });
                        SlideshowModel.loading = false;
                    }).attr('src', SlideshowModel.options.host+el.src);
                }
                // Element is photo
                else {
                    $(img).bind("load", function() {
                        $(this).css('display','none').attr('id', 'i'+el.id);
                        $('#'+SlideshowModel.options.box).append($(this));
                        if (SlideshowModel.buff != null && el.id == SlideshowModel.buff) {
                            $('#'+SlideshowModel.options.box).removeClass('loading');
                            // Start slideshow
                            if (el.id == 0) {
                                SlideshowModel.play();
                                SlideshowModel.showImage(el.id, false);
                            }
                            else {
                                SlideshowModel.showImage(el.id, true);
                            }
                            SlideshowModel.buff = null;
                        }
                        $('#t'+el.id).addClass('loaded');
                        SlideshowModel.loaded += 1;
                        SlideshowModel.loading = false;
                    }).attr('src', SlideshowModel.options.host+el.src);
                }
            }
        }
        else {
            $(document).stopTime('slideshow-load-queue');
            SlideshowModel.loading = false;
        }
    },
    // Формирование очереди загрузок
    formationQueue: function(index) {
       // SlideshowModel.loading = true;
        var buff = [];
        var el = null;
        // Make new queue
        for (var i = 0; i < SlideshowModel.queue.length; i++) {
            if (SlideshowModel.queue[i].id != index) {
                buff.push(SlideshowModel.queue[i]);
            }
            else {
                el = SlideshowModel.queue[i];
            }
        }
        // If el == null, it is mean, that image loading or loaded
        if (el != null) {
            buff.splice(0,0,el);
            if (el.type == 'i') {
                SlideshowModel.buff = el.id;
            }
        }
        else {
            // If image loaded, show it
            if ($('#t'+index).is('.loaded')) {
                $('#'+SlideshowModel.options.box).removeClass('loading');
                SlideshowModel.showImage(index, true);
            }
            // Change SlideshowModel.buff, image would show in loadQueue method
            else {
               SlideshowModel.buff = index;
            }
        }
        SlideshowModel.queue = buff;
   //     SlideshowModel.loading = false;
    },
    // Обработка клика по фотке
    thumbClick: function(index, manual) {
        var loaded = $('#t'+index).is('.loaded');
        // Фотка еще не загружена
        if (loaded == false) {
            SlideshowModel.action = true;
            $('#'+SlideshowModel.options.box+' img:visible').fadeOut(SlideshowModel.time, function() {
                $('#'+SlideshowModel.options.box).addClass('loading');
                SlideshowModel.activeThumb(index);
                SlideshowModel.formationQueue(index);
            });
        }
        else if (SlideshowModel.action == false && SlideshowModel.current != index) {
            SlideshowModel.action = true;
            $('#i'+SlideshowModel.current).fadeOut(SlideshowModel.time, function() {
                SlideshowModel.activeThumb(index);
                SlideshowModel.showImage(index, manual);
            });
        }
    },
    // Движение слайдера и активация привьюшки
    activeThumb: function(index) {
        $('#'+SlideshowModel.options.slider+ ' .active').removeClass('active');
        $('#t'+index).addClass('active');
        if (SlideshowModel.size > 21){
            var cols   = Math.ceil(SlideshowModel.size / 3);
            var cindex = Math.ceil((index + 1) / 3);
            var tlimit = ((cindex - 2) < 0) ? 0 : (cindex - 2);
            if (cols <= cindex + 2) {
                tlimit = cols - 4;
            }
        $('#'+SlideshowModel.options.slider).animate({top:'-'+tlimit * 57+'px'}, {queue:false, duration: 300});
        }
        SlideshowModel.current = index;
        $('#'+SlideshowModel.options.index).html(parseInt(SlideshowModel.current) + 1);
    },
    // Показываем картинку
    showImage: function(index, manual) {
        $('#i'+index).fadeIn(SlideshowModel.time, function() {
            if (SlideshowModel.show == true && manual == true) {
                SlideshowModel.play();
            }
            SlideshowModel.action = false;
        });
    },
    privImage: function() {
        if (SlideshowModel.current > 0) {
            SlideshowModel.thumbClick(SlideshowModel.current - 1, true);
        }
        return false;
    },
    nextImage: function(manual) {
        if (SlideshowModel.current < SlideshowModel.loaded) {
           SlideshowModel.thumbClick(SlideshowModel.current + 1, manual);
        }
        if (SlideshowModel.current == SlideshowModel.size - 1){
           SlideshowModel.thumbClick(0, manual);
        }
        return false;
    },
    up: function() {
        var top  = Math.abs($('#'+SlideshowModel.options.slider).css('top').replace('px',''));
        if (top > 0) {
            if (top < 57)
                top = 0;
            else
                top = top - 57;
            $('#'+SlideshowModel.options.slider).animate({top:'-'+top+'px'}, {queue:false, duration: 300});
        }
        return false;
    },
    down: function() {
        var top  = Math.abs($('#'+SlideshowModel.options.slider).css('top').replace('px',''));
        var ctop = parseInt(top / 57);
        var cols = Math.ceil(SlideshowModel.size / 3);
        if (ctop + 8 <= cols) {
            top = ctop + 1;
            $('#'+SlideshowModel.options.slider).animate({top:'-'+top * 57+'px'}, {queue:false, duration: 300});
        }
        return false;
    },
    play: function() {
        /**
         * Play
         */
        if (SlideshowModel.show == false) {
            if (SlideshowModel.current <= (SlideshowModel.size - 1)) {
                SlideshowModel.show = true;
                $('#'+SlideshowModel.options.play+' a').html('stop slideshow');
                $(document).everyTime(SlideshowModel.timer, 'slideshow', function() {
                    SlideshowModel.nextImage(false);
                    if (SlideshowModel.current >= SlideshowModel.size) {
                        SlideshowModel.play();
                    }
                });
            }
        } else {
            SlideshowModel.show = false;
            $('#'+SlideshowModel.options.play+' a').html('start slideshow');
            $(document).stopTime('slideshow');
        }
        return false;
    }
}

BackgroundModel = {
    images: [],
    host: '',
    count: 0,
    limit: 0,
    box: '',
    action: false,
    current: 0,
    counter: 0,
    time: 500,
    timer: 5000,
    pause: false,
    loading: false,
    init: function(images, host, count, limit, box) {
        BackgroundModel.images = images;
        BackgroundModel.host = host;
        BackgroundModel.count = count;
        BackgroundModel.limit = limit;
        BackgroundModel.box = box;
        if (BackgroundModel.count > 1) {
            if (BackgroundModel.count < BackgroundModel.limit) {
                BackgroundModel.limit = BackgroundModel.count;
            }
            // Устанавливаем
            BackgroundModel.counter = 0;
            // Устанавливаем признак загрузки картинки
            BackgroundModel.loading = false;
            $(document).everyTime('25ms', 'background-loader', function() {BackgroundModel.loadImages()});
            $(document).everyTime('25ms', 'start', function(){
                if (BackgroundModel.action && BackgroundModel.pause){
                   BackgroundModel.slideImages();
                   $(document).everyTime(BackgroundModel.timer, 'slideshow', function() {BackgroundModel.slideImages()});
                   $(document).stopTime('start');
                }
            });
        }
        else {
            BackgroundModel.loadSingleImage();
        }
    },
    loadSingleImage: function() {
        var img = new Image();
        $(img).load(function() {
            $(this).css('display','none');
            $('#'+BackgroundModel.box).removeClass('loading').append($(this));
            $(this).fadeIn(BackgroundModel.time);
        }).attr('src', BackgroundModel.host+BackgroundModel.images[0]);
    },
    loadImages: function() {
        if (BackgroundModel.counter < BackgroundModel.images.length) {
            if (BackgroundModel.loading == false) {
                BackgroundModel.loading = true;
                var img = new Image();
                $(img).bind("load", function() {
                    $(this).css('display','none');
                    $('#'+BackgroundModel.box).append($(this));

                    if (BackgroundModel.counter == 0) {
                        // If first photo loaded, show her
                        $('#'+BackgroundModel.box).removeClass('loading');
                        $('#'+BackgroundModel.box+' img').eq(0).fadeIn(BackgroundModel.time);
                        //устанавливаем признак паузы
                        $(document).oneTime(BackgroundModel.timer, function(){
                            BackgroundModel.pause = true;
                        });
                    }
                    //если загружен лимит фото - установить признак
                    if (BackgroundModel.counter == BackgroundModel.limit - 1){
                       BackgroundModel.action = true;
                    }
                    BackgroundModel.counter += 1;
                    BackgroundModel.loading = false;
                    //как только признак загрузки лимита фоток и признак паузы будут установлены -  старт слайдшоу
                }).attr('src', BackgroundModel.host+BackgroundModel.images[BackgroundModel.counter]);
            }
        } else {
            $(document).stopTime('background-loader');
        }
    },
    slideImages: function() {
        var imgs = $('#'+BackgroundModel.box+' img');
        var size = imgs.size();
        if (BackgroundModel.action) {
            $(imgs[BackgroundModel.current]).fadeOut(BackgroundModel.time, function() {
                if (BackgroundModel.current < (size - 1)) {
                    BackgroundModel.current = BackgroundModel.current + 1;
                } else {
                    BackgroundModel.current = 0;
                }
                $(imgs[BackgroundModel.current]).fadeIn(BackgroundModel.time);
            });
        }
    }
}

VideoModel = {
    q:[],
    size: 0,
    time: 300,
    action: false,
    loading: false,
    options: {'box':'', 'slider':'', 'up': '', 'down': ''},
    init: function(box, slider, up, down, source) {
        // Init vars
        VideoModel.q = source;
        VideoModel.action = false;
        VideoModel.loading = false;
        VideoModel.size = source.length;
        // Options
        VideoModel.options.box = box;
        VideoModel.options.slider = slider;
        VideoModel.options.up = up;
        VideoModel.options.down = down;

        if (VideoModel.q.length >= 1) {
            VideoModel.loadIframe(VideoModel.q[0][1], VideoModel.q[0][3], VideoModel.q[0][4]);
            // Start loader
            $(document).everyTime('25ms', 'video-load-queue', function() {
                VideoModel.loadQueue();
            });

            $('#'+VideoModel.options.up).click(function() {VideoModel.up(); return false;});
            $('#'+VideoModel.options.down).click(function() {VideoModel.down(); return false;});
        }
    },
    loadIframe: function(id, src) {
        $('#'+VideoModel.options.box).addClass('loading');
      //  if (src == 'vimeo') {
            var iframe = '<iframe src="http://player.vimeo.com/video/'+id+'?title=0&amp;byline=0&amp;portrait=0" width="722" height="404" frameborder="0"></iframe>';
      //  }
      //  else {
      //      var iframe = '<iframe class="youtube-player" type="text/html" width="722" height="404" src="http://www.youtube.com/embed/'+id+'?wmode=transparent" frameborder="0"></iframe>';
      //  }
        $('#'+VideoModel.options.box).html('').append(iframe);
        $('#'+VideoModel.options.box+' iframe').load(function() {
            $('#'+VideoModel.options.box).removeClass('loading');
        });
    },
    loadQueue: function() {
        if (VideoModel.q.length > 0) {
            if (VideoModel.loading == false) {
                // Set loading flag
                VideoModel.loading = true;
                var el = VideoModel.q.shift();
                var img = new Image();
                $(img).bind("load", function() {
                    var tbox = $('#t'+el[0]);
                    var abox = $('<a href="#"></a>').data({videoid:el[1],source:el[3],title:el[4]}).append($(this));
                    tbox.append(abox).removeClass('loading').addClass('loaded');
                    // Thumb click event
                    $(abox).click(function() {
                        $('#'+VideoModel.options.slider+' .thumb li.active').removeClass('active');
                        $(this).parent().addClass('active');
                        var id = $(this).data('videoid');
                        var src = $(this).data('source');
                        VideoModel.loadIframe(id, src);
                        var id = parseInt($(this).parent().attr('id').replace('t',''));
                        VideoModel.activeThumb(id);
                        return false;
                    });
                    if (el[0] == 0) {
                        $(abox).parent().addClass('active');
                    }
                    VideoModel.loading = false;
                }).attr('src', el[2]).removeAttr('width').attr('height', 77);
            }
        }
        else {
            $(document).stopTime('video-load-queue');
            VideoModel.loading = false;
        }
    },
    // Движение слайдера и активация привьюшки
    activeThumb: function(index) {
        $('#'+VideoModel.options.slider+' .active').removeClass('active');
        $('#t'+index).addClass('active');
        // Limit
        if (VideoModel.size > 5) {
            var tlimit = ((index - 3) < 0) ? 0 : (index - 2);
          //  if (VideoModel.size <= index + 1) {
          //      tlimit = VideoModel.size  - 5;
          // }
            // Animate for limit
            if (VideoModel.size <= index + 2){tlimit = VideoModel.size  - 5;}
           // alert (tlimit);
            $('#'+VideoModel.options.slider).animate({top:'-'+tlimit * 83+'px'}, VideoModel.time);
        }
    },
    up: function() {

        var top  = Math.abs($('#'+VideoModel.options.slider).css('top').replace('px',''));
        if (top > 0) {
            top = top - 83;
            $('#'+VideoModel.options.slider).animate({top:'-'+top+'px'}, VideoModel.time);
        }
        return false;
    },
    down: function() {
        var top  = Math.abs($('#'+VideoModel.options.slider).css('top').replace('px',''));
        var ctop = parseInt(top / 83);
        if (ctop + 5 < VideoModel.size) {
            top = ctop + 1;
            $('#'+VideoModel.options.slider).animate({top:'-'+top * 83+'px'}, 300);
        }
        return false;
    }
}

TextModel = {
    init: function(box, text) {
        $('#'+text).removeClass('none').jScrollPane({dragMaxHeight: 30, showArrows : true, arrowSize: 20});
    }
}
