(function ($) {
    $.fn.extend({
        infiniteCarousel: function (r) {
            var s = {
                transitionSpeed: 800,
                displayTime: 6000,
                textholderHeight: .25,
                displayProgressBar: true,
                displayThumbnails: true,
                displayThumbnailNumbers: true,
                displayThumbnailBackground: true,
                thumbnailWidth: '20px',
                thumbnailHeight: '20px',
                thumbnailFontSize: '.7em',
                easeLeft: 'linear',
                easeRight: 'linear',
                imagePath: '/js/infinitecarousel/images/',
                inView: 1,
                padding: '0px',
                advance: 1,
                showControls: true,
                autoHideControls: false,
                autoHideCaptions: false,
                autoStart: true,
                prevNextInternal: true,
                enableKeyboardNav: true,
                onSlideStart: function () {},
                onSlideEnd: function () {},
                onPauseClick: function () {}
            };
            var r = $.extend(s, r);
            return this.each(function () {
                var b = Math.round(Math.random() * 100000000);
                var o = r;
                var c = $(this);
                var d = o.autoStart;
                var e = $('li', c).length;
                var f = $('li:first', c).height();
                var g = $('li:first', c).width();
                if (o.inView > e - 1) o.inView = e - 1;
                $('p', c).hide();
                $(c).css({
                    'position': 'relative',
                    'overflow': 'hidden'
                }).width((g * o.inView) + (o.inView * parseInt(o.padding) * 2)).height(f + (parseInt(o.padding) * 2));
                $('ul', c).css({
                    'list-style': 'none',
                    'margin': '0',
                    'padding': '0',
                    'position': 'relative'
                }).width(g * e);
                $('li', c).css({
                    'display': 'inline',
                    'float': 'left',
                    'padding': o.padding
                });
                $('li:last', c).prependTo($('ul', c));
                $('ul', c).css('left', -g - (parseInt(o.padding) * 2) + 'px').width(9999);
                if (o.displayProgressBar) {
                    $(c).append('<div id="progress' + b + '" class="ic-progress-bar" style="position:absolute;bottom:0;background:#bbb;left:0;z-index:1"></div>');
                    $('#progress' + b).width('100%').height(5).css('opacity', '.6')
                }
                function startProgressBar(a) {
                    a = (a == null) ? o.displayTime : a;
                    $('#progress' + b).width('100%').height(5);
                    $('#progress' + b).animate({
                        'width': 0
                    }, a)
                }
                var h = parseInt($(c).css('border-bottom-width')) + parseInt($(c).css('border-top-width'));
                if (isNaN(h)) h = 0;
                var j = parseInt($(c).css('padding-left'));
                for (i = 1; i <= o.inView; i++) {
                    $(c).append('<div id="textholder' + b + '_' + i + '" class="textholder" style="position:absolute;width:' + g + 'px;bottom:0px;margin-bottom:' + -(f * o.textholderHeight + h) + 'px;"><span></span></div>');
                    $('#textholder' + b + '_' + i).css({
                        'left': (i - 1) * (g + parseInt(o.padding) * 2),
                        'margin-left': parseInt(o.padding) + j,
                        'margin-right': o.padding
                    });
                    $('#textholder' + b + '_' + i).height(f * o.textholderHeight).css({
                        'backgroundColor': '#FFF',
                        'opacity': '0.5'
                    });
                    html = '<div class="minmax" id="minmax' + b + '_' + i + '" style="width:8px;height:8px;position:absolute;top:1px;right:10px;cursor:pointer;background:url(' + o.imagePath + 'caption.gif) no-repeat 0 -8px"></div>';
                    html += '<div class="close" id="close' + b + '_' + i + '" style="width:8px;height:8px;position:absolute;top:1px;right:1px;cursor:pointer;background:url(' + o.imagePath + 'caption.gif) no-repeat 0 0"></div>';
                    $('#textholder' + b + '_' + i).append(html);
                    $('#minmax' + b + '_' + i).hide();
                    $('#close' + b + '_' + i).hide();
                    if (!o.autoHideCaptions) showtext($('li:eq(' + i + ') p', c).html(), i)
                }
                var k = parseInt($('#textholder' + b + '_1').css('padding-left')) + parseInt($('#textholder' + b + '_1').css('padding-right'));
                if (k > 0) $('.textholder', c).width(g - k);
                $('.close', c).each(function (i) {
                    $(this).click(function () {
                        $('#textholder' + b + '_' + (i + 1)).animate({
                            marginBottom: (-f * o.textholderHeight) - h - 1 + 'px'
                        }, 500)
                    })
                });
                $('.minmax', c).each(function (i) {
                    $(this).click(function () {
                        if (parseInt($('#textholder' + b + '_' + (i + 1)).css('margin-bottom')) == 0) {
                            $('#textholder' + b + '_' + (i + 1)).animate({
                                marginBottom: ((-f * o.textholderHeight) - h + 12) + 'px'
                            }, 500, function () {
                                $('#minmax' + b + '_' + (i + 1)).css('background-position', '0 -16px')
                            })
                        } else {
                            $('#textholder' + b + '_' + (i + 1)).animate({
                                marginBottom: '0px'
                            }, 500, function () {
                                $('#minmax' + b + '_' + (i + 1)).css('background-position', '0 -8px')
                            })
                        }
                    })
                });

                function showtext(t, i) {
                    if (d) {
                        $('#minmax' + b + '_' + i).hide();
                        $('#close' + b + '_' + i).hide()
                    }
                    if (t != null) {
                        $('#textholder' + b + '_' + i + ' span').html(t);
                        $('#textholder' + b + '_' + i).stop().animate({
                            marginBottom: '0px'
                        }, 500);
                        $('#minmax' + b + '_' + i).css('background-position', '0 -8px');
                        showminmax()
                    }
                }
                function showminmax() {
                    if (!d) {
                        $('.minmax', c).fadeIn(250);
                        $('.close', c).fadeIn(250)
                    }
                }
                function hideCaption() {
                    $('.textholder', c).stop().animate({
                        marginBottom: (-f * o.textholderHeight - h - 1) + 'px'
                    }, o.transitionSpeed)
                }
                if (o.displayThumbnails) {
                    function thumbclick(a) {
                        target_num = this.id.split('_');
                        if (l[0] != target_num[1]) {
                            n = 'pause';
                            $('#progress' + b).stop().fadeOut();
                            clearTimeout(q);
                            $('#thumbs' + b + ' div').css({
                                'cursor': 'default'
                            }).unbind('click');
                            d = 0;
                            setTimeout(function () {
                               
                            }, o.transitionSpeed);
                            
                        }
                        if (target_num[1] > l[0]) {
                            diff = target_num[1] - l[0];
                            moveLeft(diff)
                        }
                        if (target_num[1] < l[0]) {
                            diff = l[0] - target_num[1];
                            moveRight(diff)
                        }
                    }
                    var l = [];
                    var m = [];
                    $(c).after('<div class="slider-thumbs" id="thumbs' + b + '"></div>');
                    for (i = 0; i <= e - 1; i++) {
                        thumb = $('img:eq(' + (i + 1) + ')', c).attr('src');
                        $('#thumbs' + b).append('<div class="thumb" id="thumb' + b + '_' + (i + 1) + '" style="cursor:pointer;display:inline;float:left;width:' + o.thumbnailWidth + ';height:' + o.thumbnailHeight + ';line-height:' + o.thumbnailHeight + ';padding:0;overflow:hidden;text-align:center;margin-right:4px;">' + (i + 1) + '</div>');
                        if (i <= o.inView) $('#thumb' + b + '_' + i).css({
                            
                        });
                        m.push(i + 1)
                    }
                    for (i = 1; i <= o.inView; i++) l.push(m.shift());
                    thumb = $('img:first', c).attr('src');
                    $('#thumb' + b + '_' + e).css({
                        
                    });
                    $('#thumbs' + b + ' div.thumb:not(:first)').css({
                        opacity: .45
                    });
                    $('#thumbs' + b + ' div.thumb').hover(function () {
                        $(this).animate({
                            'opacity': 1
                        }, 150)
                    }, function () {
                        if (l[0] != this.id.split('_')[1]) $(this).animate({
                            'opacity': .45
                        }, 250)
                    });
                    $('#thumbs' + b + ' div').bind('click', thumbclick);
                    if (!o.displayThumbnailNumbers) $('#thumbs' + b + ' div').text('');
                    if (!o.displayThumbnailBackground) $('#thumbs' + b + ' div').css({
                        
                    })
                }
                if (o.showControls) {
                    
                    if (!o.prevNextInternal) {
                        wrapID = $(c).attr('id') + 'Wrapper';
                        $(c).wrap('<div id="' + wrapID + '"></div>').css('margin', '0 auto');
                        $('#' + wrapID).css('position', 'relative').width(($(c).width() + 40 + parseInt($(c).css('padding-left')) + parseInt($(c).css('padding-right'))))
                    }
                    arrowsTop = ((f / 2) - 15) + parseInt(o.padding);
                    html = '<div class="btn_rt" id="btn_rt' + b + '" style="position:absolute;right:2px;top:' + arrowsTop + 'px;cursor:pointer;border:none;width:13px;height:30px;background:url(' + o.imagePath + 'leftright.gif) no-repeat 0 0"></div>';
                    html += '<div class="btn_lt" id="btn_lt' + b + '" style="position:absolute;left:2px;top:' + arrowsTop + 'px;cursor:pointer;border:none;width:13px;height:30px;background:url(' + o.imagePath + 'leftright.gif) no-repeat -13px 0"></div>';
                    (o.prevNextInternal) ? $(c).append(html) : $('#' + wrapID).append(html);
                    $('#btn_rt' + b).css('opacity', 1).click(function () {
                        forcePrevNext('next')
                    }).hover(function () {
                        $(this).animate({
                            opacity: '0.8'
                        }, 250)
                    }, function () {
                        $(this).animate({
                            opacity: '1'
                        }, 250)
                    });
                    $('#btn_lt' + b).css('opacity', 1).click(function () {
                        forcePrevNext('prev')
                    }).hover(function () {
                        $(this).animate({
                            opacity: '0.8'
                        }, 250)
                    }, function () {
                        $(this).animate({
                            opacity: '1'
                        }, 250)
                    });
                    if (o.autoHideControls && o.prevNextInternal) {
                        function showcontrols() {
                            $('#play_pause_btn' + b).stop().animate({
                                top: '3px',
                                right: '3px'
                            }, 250);
                            $('#btn_rt' + b).stop().animate({
                                top: arrowsTop + 'px',
                                right: '2px'
                            }, 250);
                            $('#btn_lt' + b).stop().animate({
                                top: arrowsTop + 'px',
                                left: '2px'
                            }, 250)
                        }
                        function hidecontrols() {
                            $('#play_pause_btn' + b).stop().animate({
                                top: -16 - h + 'px',
                                right: -16 - h + 'px'
                            }, 250);
                            $('#btn_rt' + b).stop().animate({
                                right: '-16px'
                            }, 250);
                            $('#btn_lt' + b).stop().animate({
                                left: '-16px'
                            }, 250)
                        }
                        $(c).hover(showcontrols, hidecontrols);
                        hidecontrols()
                    }
                    if (o.autoHideCaptions) {
                        var p;

                        function autoShowCap() {
                            p = true;
                            for (i = 1; i <= o.inView; i++) showtext($('li:eq(' + i + ') p', c).html(), i)
                        }
                        function autoHideCap() {
                            p = false;
                            hideCaption()
                        }
                        $(c).hover(autoShowCap, autoHideCap);
                        hideCaption()
                    }
                }
                function keyBind() {
                    if (o.enableKeyboardNav) {
                        $(document).keydown(function (a) {
                            if (a.keyCode == 39) {
                                forcePrevNext('next');
                                $(document).unbind('keydown')
                            }
                            if (a.keyCode == 37) {
                                forcePrevNext('prev');
                                $(document).unbind('keydown')
                            }
                            if (a.keyCode == 80 || a.keyCode == 111) forcePause();
                            if (a.keyCode == 83 || a.keyCode == 115) {
                                forceStart();
                                $(document).unbind('keydown')
                            }
                        })
                    }
                }
                function forcePrevNext(a) {
                    o.onPauseClick.call(this);
                    $('#btn_rt' + b).unbind('click');
                    $('#btn_lt' + b).unbind('click');
                    setTimeout(function () {
                        $('#play_pause_btn' + b).css('background-position', '0 -16px')
                    }, o.transitionSpeed - 1);
                    d = 0;
                    $('#progress' + b).stop().fadeOut();
                    n = 'pause';
                    clearTimeout(q);
                    (a == 'prev') ? moveRight() : moveLeft();
                    $('#play_pause_btn' + b).unbind('click');
                    setTimeout(function () {
                        $('#play_pause_btn' + b).bind('click', function () {
                            forceStart()
                        });
                        $('#btn_rt' + b).bind('click', function () {
                            forcePrevNext('next')
                        });
                        $('#btn_lt' + b).bind('click', function () {
                            forcePrevNext('prev')
                        })
                    }, o.transitionSpeed)
                }
                function forcePause() {
                    $('#play_pause_btn' + b).unbind('click');
                    if (d) {
                        o.onPauseClick.call(this);
                        $('#play_pause_btn' + b).fadeTo(250, 0, function () {
                            $(this).css({
                                'background-position': '0 -16px',
                                'opacity': '.5'
                            })
                        }).animate({
                            opacity: .5
                        }, 250);
                        d = 0;
                        showminmax();
                        $('#progress' + b).stop().fadeOut();
                        clearTimeout(q);
                        setTimeout(function () {
                            $('#play_pause_btn' + b).bind('click', function () {
                                forceStart()
                            })
                        }, o.transitionSpeed)
                    }
                }
                function forceStart() {
                    $('#play_pause_btn' + b).unbind('click');
                    if (!d) {
                        setTimeout(function () {
                            $('#play_pause_btn' + b).css('background-position', '0 0')
                        }, o.transitionSpeed - 1);
                        d = 1;
                        moveLeft();
                        q = setInterval(function () {
                            moveLeft()
                        }, o.displayTime + o.transitionSpeed);
                        setTimeout(function () {
                            $('#play_pause_btn' + b).bind('click', function () {
                                forcePause()
                            })
                        }, o.transitionSpeed)
                    }
                }
                function preMove() {
                    hideCaption();
                    if (o.showControls && o.prevNextInternal) {
                        $('#btn_lt' + b).fadeOut(200);
                        $('#btn_rt' + b).fadeOut(200)
                    }
                    if (o.displayThumbnails) for (i = 1; i <= e; i++) $('#thumb' + b + '_' + i).css({
                        
                    }).animate({
                        'opacity': .45
                    }, 500)
                }
                function postMove() {
                    if (o.showControls && o.prevNextInternal) {
                        $('#btn_lt' + b).fadeIn(200);
                        $('#btn_rt' + b).fadeIn(200)
                    }
                    keyBind();
                    if (o.autoHideCaptions && p) autoShowCap();
                    if (o.displayThumbnails) for (i = 0; i < l.length; i++) $('#thumb' + b + '_' + l[i]).css({
                        
                    }).animate({
                        'opacity': 1
                    }, 500);
                    if (!o.autoHideCaptions) for (i = 1; i <= o.inView; i++) showtext($('li:eq(' + i + ') p', c).html(), i);
                    if (o.displayThumbnails) $('#thumbs' + b + ' div').unbind('click').bind('click', thumbclick).css({
                        'cursor': 'pointer'
                    });
                    ary = [];
                    for (x = 1; x <= o.inView; x++) {
                        ary.push($('img:eq(' + x + ')', c).attr('src'))
                    }
                    o.onSlideEnd.call(this, ary)
                }
                function moveLeft(a) {
                    if (a == null) a = o.advance;
                    preMove();
                    if (o.displayThumbnails) {
                        for (i = 1; i <= a; i++) {
                            l.push(m.shift());
                            m.push(l.shift())
                        }
                    }
                    if (o.displayTime == 0) {
                        clearInterval(q)
                    }
                    $('li:lt(' + a + ')', c).clone(true).insertAfter($('li:last', c));
                    o.onSlideStart.call(this, l, 'left');
                    $('ul', c).animate({
                        left: -g * (a + 1) - (parseInt(o.padding) * (a + 1)) * 2
                    }, o.transitionSpeed, o.easeLeft, function () {
                        $('li:lt(' + a + ')', c).remove();
                        $(this).css({
                            'left': -g - parseInt(o.padding) * 2
                        });
                        if (o.displayProgressBar && d) startProgressBar();
                        postMove();
                        if (o.displayTime == 0) {
                            moveLeft()
                        }
                    })
                }
                function moveRight(a) {
                    if (a == null) a = o.advance;
                    preMove();
                    if (o.displayThumbnails) {
                        for (i = 1; i <= a; i++) {
                            l.unshift(m.pop());
                            m.unshift(l.pop())
                        }
                    }
                    $('li:gt(' + (e - (a + 1)) + ')', c).clone(true).insertBefore($('li:first', c));
                    o.onSlideStart.call(this, l, 'right');
                    $('ul', c).css('left', -(g * (a + 1)) - (parseInt(o.padding) * ((a + 1) * 2))).animate({
                        left: -g - (parseInt(o.padding) * 2)
                    }, o.transitionSpeed, o.easeRight, function () {
                        $('li:gt(' + (e - 1) + ')', c).remove();
                        postMove()
                    })
                }
                if (d) {
                    var q = setInterval(function () {
                        moveLeft()
                    }, o.displayTime + o.transitionSpeed);
                    if (o.displayProgressBar) startProgressBar(o.displayTime + o.transitionSpeed)
                } else {
                    n = 'pause';
                }
                keyBind()
            })
        }
    })
})(jQuery);

