/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

var Montage = require("montage").Montage,
    Component = require("ui/component").Component;

exports.FlowController = Montage.create(Component, {

    templateDidLoad: {
        value: function() {
//            this.spacing = this.offsetController.scale;
//            this.animation = this.path2;
//            this.hasMomentum = this.scrollController.hasMomentum;
        }
    },

    scrollController: {
        enumerable: true,
        serializable: true,
        value: null
    },

    offsetController: {
        enumerable: true,
        serializable: true,
        value: null
    },

    flowComponent: {
        enumerable: true,
        serializable: true,
        value: null
    },


    
    // ------------------------------------------------------------------------
    // Forwarding these properties to their equivalents in Scroll
    _speed: {
        enumerable: true,
        serializable: true,
        value: 1
    },

    speed: {
        get: function() {
            return this._speed;
        },
        set: function(value) {
            if(this._speed !== value)
            {
                if( this.scrollController && (this.scrollController.pointerSpeedMultiplier !== value) )
                {
                    this._speed = value;
                    this.scrollController.pointerSpeedMultiplier = value;
                    this.needsDraw = true;
                }
            }
        }
    },

    hasMomentum: {
        get: function() {
            if(this.scrollController)
            {
                return this.scrollController.hasMomentum;
            }
        },
        set: function(value) {
            if( this.scrollController && (this.scrollController.hasMomentum !== value) )
            {
                this.scrollController.hasMomentum = value;
                this.needsDraw = true;
            }
        }
    },

    hasBouncing: {
        get: function() {
            if(this.scrollController)
            {
                return this.scrollController.hasBouncing;
            }
        },
        set: function(value) {
            if( this.scrollController && (this.scrollController.hasBouncing !== value) )
            {
                this.scrollController.hasBouncing = value;
                this.needsDraw = true;
            }
        }
    },

    momentumDuration: {
        get: function() {
            if(this.scrollController)
            {
                return this.scrollController.momentumDuration;
            }
        },
        set: function(value) {
            if( this.scrollController && (this.scrollController.momentumDuration !== value) )
            {
                this.scrollController.momentumDuration = value;
                this.needsDraw = true;
            }
        }
    },

    bouncingDuration: {
        get: function() {
            if(this.scrollController)
            {
                return this.scrollController.bouncingDuration;
            }
        },
        set: function(value) {
            if( this.scrollController && (this.scrollController.bouncingDuration !== value) )
            {
                this.scrollController.bouncingDuration = value;
                this.needsDraw = true;
            }
        }
    },
    // ------------------------------------------------------------------------



    // ------------------------------------------------------------------------
    // Forwarding these properties to their equivalents in FlowOffset
    _spacing: {
        enumerable: true,
        serializable: true,
        value: 350
    },

    spacing: {
        get: function() {
            return this._spacing;
        },
        set: function(scale) {
//            if( this.offsetController && (this.offsetController.scale !== scale) )
//            {
//                this.offsetController.scale = scale;
//                this.needsDraw = true;
//            }
            if(this._spacing !== scale)
            {
                if( this.offsetController && (this.offsetController.scale !== scale) )
                {
                    this._spacing = scale;
                    this.offsetController.scale = scale;
                    this.needsDraw = true;
                }
            }
        }
    },
    // ------------------------------------------------------------------------


    
    // ------------------------------------------------------------------------
    // Some paths definitions and necessary values
    interpValue: {
        enumerable: true,
        serializable: true,
        value: 1
    },

    slideShow: {
        value: {
            value: function (slide) {
                var path={
                        translateX: 10+slide.time
                    };
                return path;
            }
        }
    },
    // ------------------------------------------------------------------------


    
    // ------------------------------------------------------------------------
    // Forwarding these properties to their equivalents in Flow

    // TODO - hard-coding values for demo
    _src: {
        enumerable: true,
        serializable: true,
        value: ""
    },

    src: {
        get: function() {
            return this._src;
        },
        set: function(value) {
            this.images = this.imagesForDemo;
            this._src = "images";
            this.needsDraw = true;
        }
    },

    images: {
        enumerable: true,
        serializable: true,
        value: []
    },

    imagesForDemo: {
        enumerable: true,
        serializable: true,
        value: [
            {"src": "images/0.jpg", "text": "We win together"},
            {"src": "images/1.jpg", "text": "We do the right thing"},
            {"src": "images/2.jpg", "text": "We are passionate about what we do"},
            {"src": "images/3.jpg", "text": "We are obsessed with product superiority"},
            {"src": "images/4.jpg", "text": "We make things simple"},
            {"src": "images/5.jpg", "text": "We are customer centric"},
            {"src": "images/6.jpg", "text": "Lorem Ipsum 0"},
            {"src": "images/7.jpg", "text": "Lorem Ipsum 1"},
            {"src": "images/8.jpg", "text": "Lorem Ipsum 2"},
            {"src": "images/9.jpg", "text": "Lorem Ipsum 3"},
            {"src": "images/10.jpg", "text": "Lorem Ipsum 4"},
            {"src": "images/11.jpg", "text": "Lorem Ipsum 5"},
            {"src": "images/12.jpg", "text": "Lorem Ipsum 6"},
            {"src": "images/13.jpg", "text": "Lorem Ipsum 7"},
            {"src": "images/14.jpg", "text": "Lorem Ipsum 8"}
        ]
    },
    
    _animation: {
        enumerable: true,
        serializable: true,
        value: this.path2
    },

    animation: {
        get: function() {
            return this._animation;
        },
        set: function(value) {
            if(this._animation !== value)
            {
                if( this.flowComponent && (this.flowComponent.path !== value) )
                {
                    this._animation = value;
                    switch(value)
                    {
                        case "slideshow":
                            this.flowComponent.path = this.slideShow;
                            this.offsetController.scale = 350;
                            this.scrollController.pointerSpeedMultiplier = 1;
                            break;
                        case "carousel":
                            this.flowComponent.path = this.path2.path;
                            this.offsetController.scale = 320;
                            this.scrollController.pointerSpeedMultiplier = 1;
                            break;
                        case "cover-flow":
                            this.flowComponent.path = this.path3.path;
                            this.offsetController.scale = 1000;
                            this.scrollController.pointerSpeedMultiplier = 3;
                            break;
                        case "wave":
                            this.flowComponent.path = this.path4.path;
                            this.offsetController.scale = 320;
                            this.scrollController.pointerSpeedMultiplier = 1;
                            break;
                        case "explosion":
                            this.flowComponent.path = this.path1.path;
                            this.offsetController.scale = 320;
                            this.scrollController.pointerSpeedMultiplier = 1;
                            break;
                        default:
                    }
                    this.flowComponent.needsDraw = true;
                }
            }
        }
    }
    // ------------------------------------------------------------------------

});