/*
 * Title: Boutique carousel jQuery plugin
 * Author: Berend de Jong, Frique
 * Author URI: http://www.frique.me/
 * Version: 1.33 (20110910.2)
 */
 
(function ($) {
    $.fn.boutique = function (q) {
        var o = $.extend({
            container_width: 800,
            front_img_width: 280,
            front_img_height: 400,
            starter: 1,
            speed: 600,
            behind_opac: 0.4,
            back_opac: 0.15,
            behind_size: 0.7,
            back_size: 0.4,
            behind_distance: 'auto',
            autoplay: false,
            autointerval: 3000,
            freescroll: true,
            hovergrowth: 0.08,
            easing: 'easeInOutQuad',
            move_more_easein: 'easeInQuad',
            move_more_easebetween: 'linear',
            move_more_easeout: 'easeOutQuad',
            move_more_directly: false,
            never_move_twice: false,
            text_front_only: false,
            text_opacity: 0.7,
            keyboard: true,
            move_on_hover: false
        }, q);
        $(this).each(function () {
            var f = $(this),
                $parent = f.parent(),
                $lis = $('li', f);
            var g, easingplugin, hoverspeed, $newitem1, $newitem2, $newitem3, $newitem4, $newitem5, zpeed, next, iegrow, container_height, containerid = f.attr('id'),
                busy = false,
                current = o.starter,
                items = $lis.length,
                ie = false,
                ie6 = false,
                container_100 = false;
            if ($.browser.msie) {
                ie = true;
                if ($.browser.version < 7) {
                    ie6 = true
                }
            }
            if (o.hoverspeed) {
                hoverspeed = o.hoverspeed
            } else {
                hoverspeed = (o.speed / 4)
            }
            if (o.starter > items) {
                o.starter = items
            }
            if ($.easing.def) {
                easingplugin = true;
                $.easing.def = o.easing
            } else {
                easingplugin = false
            }
            var x = 1;
            var h = [];
            $lis.each(function () {
                var a = $(this);
                a.addClass('li' + x);
                var b = a.find('img').attr('alt'),
                    $span = a.find('span');
                if (!$span.length) {
                    if (a.find('a').length) {
                        a.children('a').append('<span/>')
                    } else {
                        a.append('<span/>')
                    }
                    $span = a.find('span');
                    if (!b) {
                        $span.hide()
                    }
                } else {
                    $span = a.find('span')
                }
                var c = $('<h6>' + b + '</h6>').prependTo($span);
                if (!b) {
                    c.hide()
                }
                h[x] = a;
                x++
            });
            if (items == 1) {
                h[1].clone().addClass('frame1').prependTo(f);
                h[1].clone().addClass('frame2').prependTo(f)
            } else if (o.starter == 2) {
                h[1].clone().addClass('frame2').prependTo(f);
                h[items].clone().addClass('frame1').prependTo(f)
            } else if (o.starter == 1) {
                h[items - 1].clone().addClass('frame1').prependTo(f);
                h[items].clone().addClass('frame2').prependTo(f)
            } else {
                h[o.starter - 1].clone().addClass('frame2').prependTo(f);
                h[o.starter - 2].clone().addClass('frame1').prependTo(f)
            }
            h[o.starter].clone().addClass('frame3').prependTo(f);
            if (items == 1) {
                h[1].clone().addClass('frame4').prependTo(f);
                h[1].clone().addClass('frame5').prependTo(f)
            } else if (o.starter == (items - 1)) {
                h[items].clone().addClass('frame4').prependTo(f);
                h[1].clone().addClass('frame5').prependTo(f)
            } else if (o.starter == items) {
                h[1].clone().addClass('frame4').prependTo(f);
                h[2].clone().addClass('frame5').prependTo(f)
            } else {
                h[o.starter + 1].clone().addClass('frame4').prependTo(f);
                h[o.starter + 2].clone().addClass('frame5').prependTo(f)
            }
            var i = f.find('.frame1'),
                $item2 = f.find('.frame2'),
                $item3 = f.find('.frame3'),
                $item4 = f.find('.frame4'),
                $item5 = f.find('.frame5');
            i.add($item5).show().animate({
                opacity: 0
            }, 0).addClass('back');
            $item2.add($item4).show().animate({
                opacity: 0
            }, 0).addClass('behind');
            $item3.show().animate({
                opacity: 0
            }, 0).addClass('front');
            var j = $('.back', f),
                $behind = $('.behind', f),
                $front = $('.front', f);
            if (o.container_width == '100%') {
                container_100 = true;
                o.container_width = parseInt($parent.width(), 10)
            }
            var k = parseInt($lis.css('borderLeftWidth'), 10),
                li_padding = parseInt($lis.css('padding-left'), 10),
                front_header = $('h6', $front).css('font-size'),
                front_span = $('span', $front).css('font-size'),
                front_top = $front.css('margin-top'),
                front_margin = parseInt($('img', $front).css('margin-left'), 10),
                front_width = Math.round(o.front_img_width + (front_margin * 2) + (li_padding * 2) + (k * 2)),
                front_height = Math.round(o.front_img_height + (front_margin * 2) + (li_padding * 2) + (k * 2)),
                behind_img_width = Math.round(o.front_img_width * o.behind_size),
                behind_img_height = Math.round(o.front_img_height * o.behind_size),
                behind_header = $('h6', $behind).css('font-size'),
                behind_span = $('span', $behind).css('font-size'),
                behind_top = $behind.css('margin-top'),
                behind_margin = parseInt($('img', $behind).css('margin-left'), 10),
                behind_width = Math.round(behind_img_width + (behind_margin * 2) + (li_padding * 2) + (k * 2)),
                behind_height = Math.round(behind_img_height + (behind_margin * 2) + (li_padding * 2) + (k * 2)),
                back_img_width = Math.round(o.front_img_width * o.back_size),
                back_img_height = Math.round(o.front_img_height * o.back_size),
                back_header = $('h6', j).css('font-size'),
                back_span = $('span', j).css('font-size'),
                back_top = j.css('margin-top'),
                back_margin = parseInt($('img', j).css('margin-left'), 10),
                back_width = Math.round(back_img_width + (back_margin * 2) + (li_padding * 2) + (k * 2)),
                back_height = Math.round(back_img_height + (back_margin * 2) + (li_padding * 2) + (k * 2)),
                item3_pos = Math.round((o.container_width / 2) - (front_width / 2)),
                item5_pos = (o.container_width - back_width),
                item2_pos;
            if (o.behind_distance != 'auto') {
                item2_pos = parseInt(o.behind_distance, 10)
            } else {
                item2_pos = Math.round((o.container_width / 4) - (behind_width / 2))
            }
            var l = (o.container_width - item2_pos - behind_width);
            j.removeClass('back');
            $behind.removeClass('behind');
            $front.removeClass('front');
            var m = $('span', $lis).css('padding-top'),
                front_span_paddingRight = $('span', $lis).css('padding-right'),
                front_span_paddingBottom = $('span', $lis).css('padding-bottom'),
                front_span_paddingLeft = $('span', $lis).css('padding-left'),
                front_span_animate = {
                    opacity: o.text_opacity,
                    fontSize: front_span,
                    paddingTop: m,
                    paddingRight: front_span_paddingRight,
                    paddingBottom: front_span_paddingBottom,
                    paddingLeft: front_span_paddingLeft
                },
                behind_span_animate = {
                    opacity: o.text_opacity,
                    fontSize: behind_span,
                    paddingTop: Math.round(parseInt(m, 10) * 0.8),
                    paddingRight: Math.round(parseInt(front_span_paddingRight, 10) * 0.8),
                    paddingBottom: Math.round(parseInt(front_span_paddingBottom, 10) * 0.8),
                    paddingLeft: Math.round(parseInt(front_span_paddingLeft, 10) * 0.8)
                },
                back_span_animate = {
                    opacity: o.text_opacity,
                    fontSize: back_span,
                    paddingTop: Math.round(parseInt(m, 10) * 0.6),
                    paddingRight: Math.round(parseInt(front_span_paddingRight, 10) * 0.6),
                    paddingBottom: Math.round(parseInt(front_span_paddingBottom, 10) * 0.6),
                    paddingLeft: Math.round(parseInt(front_span_paddingLeft, 10) * 0.6)
                };
            if (o.text_front_only) {
                behind_span_animate.opacity = 0;
                back_span_animate.opacity = 0
            }
            if (ie6) {
                var n = (parseInt($('span:visible', $front).css('margin-left'), 10) + parseInt($('span:visible', $front).css('margin-right'), 10)),
                    behind_span_margin = (parseInt($('span:visible', $behind).css('margin-left'), 10) + parseInt($('span:visible', $behind).css('margin-right'), 10)),
                    back_span_margin = (parseInt($('span:visible', j).css('margin-left'), 10) + parseInt($('span:visible', j).css('margin-right'), 10)),
                    ie6_front_span_animate = $.extend({
                        width: front_width - parseInt(front_span_paddingRight, 10) - parseInt(front_span_paddingLeft, 10) - n - (k * 2)
                    }, front_span_animate),
                    ie6_behind_span_animate = $.extend({
                        width: behind_width - behind_span_animate.paddingRight - behind_span_animate.paddingLeft - behind_span_margin - (k * 2)
                    }, behind_span_animate),
                    ie6_back_span_animate = $.extend({
                        width: back_width - back_span_animate.paddingRight - back_span_animate.paddingRight - back_span_margin - (k * 2)
                    }, back_span_animate)
            }
            var p = (front_height + parseInt(front_top, 10)),
                behind_space = (behind_height + parseInt(behind_top, 10)),
                back_space = (back_height + parseInt(back_top, 10));
            if (p > behind_space && p > back_space) {
                container_height = p
            } else if (behind_space > p && behind_space > back_space) {
                container_height = behind_space
            } else {
                container_height = back_space
            }
            f.height(container_height).width(o.container_width);
            i.css({
                left: 0,
                bottom: 0
            }).animate({
                opacity: o.back_opac
            }, 0).find('img').animate({
                width: back_img_width,
                height: back_img_height,
                margin: back_margin,
                opacity: 1
            }, 0).siblings('span:visible').css(back_span_animate).children('h6:visible').css({
                'font-size': back_header
            });
            $item2.css({
                left: item2_pos,
                bottom: 0,
                'z-index': 2
            }).animate({
                opacity: o.behind_opac
            }, 0).find('img').animate({
                width: behind_img_width,
                height: behind_img_height,
                margin: behind_margin,
                opacity: 1
            }, 0).siblings('span:visible').css(behind_span_animate).children('h6:visible').css({
                'font-size': behind_header
            });
            $item3.css({
                left: item3_pos,
                bottom: 0,
                'z-index': 3
            }).animate({
                opacity: 1
            }, 0).find('a *').css({
                cursor: 'pointer'
            }).end().find('img').animate({
                width: o.front_img_width,
                height: o.front_img_height,
                margin: front_margin,
                opacity: 1
            }, 0).siblings('span:visible').css(front_span_animate).children('h6:visible').css({
                'font-size': front_header
            });
            $item4.css({
                left: l,
                bottom: 0,
                'z-index': 2
            }).animate({
                opacity: o.behind_opac
            }, 0).find('img').animate({
                width: behind_img_width,
                height: behind_img_height,
                margin: behind_margin,
                opacity: 1
            }, 0).siblings('span:visible').css(behind_span_animate).children('h6:visible').css({
                'font-size': behind_header
            });
            $item5.css({
                left: item5_pos,
                bottom: 0
            }).animate({
                opacity: o.back_opac
            }, 0).find('img').animate({
                width: back_img_width,
                height: back_img_height,
                margin: back_margin,
                opacity: 1
            }, 0).siblings('span:visible').css(back_span_animate).children('h6:visible').css({
                'font-size': back_header
            });
            if (ie6) {
                $('span:visible', j).css(ie6_back_span_animate);
                $('span:visible', $behind).css(ie6_behind_span_animate);
                $('span:visible', $front).css(ie6_front_span_animate)
            }
            function setContainerWidth() {
                var a = parseInt($parent.width(), 10);
                f.width(a);
                item2_pos = Math.round((a / 4) - (behind_width / 2));
                item3_pos = Math.round((a / 2) - (front_width / 2));
                l = (a - item2_pos - behind_width);
                item5_pos = (a - back_width);
                $item2.css({
                    left: item2_pos
                });
                $item3.css({
                    left: item3_pos
                });
                $item4.css({
                    left: l
                });
                $item5.css({
                    left: item5_pos
                })
            };
            if (container_100) {
                setContainerWidth()
            }
            function stopInterval() {
                if (g) {
                    clearInterval(g);
                    g = false
                }
            };

            function startInterval() {
                if (g) {
                    stopInterval()
                }
                g = setInterval(function () {
                    $item4.click()
                }, o.autointerval)
            };

            function moveRight(b, c) {
                busy = true;
                c = c || 'normal';
                var d = 'swing';
                zpeed = o.speed;
                if (b > 1 && c == 'first') {
                    if (easingplugin) {
                        d = o.move_more_easein
                    }
                    zpeed = Math.round(o.speed * 0.7)
                } else if (b > 1) {
                    if (easingplugin) {
                        d = o.move_more_easebetween
                    }
                    zpeed = Math.round(o.speed * 0.7)
                } else if (c == 'last') {
                    if (easingplugin) {
                        d = o.move_more_easeout
                    }
                } else {
                    if (easingplugin) {
                        d = o.easing
                    }
                }
                if (o.autoplay) {
                    stopInterval()
                }
                if (current == (items - 2)) {
                    next = 1
                } else if (current == (items - 1)) {
                    next = 2;
                    if (next > items) {
                        next = 1
                    }
                } else if (current == items) {
                    next = 3;
                    if (next > items) {
                        next = 1
                    }
                } else {
                    next = (current + 3)
                }
                i.removeClass('frame1').addClass('remove').css('z-index', -1);
                $newitem1 = $item2;
                $newitem1.removeClass('frame2').addClass('frame1').stop().animate({
                    opacity: o.back_opac,
                    left: 0,
                    bottom: 0
                }, zpeed, d).find('img').stop().animate({
                    width: back_img_width,
                    height: back_img_height,
                    marginTop: back_margin,
                    marginRight: back_margin,
                    marginBottom: back_margin,
                    marginLeft: back_margin,
                    opacity: 1
                }, zpeed, d).end().find('h6:visible').stop().animate({
                    'font-size': back_header
                }, zpeed, d);
                if (ie6) {
                    $newitem1.find('span:visible').stop().animate(ie6_back_span_animate, zpeed, d)
                } else {
                    $newitem1.find('span').stop().animate(back_span_animate, zpeed, d)
                }
                setTimeout(function () {
                    $newitem1.css('z-index', 1)
                }, (zpeed / 4));
                $newitem2 = $item3;
                $newitem2.removeClass('frame3').addClass('frame2').stop().animate({
                    opacity: o.behind_opac,
                    left: item2_pos,
                    bottom: 0
                }, zpeed, d).find('img').stop().animate({
                    width: behind_img_width,
                    height: behind_img_height,
                    marginTop: behind_margin,
                    marginRight: behind_margin,
                    marginBottom: behind_margin,
                    marginLeft: behind_margin,
                    opacity: 1
                }, zpeed, d).end().find('h6:visible').stop().animate({
                    'font-size': behind_header
                }, zpeed, d);
                if (ie6) {
                    $newitem2.find('span:visible').stop().animate(ie6_behind_span_animate, zpeed, d)
                } else {
                    $newitem2.find('span').stop().animate(behind_span_animate, zpeed, d)
                }
                setTimeout(function () {
                    $newitem2.css('z-index', 2)
                }, (zpeed / 4));
                $newitem3 = $item4;
                $newitem3.removeClass('frame4').addClass('frame3').stop().animate({
                    opacity: 1,
                    left: item3_pos,
                    bottom: 0
                }, zpeed, d).find('img').stop().animate({
                    width: o.front_img_width,
                    height: o.front_img_height,
                    marginTop: front_margin,
                    marginRight: front_margin,
                    marginBottom: front_margin,
                    marginLeft: front_margin,
                    opacity: 1
                }, zpeed, d).end().find('h6:visible').stop().animate({
                    'font-size': front_header
                }, zpeed, d);
                if (ie6) {
                    $newitem3.find('span:visible').stop().animate(ie6_front_span_animate, zpeed, d)
                } else {
                    $newitem3.find('span').stop().animate(front_span_animate, zpeed, d)
                }
                setTimeout(function () {
                    $newitem3.css('z-index', 3)
                }, (zpeed / 4));
                $newitem4 = $item5;
                $newitem4.removeClass('frame5').addClass('frame4').stop().animate({
                    opacity: o.behind_opac,
                    left: l,
                    bottom: 0
                }, zpeed, d).find('img').stop().animate({
                    width: behind_img_width,
                    height: behind_img_height,
                    marginTop: behind_margin,
                    marginRight: behind_margin,
                    marginBottom: behind_margin,
                    marginLeft: behind_margin,
                    opacity: 1
                }, zpeed, d).end().find('h6:visible').stop().animate({
                    'font-size': behind_header
                }, zpeed, d);
                if (ie6) {
                    $newitem4.find('span:visible').stop().animate(ie6_behind_span_animate, zpeed, d)
                } else {
                    $newitem4.find('span').stop().animate(behind_span_animate, zpeed, d)
                }
                setTimeout(function () {
                    $newitem4.css('z-index', 2)
                }, (zpeed / 4));
                h[next].clone().addClass('frame5').prependTo(f).show().animate({
                    opacity: 0,
                    left: item5_pos,
                    bottom: 0
                }, 0).animate({
                    opacity: o.back_opac
                }, zpeed, function () {
                    $newitem2.find('a *').css({
                        cursor: 'default'
                    });
                    if (o.autoplay) {
                        startInterval()
                    }
                    if (b == 2) {
                        moveRight(1, 'last')
                    } else if (b > 1) {
                        moveRight(b - 1)
                    } else {
                        $newitem3.find('a *').css({
                            cursor: 'pointer'
                        })
                    }
                    if (!$newitem3.is(':animated')) {
                        busy = false;
                        f.find('.remove').stop().fadeOut(zpeed, function () {
                            $(this).remove()
                        });
                        if (typeof move_callback == 'function') {
                            var a = $newitem3.find('a').attr('href');
                            if (!a) {
                                a = 'no_anchor'
                            }
                            move_callback(a)
                        }
                    }
                }).find('img').animate({
                    width: back_img_width,
                    height: back_img_height,
                    margin: back_margin,
                    opacity: 1
                }, 0).end().find('h6:visible').css({
                    'font-size': back_header
                });
                i = $newitem1, $item2 = $newitem2, $item3 = $newitem3, $item4 = $newitem4, $item5 = f.find('.frame5');
                if (ie6) {
                    $item5.find('span:visible').animate(ie6_back_span_animate, 0)
                } else {
                    $item5.find('span').animate(back_span_animate, 0)
                }
                f.find('.remove').fadeOut(zpeed, function () {
                    $(this).remove()
                });
                if (current == items) {
                    current = 1
                } else {
                    current = (current + 1)
                }
            };

            function moveLeft(b, c) {
                busy = true;
                c = c || 'normal';
                var d = 'swing';
                var e = o.speed;
                if (b > 1 && c == 'first') {

                    if (easingplugin) {
                        d = o.move_more_easein
                    }
                    e = Math.round(o.speed * 0.7)
                } else if (b > 1) {
                    if (easingplugin) {
                        d = o.move_more_easebetween
                    }
                    e = Math.round(o.speed * 0.7)
                } else if (c == 'last') {
                    if (easingplugin) {
                        d = o.move_more_easeout
                    }
                } else {
                    if (easingplugin) {
                        d = o.easing
                    }
                }
                if (o.autoplay) {
                    stopInterval()
                }
                if (current == 3) {
                    next = items
                } else if (current == 2) {
                    next = (items - 1);
                    if (next < 1) {
                        next = items
                    }
                } else if (current == 1) {
                    next = (items - 2);
                    if (next < 1) {
                        next = items
                    }
                } else {
                    next = (current - 3)
                }
                $item5.removeClass('frame5').addClass('remove').css('z-index', -1);
                $newitem5 = $item4;
                $newitem5.removeClass('frame4').addClass('frame5').stop().animate({
                    opacity: o.back_opac,
                    left: item5_pos,
                    bottom: 0
                }, e, d).find('img').stop().animate({
                    width: back_img_width,
                    height: back_img_height,
                    marginTop: back_margin,
                    marginRight: back_margin,
                    marginBottom: back_margin,
                    marginLeft: back_margin,
                    opacity: 1
                }, e, d).end().find('h6:visible').stop().animate({
                    'font-size': back_header
                }, e, d);
                if (ie6) {
                    $newitem5.find('span:visible').stop().animate(ie6_back_span_animate, e, d)
                } else {
                    $newitem5.find('span').stop().animate(back_span_animate, e, d)
                }
                setTimeout(function () {
                    $newitem5.css('z-index', 1)
                }, (e / 4));
                $newitem4 = $item3;
                $newitem4.removeClass('frame3').addClass('frame4').stop().animate({
                    opacity: o.behind_opac,
                    left: l,
                    bottom: 0
                }, e, d).find('img').stop().animate({
                    width: behind_img_width,
                    height: behind_img_height,
                    marginTop: behind_margin,
                    marginRight: behind_margin,
                    marginBottom: behind_margin,
                    marginLeft: behind_margin,
                    opacity: 1
                }, e, d).end().find('h6:visible').stop().animate({
                    'font-size': behind_header
                }, e, d);
                if (ie6) {
                    $newitem4.find('span:visible').stop().animate(ie6_behind_span_animate, e, d)
                } else {
                    $newitem4.find('span').stop().animate(behind_span_animate, e, d)
                }
                setTimeout(function () {
                    $newitem4.css('z-index', 2)
                }, (e / 4));
                $newitem3 = $item2;
                $newitem3.removeClass('frame2').addClass('frame3').stop().animate({
                    opacity: 1,
                    left: item3_pos,
                    bottom: 0
                }, e, d).find('img').stop().animate({
                    width: o.front_img_width,
                    height: o.front_img_height,
                    marginTop: front_margin,
                    marginRight: front_margin,
                    marginBottom: front_margin,
                    marginLeft: front_margin,
                    opacity: 1
                }, e, d).end().find('h6:visible').stop().animate({
                    'font-size': front_header
                }, e, d);
                if (ie6) {
                    $newitem3.find('span:visible').stop().animate(ie6_front_span_animate, e, d)
                } else {
                    $newitem3.find('span').stop().animate(front_span_animate, e, d)
                }
                setTimeout(function () {
                    $newitem3.css('z-index', 3)
                }, (e / 4));
                $newitem2 = i;
                $newitem2.removeClass('frame1').addClass('frame2').stop().animate({
                    opacity: o.behind_opac,
                    left: item2_pos,
                    bottom: 0
                }, e, d).find('img').stop().animate({
                    width: behind_img_width,
                    height: behind_img_height,
                    marginTop: behind_margin,
                    marginRight: behind_margin,
                    marginBottom: behind_margin,
                    marginLeft: behind_margin,
                    opacity: 1
                }, e, d).end().find('h6:visible').stop().animate({
                    'font-size': behind_header
                }, e, d);
                if (ie6) {
                    $newitem2.find('span:visible').stop().animate(ie6_behind_span_animate, e, d)
                } else {
                    $newitem2.find('span').stop().animate(behind_span_animate, e, d)
                }
                setTimeout(function () {
                    $newitem2.css('z-index', 2)
                }, (e / 4));
                h[next].clone().addClass('frame1').prependTo(f).show().animate({
                    opacity: 0,
                    left: 0,
                    bottom: 0
                }, 0).animate({
                    opacity: o.back_opac
                }, e, function () {
                    $newitem4.find('a *').css({
                        cursor: 'default'
                    });
                    if (o.autoplay) {
                        startInterval()
                    }
                    if (b == 2) {
                        moveLeft(1, 'last')
                    } else if (b > 1) {
                        moveLeft(b - 1)
                    } else {
                        $newitem3.find('a *').css({
                            cursor: 'pointer'
                        })
                    }
                    if (!$newitem3.is(':animated')) {
                        busy = false;
                        f.find('.remove').stop().fadeOut(e, function () {
                            $(this).remove()
                        });
                        if (typeof move_callback == 'function') {
                            var a = $newitem3.find('a').attr('href');
                            if (!a) {
                                a = 'no_anchor'
                            }
                            move_callback(a)
                        }
                    }
                }).find('img').animate({
                    width: back_img_width,
                    height: back_img_height,
                    margin: back_margin,
                    opacity: 1
                }, 0).end().find('h6:visible').css({
                    'font-size': back_header
                });
                i = f.find('.frame1'), $item2 = $newitem2, $item3 = $newitem3, $item4 = $newitem4, $item5 = $newitem5;
                if (ie6) {
                    i.find('span:visible').animate(ie6_back_span_animate, 0)
                } else {
                    i.find('span').animate(back_span_animate, 0)
                }
                f.find('.remove').fadeOut(e, function () {
                    $(this).remove()
                });
                if (current == 1) {
                    current = items
                } else {
                    current = (current - 1)
                }
            };
            window[containerid + '_ext_prev'] = function () {
                moveLeft(1)
            };
            window[containerid + '_ext_next'] = function () {
                moveRight(1)
            };
            i.live('click', function (e) {
                if (o.freescroll || !busy) {
                    if (o.never_move_twice) {
                        moveLeft(1)
                    } else if (o.move_more_directly) {
                        moveLeft(1);
                        moveLeft(1)
                    } else {
                        moveLeft(2, 'first')
                    }
                    e.preventDefault()
                }
            });
            $item2.live('click', function (e) {
                if (o.freescroll || !busy) {
                    moveLeft(1);
                    e.preventDefault()
                }
            });
            $item4.live('click', function (e) {
                if (o.freescroll || !busy) {
                    moveRight(1);
                    e.preventDefault()
                }
            });
            $item5.live('click', function (e) {
                if (o.freescroll || !busy) {
                    if (o.never_move_twice) {
                        moveRight(1)
                    } else if (o.move_more_directly) {
                        moveRight(1);
                        moveRight(1)
                    } else {
                        moveRight(2, 'first')
                    }
                    e.preventDefault()
                }
            });
            if (o.move_on_hover) {
                i.live('mousemove', function () {
                    i.click()
                });
                $item2.live('mousemove', function () {
                    $item2.click()
                });
                $item4.live('mousemove', function () {
                    $item4.click()
                });
                $item5.live('mousemove', function () {
                    $item5.click()
                })
            }
            $item3.live('hover', function (e) {
                if ((e.type == 'mouseover' || e.type == 'mouseenter') && !busy) {
                    if (o.autoplay) {
                        stopInterval()
                    }
                    $item3.addClass('zoomed').stop(true, true).animate({
                        left: '-=' + (o.front_img_width * (o.hovergrowth / 2)),
                        bottom: 0 /*'-=' + (o.front_img_height * o.hovergrowth)*/
                    }, hoverspeed).find('img').stop().animate({
                        width: (o.front_img_width * (1 + o.hovergrowth)),
                        height: (o.front_img_height * (1 + o.hovergrowth))
                    }, hoverspeed);
                    $item2.stop(true, true).animate({
                        left: '-=' + (behind_img_width * o.hovergrowth)
                    }, hoverspeed);
                    $item4.stop(true, true).animate({
                        left: '+=' + (behind_img_width * o.hovergrowth)
                    }, hoverspeed);
                    if (ie6) {
                        iegrow = Math.round(o.hovergrowth * o.front_img_width);
                        $item3.find('span:visible').animate({
                            width: '+=' + iegrow
                        }, hoverspeed)
                    }
                } else if (!busy) {
                    if (o.autoplay) {
                        startInterval()
                    }
                    $item3.stop().animate({
                        left: item3_pos,
                        bottom: 0
                    }, hoverspeed).find('img').stop().animate({
                        width: o.front_img_width,
                        height: o.front_img_height
                    }, hoverspeed, function () {
                        $item3.removeClass('zoomed')
                    });
                    $item2.stop().animate({
                        left: item2_pos
                    }, hoverspeed);
                    $item4.stop().animate({
                        left: l
                    }, hoverspeed);
                    if (ie6) {
                        iegrow = Math.round(o.hovergrowth * o.front_img_width);
                        f.find('.zoomed span:visible').animate({
                            width: '-=' + iegrow
                        }, hoverspeed)
                    }
                }
            });
            if (!ie) {
                f.find('.frame3:not(.zoomed)').live('mousemove', function () {
                    $item3.mouseover()
                })
            }
            $item3.find('a').live('click', function () {
                if (typeof link_callback == 'function') {
                    link_callback($(this).attr('href'))
                }
            });
            if (o.keyboard) {
                $(document).keydown(function (e) {
                    if (e.keyCode == 13 || e.keyCode == 32 || e.keyCode == 39) {
                        moveRight(1)
                    }
                    if (e.keyCode == 37) {
                        moveLeft(1)
                    }
                })
            }
            if (o.autoplay) {
                startInterval()
            }
            if (container_100) {
                $(window).resize(function () {
                    setContainerWidth()
                })
            }
        })
    }
})(jQuery);
