﻿function PortfolioMain() {
    var _this = this;



    var itemWidth = 0;

    this.init = function () {
        var count = $(".portfolio-main .portfolio-item").length;
        itemWidth = $(".portfolio-main .portfolio-item").width() + 40;
        _this.container().css({ "width": itemWidth * count });

        _this.leftButton().live("click", function () {
            _this.moveRight();
        });

        _this.rightButton().live("click", function () {
            _this.moveLeft();
        });
    }

    this.container = function () {
        return $(".portfolio-main .container");
    }
    this.leftButton = function () {
        return $(".portfolio-main .portfolio-wrapper .left-arrow");
    }

    this.rightButton = function () {
        return $(".portfolio-main .portfolio-wrapper .right-arrow");
    }


    this.moveLeft = function () {
        _this.container().stop(true, true).animate({
            left: -1 * itemWidth
        }, 1000, function () {
            // Animation complete.
            var obj = $('.portfolio-item', _this.container()).first();
            obj.detach();
            _this.container().css({ "left": "0" });
            obj.appendTo(_this.container());
        });

    }

    this.moveRight = function () {
        var obj = $('.portfolio-item', _this.container()).last();
        obj.detach();
        _this.container().css({ "left": -1 * itemWidth });
        obj.prependTo(_this.container());
        _this.container().stop().animate({
            left: 0
        }, 1000);
    }
}

var portfolioMain = null;
$().ready(function () {
    portfolioMain = new PortfolioMain();
    portfolioMain.init();
});
