﻿/* ------------------------------------------------------ */
/* movie.js
/* ------------------------------------------------------ */
/* Created: 04/05/2010 (dd/mm/yy)
/* Copyright: Jack Wills Ltd.
/* URL: http://www.aubincinema.com/Movie/{id}
/* ------------------------------------------------------ */
var $movie = {
    context: false,
    self: this,

    init: function() {
        self.context = $core.context;
        
        $('#image_slider > div').slideshow({
            slideWidth: 180,
            slideHeight: 135
        });
    }
};

$(function() {
    $movie.init();
});

/* ----------------------------------------------------------------------------- */
/* Mini Slideshow plugin
/* ----------------------------------------------------------------------------- */
/* Copyright: Jack Wills Ltd.
/* Created: 04/05/2010
/* ----------------------------------------------------------------------------- */
(function($) {

    $.fn.slideshow = function(options) {
        var self = this, o, $slideshow, $slides, count, timer;

        // merge passed options with default options
        o = $.extend({}, $.fn.slideshow.defaults, options);

        function prepareMe() {
            if (o.effect === 'fade') {
                prepareFade();
            }
        }

        function fade(el) {
            clearTimeout(timer);

            timer = setTimeout(function() {
                el.fadeOut('slow', function() {
                    var next = (el.next().length) ? el.next() : $slides.eq(0),
                        nextNext = (next.next().length) ? next.next() : $slides.eq(0);

                    el.css('z-index', '0');
                    next.css('z-index', '2');
                    nextNext.css('z-index', '1');

                    if (!el.next().next().length) {
                        $slides.show();
                    }

                    fade(next);
                });
            }, 3000);
        }

        function prepareFade() {
            $slideshow.css({
                'position': 'relative',
                'width': o.slideWidth,
                'height': o.slideHeight
            });

            $slides.each(function(i, val) {
                var $s = $(this);
                var zIndex = (i === 0) ? 2 : 0;

                if (i === 1) {
                    zIndex = 1;
                }

                $s.css({
                    'position': 'absolute',
                    'z-index': zIndex,
                    'width': o.slideWidth,
                    'height': o.slideHeight,
                    'left': 0,
                    'top': 0
                });

                if (i === 0) {
                    fade($s);
                }
            });
        }

        return self.each(function() {
            $slideshow = $(this),
            $slides = $slideshow.children(),
            count = $slides.length;

            if (count > 1) {
                prepareMe();
            }
        });
    }

    $.fn.slideshow.defaults = {
        slideWidth: 100,
        slideHeight: 100,
        effect: 'fade'
    };

})(jQuery);
