/*
 * InfiniteCarousel v1.1.0
 * Based off code from http://jqueryfordesigners.com/jquery-infinite-carousel/
 *
 * Author: Stephen Jones (Steve Jones)
 * Date: 2009-09-03 16:37
 * 
 * 1.1.0 - Added in Auto-Scroll to carousel, fixed timing issue with autoscroll.
 * 1.0.3 - Updated the class hover effect and removes any pre-set styles from the items.
 * 1.0.2 - Disables the carousel if not enough items are displayed (degrades nicely).
*/
(function () {
    jQuery.fn.infiniteCarousel = function (d, e, b, c, a) {
        return this.each(function () {
            var t = jQuery("> div", this).css("overflow", "hidden"),
                m = t.find("> ul").width(9999),
                g = m.find("> li"),
                p = g.filter(":first"),
                f, n = p.outerWidth(true),
                q = Math.floor(t.innerWidth() / n),
                r = q + Math.ceil(q / 2),
                i = g.length,
                o = null,
                h = null,
                l = (e > 0) ? true : false;
            e = (e < q) ? e : q;
            if (c == null && a == null) {
                c = 1000;
                a = 1
            }
            if (i <= q) {
                return
            }
            g.removeAttr("style");
            g.filter(":first").before(g.slice(-r).clone(true).addClass("cloned"));
            g.filter(":last").after(g.slice(0, r).clone(true).addClass("cloned"));
            g = m.find("> li");
            f = m.find(".cloned");
            cloneAmount = f.length / 2;
            t.scrollLeft(n * cloneAmount);

            function j(w, v) {
                var u = n * w;
                var x = (t.scrollLeft() % n);
                if (v && t.filter(":animated").length > 0) {
                    return
                }
                if (w > 0) {
                    u -= x
                } else {
                    u += (x > 0) ? n - x : 0
                }
                t.filter(":animated").stop(true);
                t.animate({
                    scrollLeft: "+=" + u
                }, {
                    queue: false,
                    duration: d,
                    easing: b
                }, k())
            }
            function k() {
                var u = t.scrollLeft() / n;
                if (u <= q) {
                    t.scrollLeft(n * (u + i))
                } else {
                    if (u >= i + cloneAmount - Math.ceil(q / 2) - 1) {
                        t.scrollLeft(n * (u - i))
                    }
                }
            }
            function s() {
                if (c > 0 && a != 0) {
                    h = setInterval(function () {
                        j(a, true)
                    }, (d + c))
                }
            }
            t.after('<a href="#" class="arrow back">&lt;</a><a href="#" class="arrow forward">&gt;</a>');
            jQuery("a.back", this).click(function () {
                j(-q, false);
                return false
            });
            jQuery("a.forward", this).click(function () {
                j(+q, false);
                return false
            });
            s();
            if (l) {
                jQuery("a.forward", this).hover(function () {
                    clearInterval(h);
                    j(e, true);
                    o = setInterval(function () {
                        j(e, true)
                    }, (d * 2))
                }, function () {
                    clearInterval(o);
                    s()
                });
                jQuery("a.back", this).hover(function () {
                    clearInterval(h);
                    j(-e, true);
                    o = setInterval(function () {
                        j(-e, true)
                    }, (d * 2))
                }, function () {
                    clearInterval(o);
                    s()
                })
            }
        })
    }
})(jQuery);
jQuery(document).ready(function () {
    jQuery(".wrapper a.packshot img").mouseover(function () {
        jQuery(this).fadeTo(250, 0.75);
        jQuery(this).fadeTo(500, 1)
    })
});
