(function($) {
  Drupal.behaviors.jquery_cycle = {
    attach: function (context, settings) {
    //console.log(settings);
    //set up the cycle stuff
      $(document).ready(function(){
        //This event fires when the dom is ready but not everything is loaded properly
        //Hide the later elements of the slideshow so there isn't a visual jump
        var className = "."+settings.jquery_cycle.className;

        var counter = 0;

        //Hide all subsequent images so they don't show before cycle has been loaded
        $(className).find('img').each(function(key, value){
            if(counter > 0)
            {
              $(this).hide();
            }
            counter++;
        });
      });

      $(window).load(function(){
        //This event is fired after all items in the DOM have loaded
        
        //Apply the cycle to the desired class
        var className = "."+settings.jquery_cycle.className;

        $(className).cycle({
          fx: settings.jquery_cycle.fx, 
          timeout: settings.jquery_cycle.timeout
          });

        //Show all images now that cycle has been loaded so that they actually appear in the slideshow
        $(className).find('img').each(function(key, value){
            $(this).show();
          });
      });
    }
  };
 })(jQuery);
;

