/*
 * jQuery Gigi EI Slide Menu
 * version: 0.2 (10/01/2009)
 * @requires jQuery v1.2.6 or later
 *
 * No use and no modification whitout express authorisation
 *
 * Revision: $Id$
 */
(
function($)
{
 $.fn.GigiEIScrollProperties = function( options )
 {
  if( $(this).length > 0 )
  {
   options = $.extend({
                       nbElementsToScroll: 1,
                       animationTime: 1500,
                       rotationTime: 5000,
                       callback: null
                      }, options || {} );
   
   var table = $(this);
   
   window.setInterval( function(){ scroll( options.callback ); },
                       options.rotationTime );
   
   var inAnimation = false;
   function scroll( call )
   {
    var scrollLeft = 0;
    var nbCloned = 0;
    
    if( inAnimation === false )
    {
     inAnimation = true;
     
     iRowSpan = 0;
     $.each( $(table).find( "tr" ),
             function( i, tr )
             {
              if( i >= iRowSpan )
              {
               var tds = $(tr).children("td:lt("+options.nbElementsToScroll+")");
               iRowSpan  = i+($(tds[0]).attr("rowspan")?$(tds[0]).attr("rowspan"):1);
               $(tds).clone().appendTo(tr);
               nbCloned = tds.length;
               
               if( i == 0 )
               {
                $.each( $(tds),
                        function( i, td )
                        { 
                         scrollLeft += $(td).width();
                        } );
               }
              }
             } );
     
     $(table).parent().animate( { scrollLeft: scrollLeft }, 
                                options.animationTime,
                                function()
                                {
                                 iRowSpan = 0;
                                 $.each( $(table).find( "tr" ),
                                         function( i, tr )
                                         {
                                          if( i >= iRowSpan )
                                          {
                                           var td = $(tr).children("td:lt("+nbCloned+")");
                                           iRowSpan  = i+($(td[0]).attr("rowspan")?$(td[0]).attr("rowspan"):1);
                                           $(td).remove();
                                          }
                                         } );
                                 $(table).parent().attr( 'scrollLeft', 0 );
                                 
                                 inAnimation = false;
                                 scrollLeft = 0;
                                 if( $.isFunction( call ) )
                                 {
                                  call();
                                 }
                                } );
    }
   }
  }
 };
}
)(jQuery);