﻿$.rsfSlideshow = {
    defaults: {
        //	Duration of the interval between each slide in seconds
        interval: 5,
        //	Duration of the transition effect in milliseconds
        transition: 1000,
        //	The transition effect.
        effect: 'fade',
        //	Easing for slide effects (use the easing jQuery plugin for more options)
        easing: 'swing',
        //	If true, the slideshow will loop
        loop: true,
        //	Start slideshow automatically on initialisation
        autostart: true,
        //	Slides to add to the slideshow
        slides: [],
        //	Class of the div containing the slide image and caption
        slide_container_class: 'slide-container',
        //	Class to add to slide caption <span>
        slide_caption_class: 'slide-caption',
        //	jQuery selector for the element containing slide data when using markup to pass data.
        //	If this is an ID (starts with '#') the element can be placed anywhere on the page, 
        //	Any other selector is assumed to be a child of the slideshow element.
        data_container: 'ol.slides',
        //	jQuery selector for each slide data element
        slide_data_container: 'li',
        //	Objects containing selection routes for slide attributes
        //	One or both of 'selector' and/or 'attr' must be present
        slide_data_selectors: {
            url: { selector: 'a', attr: 'href' },
            caption: { selector: 'a', attr: 'title' },
            link_to: { selector: 'a', attr: 'data-link-to' },
            effect: { selector: 'a', attr: 'data-effect' }
        },


        //	Default event handlers, assigned to every instance of the slideshow
        eventHandlers: {
            rsStartShow: function (rssObj, e) {
                var controlSettings = $(rssObj).data('rsf_slideshow').settings.controls.playPause;
                var $playPause = controlSettings.get($(rssObj));
                $playPause.html('Pause').addClass(controlSettings.playing_class);
            },
            rsStopShow: function (rssObj, e) {
                var controlSettings = $(rssObj).data('rsf_slideshow').settings.controls.playPause;
                var $playPause = controlSettings.get($(rssObj));
                $playPause.html('Play').addClass(controlSettings.paused_class);
            }
        },


        /**
        *	These options define methods for generating, placing and finding
        *	slideshow control elements.
        */

        controls: {
            playPause: {
                generate: function ($slideshow) {
                    return $('<a href="#" class="rs-play-pause ' +
								 $slideshow.data('rsf_slideshow').settings.controls.playPause.paused_class +
								 '" data-control-for="' +
								 $slideshow.attr('id') + '">Play</a>');
                },
                place: function ($slideshow, $control) {
                    var $container =
							$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);
                    $container.append($control);
                },
                get: function ($slideshow) {
                    return $('.rs-play-pause[data-control-for="' + $slideshow.attr('id') + '"]');
                },
                playing_class: 'rs-playing',
                paused_class: 'rs-paused',
                auto: false
            },
            previousSlide: {
                generate: function ($slideshow) {
                    return $('<a href="#" class="rs-prev" data-control-for="' +
								 $slideshow.attr('id') + '">&lt;</a>');
                },
                place: function ($slideshow, $control) {
                    var $container =
							$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);
                    $container.append($control);
                },
                get: function ($slideshow) {
                    return $('.rs-prev[data-control-for="' + $slideshow.attr('id') + '"]');
                },
                autostop: true,
                auto: false
            },
            nextSlide: {
                generate: function ($slideshow) {
                    return $('<a href="#" class="rs-next" data-control-for="' +
								 $slideshow.attr('id') + '">&gt;</a>');
                },
                place: function ($slideshow, $control) {
                    var $container =
							$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);
                    $container.append($control);
                },
                get: function ($slideshow) {
                    return $('.rs-next[data-control-for="' + $slideshow.attr('id') + '"]');
                },
                autostop: true,
                auto: false
            },
            index: {
                generate: function ($slideshow) {
                    var slide_count = $slideshow.rsfSlideshow('totalSlides'),
							$indexControl = $('<ul class="rs-index-list clearfix"></ul>');
                    $indexControl.attr('data-control-for', $slideshow.attr('id'));
                    for (var i = 0; i < slide_count; i++) {
                        var $link = $('<a href="#"></a>');
                        $link.addClass('rs-index');
                        $link.attr('data-control-for', $slideshow.attr('id'));
                        $link.attr('data-slide-key', i);
                        $link.append(i + 1);
                        if (i === $slideshow.rsfSlideshow('currentSlideKey')) {
                            $link.addClass('rs-active');
                        }
                        var $li = $('<li></li>');
                        $li.append($link);
                        $indexControl.append($li);
                    }
                    return $indexControl;
                },
                place: function ($slideshow, $control) {
                    var $container =
							$slideshow.data('rsf_slideshow').settings.controls.container.get($slideshow);
                    $container.append($control);
                },
                get: function ($slideshow) {
                    return $('.rs-index-list[data-control-for="' + $slideshow.attr('id') + '"]');
                },
                getEach: function ($slideshow) {
                    return $('.rs-index[data-control-for="' + $slideshow.attr('id') + '"]');
                },
                getSingleByKey: function ($slideshow, slide_key) {
                    return $('.rs-index[data-control-for="' +
								$slideshow.attr('id') + '"][data-slide-key="' + slide_key + '"]');
                },
                getSlideKey: function ($controlItem) {
                    return $controlItem.attr('data-slide-key');
                },
                active_class: 'rs-active',
                autostop: true,
                auto: false
            },
            container: {
                generate: function ($slideshow) {
                    return $('<div class="rs-controls clearfix" id="rs-controls-' + $slideshow.attr('id') + '"></div>');
                },
                place: function ($slideshow, $control) {
                    $slideshow.after($control);
                },
                get: function ($slideshow) {
                    return $('#rs-controls-' + $slideshow.attr('id'));
                }
            }
        }
    },


    //	Transition effects
    transitions: {
        none: function ($slideshow, $slide) {
            $slide.css('display', 'block');
        },
        fade: function ($slideshow, $slide) {
            $slide.fadeIn(
					$slideshow.data('rsf_slideshow').settings.transition,
					function () {
					    RssPrivateMethods._endTransition($slideshow, $slide);
					});
        },
        slideLeft: function ($slideshow, $slide) {
            var left_offset = $slide.outerWidth();
            RssPrivateMethods._doSlide($slideshow, $slide, left_offset, 0);
        },
        slideRight: function ($slideshow, $slide) {
            var left_offset = 0 - $slide.outerWidth();
            RssPrivateMethods._doSlide($slideshow, $slide, left_offset, 0);
        },
        slideUp: function ($slideshow, $slide) {
            var top_offset = $slide.outerHeight();
            RssPrivateMethods._doSlide($slideshow, $slide, 0, top_offset);
        },
        slideDown: function ($slideshow, $slide) {
            var top_offset = 0 - $slide.outerHeight();
            RssPrivateMethods._doSlide($slideshow, $slide, 0, top_offset);
        }
    }

};
