/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Sitewide and Public Functions (Responsive)
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

vm_slideshow = (function ($) {
    'use strict';

    var fn = {},
        jsFolder = '/themes/javascript/compressed/jquery/plugins/';

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    fn.loadCycle = function (selector, options) {
        var scriptURL = jsFolder + 'jquery.cycle.all.js',
            selector  = $(selector),
            options   = (!options || options == '') ? {
                    //defaults listed here: http://jquery.malsup.com/cycle2/api/#options
                                                log : false,
                                             slides : '> div.slide',
                                           // paused : true,
                                       pauseOnHover : true,
                                              speed : 600,
                                              pager : '> div.pager',
                                      pagerTemplate : '<span>&emsp;</span>',
                                   pagerActiveClass : 'current'
                } : options;
        if (selector.is(':visible')) {
            $.getScript(scriptURL)
                .done(function () {
                    var slides = $('.slide', selector);
                    // can override or add options here with the syntax options.OPTION_NAME = 'new value'
                    selector.cycle(options);
                    slides.each(function () {
                        var img = $(this).find('img');
                        img.attr({
                            'longdesc' : $(this).data('longdesc'),
                            'aria-describedby' : $(this).data('aria-describedby')
                        })
                    })
                })
                .fail(function () {
                    if (window.console) {
                        console.log(scriptURL + ' didn\'t load');
                    }
                });
        };
    };

    return {
        loadCycle : fn.loadCycle,
    }
})(jQuery);

/*-----------------------------------*
  When DOM is loaded, call the functions in "init" section
  -----------------------------------*/
$(document).ready(function(){
    'use strict';
    vm_slideshow.loadCycle();
});
