/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


;(function(jQuery) {

   jQuery.fn.tinyslideshow = function(settings) {
     var config = {path:''};
     if (settings) jQuery.extend(config, settings);
     var imgs; var currentIndex=-1;

         function _next() {
            if (currentIndex == imgs.length-1)
                currentIndex = 0;
            else
                currentIndex++;
            _goto(currentIndex);
         }
         function _prev() {
            if (currentIndex == 0)
                currentIndex = imgs.length-1;
            else
                currentIndex--;
            _goto(currentIndex);
         }
         function _goto(i) {
             try {
               currentIndex = i;
                imgs.hide();
                jQuery('.ts-nav-link').css('color','#696969').eq(i).css('color','#4092ca');
                imgs.eq(currentIndex).fadeIn();
             } catch (e) {}
         }

     this.each(function(e) {
         imgs = jQuery(this).children();
         imgs.click( function(e) { e.preventDefault(); _next() } );

         var html = '<div class="ts-navigation" style="border: 1px solid #EAEAEA; padding: 5px; margin-top: 10px;text-align:center;">';
         html += '<a href="#" class="ts-nav-prev"><img style="vertical-align:middle" src="'+config.path+'ts-prev.png"/></a>';
         for (var i=0; i<imgs.length; i++)
             html +=  '<a href="#" class="ts-nav-link" rel="'+i+'" style="color: #696969;font-weight:bold;text-decoration:none"> '+(i+1)+' </a> &nbsp; ';
         html += '<a href="#" class="ts-nav-next"><img style="vertical-align:middle" src="'+config.path+'ts-next.png"/></a>';
         html += '</div>';
         jQuery(html).appendTo(jQuery(this));
         jQuery(this).find('.ts-nav-link').click( function(e) { e.preventDefault(); _goto(jQuery(this).attr('rel')); });
         jQuery(this).find('.ts-nav-next').click( function(e) { e.preventDefault(); _next(); } );
         jQuery(this).find('.ts-nav-prev').click( function(e) { e.preventDefault(); _prev(); } );
         
         _goto(0);

     });
     return this;
   };

 })(jQuery);

