var ProductRotator = function(){
            var self = this;
            self.v = {ani:{duration:600}};
            self.el = {};
            self.products = [];
            //
            // Product
            self.Product = function(name, url, img, thumb, img_alt, thumb_alt){
                var product = this;
                //
                // Init
                product.init = function(name, url, img, thumb, img_alt, thumb_alt){
                    product.name = name;
                    product.url = url;
                    product.img = img;
                    product.thumb = thumb;
                    product.img_alt = img_alt;
                    product.thumb_alt = thumb_alt;
                    return product;
                };
                return product.init(name, url, img, thumb, img_alt, thumb_alt);
            };
            self.addProduct = function(name, url, img, thumb, img_alt, thumb_alt) {
                var product = new self.Product(name, url, img, thumb, img_alt, thumb_alt);
                self.products.push(product);
                return self;
            };
            self.getNext = function(i) {
                if (++i >= self.products.length) {
                    return 0;
                } else {
                    return i
                };
            };
            self.getPrev = function(i) {
                if (--i < 0) {
                    return self.products.length - 1;
                } else {
                    return i
                };
            };
            self.setHero = function(i) {
                var product = self.products[i];
                var link = $('<a/>')
                    .attr('href', product.url)
                    .appendTo(self.el.heroContainer);
                var productEl = $('<img/>')
                    .attr('src', product.img)
                    .attr('alt', product.img_alt)
                    .appendTo(link);
                return productEl;
            };
            self.setLeft = function(i) {
                var product = self.products[i];
                var productEl = $('<img/>')
                    .attr('src', product.thumb)
                    .appendTo(self.el.leftContainer)
                    .click(function(){ self.goTo(i, -1) });
                return productEl;
            };
            self.setRight = function(i) {
                var product = self.products[i];
                var productEl = $('<img/>')
                    .attr('src', product.thumb)
                    .appendTo(self.el.rightContainer)
                    .click(function(){ self.goTo(i, 1) });
                return productEl;
            };
            self.goTo = function(i, dir) {
				// hero
                self.el.heroContainer.find('img')
                    .animate({
                        'opacity': 0
                    }, {
                        complete: function(){
                            $(this).remove();
                            self.setHero(i).hide().fadeIn('slow');
                        }
                    });
                // left
                self.el.leftContainer.find('img')
                    .animate({
                        'left': -150*dir,
                        'opacity': 0
                    }, {
                        duration: self.v.ani.duration,
                        complete: function(){ $(this).remove(); }
                    });
                self.setLeft(self.getPrev(i))
                    .attr('src', 'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb2.png')
                    .css({
                        'left': 150*dir,
                        'opacity': 0
                    })
                    .animate({
                        'left': 0,
                        'opacity': 1
                    }, {
                        duration: self.v.ani.duration
                    });
                // right
                self.el.rightContainer.find('img')
                    .animate({
                        'right': 150*dir,
                        'opacity': 0
                    }, {
                        duration: self.v.ani.duration,
                        complete: function(){ $(this).remove(); }
                    });
                self.setRight(self.getNext(i))
                    .attr('src', 'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb1.png')
                    .css({
                        'right': -150*dir,
                        'opacity': 0
                    })
                    .animate({
                        'right': 27,
                        'opacity': 1
                    }, {
                        duration: self.v.ani.duration
                    });
            };
            //
            // Start
            self.start = function(){
                self.setHero(0).hide().fadeIn('slow');
                self.setLeft(self.getPrev(0)).hide().fadeIn('slow');
                self.setRight(self.getNext(0)).hide().fadeIn('slow');
                return self;
            };
            //
            // Init
            self.init = function(){
                self.el.leftContainer = $('#leftContainer');
                self.el.rightContainer = $('#rightContainer');
                self.el.leftForeground = $('#leftForeground');
                self.el.rightForeground = $('#rightForeground');
                self.el.heroContainer = $('#heroContainer');
                return self;
            };
            return self.init();
        };
        $(document).ready(function(){
            pr = new ProductRotator();
            
                pr.addProduct(
                    'title',
                    '#',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/hdr-img.png',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb1.png',
                    'title. ',
                    'sometitle'
                );
            
                pr.addProduct(
                    'title',
                    '#',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/hdr-img2.jpg',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb1.png',
                    '',
                    ''
                );
            
                pr.addProduct(
                    'title',
                    '#',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/hdr-img3.jpg',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb1.png',
                    '',
                    ''
                );
            
                pr.addProduct(
                    'title',
                    '#',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/hdr-img4.jpg',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb1.png',
                    '',
                    ''
                );
            
                pr.addProduct(
                    'title',
                    '#',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/hdr-img5.jpg',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb2.png',
                    '',
                    ''
                );
				pr.addProduct(
                    'title',
                    '#',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/hdr-img6.jpg',
                    'http://www.heritagepaintingvancouver.ca/wp-content/themes/heritage/images/thumb2.png',
                    '',
                    ''
                );
            
            pr.start();
        });
