/*
Copyright 2010  Brian Sage  (email : brian at sagehome dot com)

All rights are reserved by the author. 

This program is NOT for redistribution, customization, nor modification.
If you have obtained this program for free, please contact the author. A
reward may be issued for information regarding piracy.

======================

WordPress-Mu is distributed under the GNU General Public License.

You should have received a copy of the GNU General Public License
along with your distribution of WordPress; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/




if (typeof window.console == 'undefined') window.console = {'log':function(){}};

if (typeof multiplus_public == 'undefined') var multiplus_public = {};

jQuery(function(){
  //console.log('multiplus_public loaded');


  if(jQuery('body').hasClass('multiplus_slideshow')){
    multiplus_public.slideshow.init();
  }
  
  
});




multiplus_public = {
  slideshow: {

  
    init: function(){
      //if(!jQuery('body').hasClass('multiplus_admin')){
        //console.log('slideshow.init()');
        
        $slideshow_slides = jQuery('.multiplus_public_content_surround a.multiplus_gallery_thumb, .multiplus_content_current a.multiplus_gallery_thumb');
        
        $slideshow_slides.each(function(){
          var slide = document.createElement('img');
          slide.src = jQuery(this).attr('href');
          jQuery(slide).animate({opacity:0},0,function(){
            jQuery('#multiplus_slideshow_slides').append(slide);
          });
        });
        
        multiplus_public.slideshow.cycle();
        multiplus_public.slideshow.cycle_timer = window.setInterval("multiplus_public.slideshow.cycle()", 4000);
      //}
    },


    cycle_timer: null,
    
    
    cycle: function() {
      //console.log('multiplus_public.slideshow.cycle()');

      if(jQuery('#multiplus_slideshow_slides img').length > 1) {
        
        var jQactive = jQuery('#multiplus_slideshow_slides img.active');
        if (jQactive.length == 0) {
          jQactive = jQuery('#multiplus_slideshow_slides img:last');
          jQactive.addClass('active');
        }
        
        var jQnext = jQactive.next().length ? jQactive.next() : jQuery('#multiplus_slideshow_slides img:first');
  
        jQnext.animate({
          opacity: 0
        });
        
        jQactive.removeClass('active').addClass('last-active');
        
        jQnext.addClass('active').animate({
          opacity: 1
        }, 1000, function(){
          jQuery('#multiplus_slideshow_slides img.last-active').removeClass('last-active').animate({
            opacity: 0
          }, 0);
        });
      } else {
        jQuery('#multiplus_slideshow_slides img').stop().animate({
          opacity: 1
        });
      }
    }
    
    
    // multiplus_public.slideshow
  }




}