/**
 * UltimatePlayer Fade plugin (copyright 2011)
 * @author zbigniew.labacz@gmail.com
 * @package UltimatePlayer
 */
;(function($) {
    
    LIB.namespace('UltimatePlayer');
    
    UltimatePlayer.Slide = $.inherit(UltimatePlayer.Base, {
        
        /**
         * Direction config
         * @var {}
         */
        cfg: undefined,
        
        /**
         * Konstruktor
         * @param [ DOMElement ] dom
         * @param {} config
         */
        __constructor: function(dom, config)
        {
            this.animationConfig = $.extend({
                className: 'Slide',
                direction: 'horizontal',
                duration: 500
            }, config.animation || {});
            this.__base(dom, config);
        },
        
        /**
         * Pobiera konfiguracje run-time playera dla różnych rodzajów animacji
         * @return {}
         */
        getDirectionConfig: function(name)
        {
            if (typeof this.cfg == 'undefined')
            {
                this.cfg = {
                    horizontal: {
                        slider_css: {
                            width: this.getElements().size() * this.config.width,
                            heigth: this.config.height
                        },
                        element_css: {
                            'float': 'left'
                        },
                        parameter: 'left',
                        offset: this.config.width
                    },
                    vertical: {
                        slider_css: {
                            width: this.config.width,
                            heigth: this.getElements().size() * this.config.height
                        },
                        element_css: {
                            'float': 'none'
                        },
                        parameter: 'top',
                        offset: this.config.height
                    }
                };
            }
            
            return this.cfg[this.animationConfig.direction][name];
            
        },
        
        /**
         * Dostosowanie ustawień
         */
        customize: function()
        {
            var sliderCss = this.getDirectionConfig('slider_css');
            sliderCss['position'] = 'absolute';
            sliderCss['left'] = 0;
            sliderCss['top'] = 0;
            this.getSlider().css(sliderCss);
            this.getElements().css(this.getDirectionConfig('element_css'));
        },
        
        /**
         * Animacja
         */
        animate: function()
        {
            var _this = this;
            var properties = {};
            var targetElement = this.getElements().eq(this.getOffset());
            properties[this.getDirectionConfig('parameter')] = this.getOffset() * this.getDirectionConfig('offset') * -1;
            this.getSlider().animate(properties, this.animationConfig.duration, 'swing', function() {
                _this.setCurrentElement(targetElement);
            })
        }
        
    });
    
})(jQuery);