(function ($) {
    $.fn.extend({
        infiniteCarouselFade: function (r) {
            var s = {
                transitionSpeed: 800,
                displayTime: 6000,
                textholderHeight: .25,
                displayProgressBar: true,
                displayThumbnails: true,
                displayThumbnailNumbers: true,
                displayThumbnailBackground: true,
                thumbnailWidth: '20px',
                thumbnailHeight: '20px',
                thumbnailFontSize: '.7em',
                easeLeft: 'linear',
                easeRight: 'linear',
                imagePath: '/js/infinitecarousel/images/',
                inView: 1,
                padding: '0px',
                advance: 1,
                showControls: true,
                autoHideControls: false,
                autoHideCaptions: false,
                autoStart: true,
                prevNextInternal: true,
                enableKeyboardNav: true,
                onSlideStart: function () {},
                onSlideEnd: function () {},
                onPauseClick: function () {}
            };
            var r = $.extend(s, r);
            return this.each(function () {
                var b = Math.round(Math.random() * 100000000);
                var o = r;
                var c = $(this);
                var d = o.autoStart;
                var e = $('img', c).length;
                var f = $('img:first', c).height();
                var g = $('img:first', c).width();
                if (o.inView > e - 1) o.inView = e - 1;
                $('p', c).hide();
                $(c).css({
                    'position': 'relative',
                    'overflow': 'hidden'
                }).width((g * o.inView) + (o.inView * parseInt(o.padding) * 2)).height(f + (parseInt(o.padding) * 2));
                $('ul', c).css({
                    'list-style': 'none',
                    'margin': '0',
                    'padding': '0',
                    'position': 'relative'
                }).width(g * e);
                $('li', c).css({
                    'display': 'inline',
                    'float': 'left',
                    'padding': o.padding
                });
                $('li:last', c).prependTo($('ul', c));
                $('ul', c).css('left', -g - (parseInt(o.padding) * 2) + 'px').width(9999);
                if (o.displayProgressBar) {
                    $(c).append('<div id="progress' + b + '" class="ic-progress-bar" style="position:absolute;bottom:0;background:#bbb;left:0;z-index:1"></div>');
                    $('#progress' + b).width('100%').height(5).css('opacity', '.6')
                }
                function startProgressBar(a) {
                    a = (a == null) ? o.displayTime : a;
                    $('#progress' + b).width('100%').height(5);
                    $('#progress' + b).animate({
                        'width': 0
                    }, a)
                }
                var h = parseInt($(c).css('border-bottom-width')) + parseInt($(c).css('border-top-width'));
                if (isNaN(h)) h = 0;
                var j = parseInt($(c).css('padding-left'));
                for (i = 1; i <= o.inView; i++) {
                    $(c).append('<div id="textholder' + b + '_' + i + '" class="textholder" style="position:absolute;width:' + g + 'px;bottom:0px;margin-bottom:' + -(f * o.textholderHeight + h) + 'px;"><span></span></div>');
                    $('#textholder' + b + '_' + i).css({
                        'left': (i - 1) * (g + parseInt(o.padding) * 2),
                        'margin-left': parseInt(o.padding) + j,
                        'margin-right': o.padding
                    });
                    $('#textholder' + b + '_' + i).height(f * o.textholderHeight).css({
                        'backgroundColor': '#FFF',
                        'opacity': '0.5'
                    });
                    html = '<div class="minmax" id="minmax' + b + '_' + i + '" style="width:8px;height:8px;position:absolute;top:1px;right:10px;cursor:pointer;background:url(' + o.imagePath + 'caption.gif) no-repeat 0 -8px"></div>';
                    html += '<div class="close" id="close' + b + '_' + i + '" style="width:8px;height:8px;position:absolute;top:1px;right:1px;cursor:pointer;background:url(' + o.imagePath + 'caption.gif) no-repeat 0 0"></div>';
                    $('#textholder' + b + '_' + i).append(html);
                    $('#minmax' + b + '_' + i).hide();
                    $('#close' + b + '_' + i).hide();
                    if (!o.autoHideCaptions) showtext($('li:eq(' + i + ') p', c).html(), i)
                }
                var k = parseInt($('#textholder' + b + '_1').css('padding-left')) + parseInt($('#textholder' + b + '_1').css('padding-right'));
                if (k > 0) $('.textholder', c).width(g - k);
                $('.close', c).each(function (i) {
                    $(this).click(function () {
                        $('#textholder' + b + '_' + (i + 1)).animate({
                            marginBottom: (-f * o.textholderHeight) - h - 1 + 'px'
                        }, 500)
                    })
                });
                $('.minmax', c).each(function (i) {
                    $(this).click(function () {
                        if (parseInt($('#textholder' + b + '_' + (i + 1)).css('margin-bottom')) == 0) {
                            $('#textholder' + b + '_' + (i + 1)).animate({
                                marginBottom: ((-f * o.textholderHeight) - h + 12) + 'px'
                            }, 500, function () {
                                $('#minmax' + b + '_' + (i + 1)).css('background-position', '0 -16px')
                            })
                        } else {
                            $('#textholder' + b + '_' + (i + 1)).animate({
                                marginBottom: '0px'
                            }, 500, function () {
                                $('#minmax' + b + '_' + (i + 1)).css('background-position', '0 -8px')
                            })
                        }
                    })
                });

                function showtext(t, i) {
                    if (d) {
                        $('#minmax' + b + '_' + i).hide();
                        $('#close' + b + '_' + i).hide()
                    }
                    if (t != null) {
                        $('#textholder' + b + '_' + i + ' span').html(t);
                        $('#textholder' + b + '_' + i).stop().animate({
                            marginBottom: '0px'
                        }, 500);
                        $('#minmax' + b + '_' + i).css('background-position', '0 -8px');
                        showminmax()
                    }
                }
                function showminmax() {
                    if (!d) {
                        $('.minmax', c).fadeIn(250);
                        $('.close', c).fadeIn(250)
                    }
                }
                function hideCaption() {
                    $('.textholder', c).stop().animate({
                        marginBottom: (-f * o.textholderHeight - h - 1) + 'px'
                    }, o.transitionSpeed)
                }
                if (o.displayThumbnails) {
                    function thumbclick(a) {
                        target_num = this.id.split('_');
                        if (l[0] != target_num[1]) {
                            n = 'pause';
                            $('#progress' + b).stop().fadeOut();
                            clearTimeout(q);
                            $('#thumbs' + b + ' div').css({
                                'cursor': 'default'
                            }).unbind('click');
                            d = 0;
                            setTimeout(function () {
                               
                            }, o.transitionSpeed);
                            
                        }
                        if (target_num[1] > l[0]) {
                            diff = target_num[1] - l[0];
                            moveLeft(diff)
                        }
                        if (target_num[1] < l[0]) {
                            diff = l[0] - target_num[1];
                            moveRight(diff)
                        }
                    }
                    var l = [];
                    var m = [];
                    $(c).after('<div class="slider-thumbs" id="thumbs' + b + '"></div>');
                    for (i = 0; i <= e - 1; i++) {
                        thumb = $('img:eq(' + (i + 1) + ')', c).attr('src');
                        $('#thumbs' + b).append('<div class="thumb" id="thumb' + b + '_' + (i + 1) + '" style="cursor:pointer;display:inline;float:left;width:' + o.thumbnailWidth + ';height:' + o.thumbnailHeight + ';line-height:' + o.thumbnailHeight + ';padding:0;overflow:hidden;text-align:center;margin-right:4px;">' + (i + 1) + '</div>');
                        if (i <= o.inView) $('#thumb' + b + '_' + i).css({
                            
                        });
                        m.push(i + 1)
                    }
                    for (i = 1; i <= o.inView; i++) l.push(m.shift());
                    thumb = $('img:first', c).attr('src');
                    $('#thumb' + b + '_' + e).css({
                        
                    });
                    $('#thumbs' + b + ' div.thumb:not(:first)').css({
                        opacity: .45
                    });
                    $('#thumbs' + b + ' div.thumb').hover(function () {
                        $(this).animate({
                            'opacity': 1
                        }, 150)
                    }, function () {
                        if (l[0] != this.id.split('_')[1]) $(this).animate({
                            'opacity': .45
                        }, 250)
                    });
                    $('#thumbs' + b + ' div').bind('click', thumbclick);
                    if (!o.displayThumbnailNumbers) $('#thumbs' + b + ' div').text('');
                    if (!o.displayThumbnailBackground) $('#thumbs' + b + ' div').css({
                        
                    })
                }
                if (o.showControls) {
                    
                    if (!o.prevNextInternal) {
                        wrapID = $(c).attr('id') + 'Wrapper';
                        $(c).wrap('<div id="' + wrapID + '"></div>').css('margin', '0 auto');
                        $('#' + wrapID).css('position', 'relative').width(($(c).width() + 40 + parseInt($(c).css('padding-left')) + parseInt($(c).css('padding-right'))))
                    }
                    arrowsTop = ((f / 2) - 15) + parseInt(o.padding);
                    html = '<div class="btn_rt" id="btn_rt' + b + '" style="position:absolute;right:2px;top:' + arrowsTop + 'px;cursor:pointer;border:none;width:13px;height:30px;background:url(' + o.imagePath + 'leftright.gif) no-repeat 0 0"></div>';
                    html += '<div class="btn_lt" id="btn_lt' + b + '" style="position:absolute;left:2px;top:' + arrowsTop + 'px;cursor:pointer;border:none;width:13px;height:30px;background:url(' + o.imagePath + 'leftright.gif) no-repeat -13px 0"></div>';
                    (o.prevNextInternal) ? $(c).append(html) : $('#' + wrapID).append(html);
                    $('#btn_rt' + b).css('opacity', 1).click(function () {
                        forcePrevNext('next')
                    }).hover(function () {
                        $(this).animate({
                            opacity: '0.8'
                        }, 250)
                    }, function () {
                        $(this).animate({
                            opacity: '1'
                        }, 250)
                    });
                    $('#btn_lt' + b).css('opacity', 1).click(function () {
                        forcePrevNext('prev')
                    }).hover(function () {
                        $(this).animate({
                            opacity: '0.8'
                        }, 250)
                    }, function () {
                        $(this).animate({
                            opacity: '1'
                        }, 250)
                    });
                    if (o.autoHideControls && o.prevNextInternal) {
                        function showcontrols() {
                            $('#play_pause_btn' + b).stop().animate({
                                top: '3px',
                                right: '3px'
                            }, 250);
                            $('#btn_rt' + b).stop().animate({
                                top: arrowsTop + 'px',
                                right: '2px'
                            }, 250);
                            $('#btn_lt' + b).stop().animate({
                                top: arrowsTop + 'px',
                                left: '2px'
                            }, 250)
                        }
                        function hidecontrols() {
                            $('#play_pause_btn' + b).stop().animate({
                                top: -16 - h + 'px',
                                right: -16 - h + 'px'
                            }, 250);
                            $('#btn_rt' + b).stop().animate({
                                right: '-16px'
                            }, 250);
                            $('#btn_lt' + b).stop().animate({
                                left: '-16px'
                            }, 250)
                        }
                        $(c).hover(showcontrols, hidecontrols);
                        hidecontrols()
                    }
                    if (o.autoHideCaptions) {
                        var p;

                        function autoShowCap() {
                            p = true;
                            for (i = 1; i <= o.inView; i++) showtext($('li:eq(' + i + ') p', c).html(), i)
                        }
                        function autoHideCap() {
                            p = false;
                            hideCaption()
                        }
                        $(c).hover(autoShowCap, autoHideCap);
                        hideCaption()
                    }
                }
                function keyBind() {
                    if (o.enableKeyboardNav) {
                        $(document).keydown(function (a) {
                            if (a.keyCode == 39) {
                                forcePrevNext('next');
                                $(document).unbind('keydown')
                            }
                            if (a.keyCode == 37) {
                                forcePrevNext('prev');
                                $(document).unbind('keydown')
                            }
                            if (a.keyCode == 80 || a.keyCode == 111) forcePause();
                            if (a.keyCode == 83 || a.keyCode == 115) {
                                forceStart();
                                $(document).unbind('keydown')
                            }
                        })
                    }
                }
                function forcePrevNext(a) {
                    o.onPauseClick.call(this);
                    $('#btn_rt' + b).unbind('click');
                    $('#btn_lt' + b).unbind('click');
                    setTimeout(function () {
                        $('#play_pause_btn' + b).css('background-position', '0 -16px')
                    }, o.transitionSpeed - 1);
                    d = 0;
                    $('#progress' + b).stop().fadeOut();
                    n = 'pause';
                    clearTimeout(q);
                    (a == 'prev') ? moveRight() : moveLeft();
                    $('#play_pause_btn' + b).unbind('click');
                    setTimeout(function () {
                        $('#play_pause_btn' + b).bind('click', function () {
                            forceStart()
                        });
                        $('#btn_rt' + b).bind('click', function () {
                            forcePrevNext('next')
                        });
                        $('#btn_lt' + b).bind('click', function () {
                            forcePrevNext('prev')
                        })
                    }, o.transitionSpeed)
                }
                function forcePause() {
                    $('#play_pause_btn' + b).unbind('click');
                    if (d) {
                        o.onPauseClick.call(this);
                        $('#play_pause_btn' + b).fadeTo(250, 0, function () {
                            $(this).css({
                                'background-position': '0 -16px',
                                'opacity': '.5'
                            })
                        }).animate({
                            opacity: .5
                        }, 250);
                        d = 0;
                        showminmax();
                        $('#progress' + b).stop().fadeOut();
                        clearTimeout(q);
                        setTimeout(function () {
                            $('#play_pause_btn' + b).bind('click', function () {
                                forceStart()
                            })
                        }, o.transitionSpeed)
                    }
                }
                function forceStart() {
                    $('#play_pause_btn' + b).unbind('click');
                    if (!d) {
                        setTimeout(function () {
                            $('#play_pause_btn' + b).css('background-position', '0 0')
                        }, o.transitionSpeed - 1);
                        d = 1;
                        moveLeft();
                        q = setInterval(function () {
                            moveLeft()
                        }, o.displayTime + o.transitionSpeed);
                        setTimeout(function () {
                            $('#play_pause_btn' + b).bind('click', function () {
                                forcePause()
                            })
                        }, o.transitionSpeed)
                    }
                }
                function preMove() {
                    hideCaption();
                    if (o.showControls && o.prevNextInternal) {
                        $('#btn_lt' + b).fadeOut(200);
                        $('#btn_rt' + b).fadeOut(200)
                    }
                    if (o.displayThumbnails) for (i = 1; i <= e; i++) $('#thumb' + b + '_' + i).css({
                        
                    }).animate({
                        'opacity': .45
                    }, 500)
                }
                function postMove() {
                    if (o.showControls && o.prevNextInternal) {
                        $('#btn_lt' + b).fadeIn(200);
                        $('#btn_rt' + b).fadeIn(200)
                    }
                    keyBind();
                    if (o.autoHideCaptions && p) autoShowCap();
                    if (o.displayThumbnails) for (i = 0; i < l.length; i++) $('#thumb' + b + '_' + l[i]).css({
                        
                    }).animate({
                        'opacity': 1
                    }, 500);
                    if (!o.autoHideCaptions) for (i = 1; i <= o.inView; i++) showtext($('li:eq(' + i + ') p', c).html(), i);
                    if (o.displayThumbnails) $('#thumbs' + b + ' div').unbind('click').bind('click', thumbclick).css({
                        'cursor': 'pointer'
                    });
                    ary = [];
                    for (x = 1; x <= o.inView; x++) {
                        ary.push($('img:eq(' + x + ')', c).attr('src'))
                    }
                    o.onSlideEnd.call(this, ary)
                }
                function moveLeft(a) {
                    if (a == null) a = o.advance;
                    preMove();
                    if (o.displayThumbnails) {
                        for (i = 1; i <= a; i++) {
                            l.push(m.shift());
                            m.push(l.shift())
                        }
                    }
                    if (o.displayTime == 0) {
                        clearInterval(q)
                    }
                    $('li:lt(' + a + ')', c).clone(true).insertAfter($('li:last', c));
                    o.onSlideStart.call(this, l, 'left');
                    $('ul', c).fadeIn({
                        left: -g * (a + 1) - (parseInt(o.padding) * (a + 1)) * 2
                    }, o.transitionSpeed, o.easeLeft, function () {
                        $('li:lt(' + a + ')', c).remove();
                        $(this).css({
                            'left': -g - parseInt(o.padding) * 2
                        });
                        if (o.displayProgressBar && d) startProgressBar();
                        postMove();
                        if (o.displayTime == 0) {
                            moveLeft()
                        }
                    })
                }
                function moveRight(a) {
                    if (a == null) a = o.advance;
                    preMove();
                    if (o.displayThumbnails) {
                        for (i = 1; i <= a; i++) {
                            l.unshift(m.pop());
                            m.unshift(l.pop())
                        }
                    }
                    $('li:gt(' + (e - (a + 1)) + ')', c).clone(true).insertBefore($('li:first', c));
                    o.onSlideStart.call(this, l, 'right');
                    $('ul', c).css('left', -(g * (a + 1)) - (parseInt(o.padding) * ((a + 1) * 2))).animate({
                        left: -g - (parseInt(o.padding) * 2)
                    }, o.transitionSpeed, o.easeRight, function () {
                        $('li:gt(' + (e - 1) + ')', c).remove();
                        postMove()
                    })
                }
                if (d) {
                    var q = setInterval(function () {
                        moveLeft()
                    }, o.displayTime + o.transitionSpeed);
                    if (o.displayProgressBar) startProgressBar(o.displayTime + o.transitionSpeed)
                } else {
                    n = 'pause';
                }
                keyBind()
            })
        }
    })
})(jQuery);
