//simple picture slideShow
//jQuery plugin
//2010.11.06

/*
<div switch=off|on id=whatever style="padding:15px">

<span style="font-size:large">whatever</span><br />      

<img id=slide style="border-radius:15px" /> <br clear = all />

<span id=comment></span>       

<ul id=slideList>
      <li title='comment1'>pic1</li>
      .
      .
      .
</ul>
</div>

defaults:
speed 4000   //milliseconds


jQuery('div#whatever').slideShow({speed:2000});

*/
context_array = new Array();
current_frame_array = new Array();



function changeFrame(index)
{

               var current_frame = current_frame_array[index];
               var current_context=context_array[index];
              
               
                  jQuery('img#slide',current_context).attr('src',jQuery('ul#slideList li' ,current_context).eq(current_frame)
                     .text());
                      
                  jQuery('span#comment',current_context).text(jQuery('ul#slideList li',current_context)
                                         .eq(current_frame).attr('title'));      
                 
                       
                
                
                var frames = jQuery('ul#slideList li',current_context).length ;
                current_frame_array[index] = (current_frame+1)%frames;
               
                
               
             
}


jQuery.fn.slideShow = function(options){

   var opts = jQuery.extend({},jQuery.fn.slideShow.defaults,options);
   
   return this.each(function(){
             
             var on_off =jQuery(this).attr('switch');
             var list_length = jQuery('ul#slideList li',this).length;
             if (on_off && on_off .toLowerCase()=='off' ||
                                                  list_length==0 ){
             
                jQuery(this).hide();
                return;
             
             
             }
             
             //hide the data
            jQuery('ul#slideList',this).hide();
            
          
                             
             
             //now start the show
             var context_index = context_array.length;    
             context_array[context_index] = this;
             current_frame_array[context_index] =0;
             changeFrame(context_index);
             window.setInterval("changeFrame("+context_index+")", opts.speed);




   });

};

jQuery.fn.slideShow.defaults = {

      speed: 4000
      
};
