(function($) {                                          // Compliant with jquery.noConflict()
$.fn.jCarouselLite = function(o) {
    o = $.extend({
        btnPrev: null,
        btnNext: null,
        btnGo: null,
        mouseWheel: false,
        auto: null,
        hoverPause: false,

        speed: 200,
        easing: null,

        vertical: false,
        circular: true,
        visible: 3,
        start: 0,
        scroll: 1,

        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

       function Max(Liste)
	    {
		  var Lunghezza = Liste.length;
		  var Max = 0; 
	 	  for(Inizio = 0; Inizio < Lunghezza; Inizio++)
		   { 
		    if( Max < Liste[Inizio].offsetHeight) Max = Liste[Inizio].offsetHeight;
		   }
 		  return Max;		
		};
       function Somma(Liste)
	    {
		  var Lunghezza = Liste.length;
		  var Max = 0; 
	 	  for(Inizio = 0; Inizio < Lunghezza; Inizio++)
		   { 
		    Max = Max + Liste[Inizio].offsetHeight;
		   }
 		  return Max;		
		};

	   function startAuto() 
		 {
          stopAuto();
          autoInterval = setInterval(function(){go(curr+o.scroll);}, o.auto+o.speed);
		 };

        function stopAuto() 
		 {
		  clearInterval(autoInterval);
	     };

        function go(to) 
		 {
            if(!running) 
			 {
              if(o.circular) 
			   {            // If circular we are in first or last, then goto the other end
                if(to<0) 
				 {           // If before range, then go around
                  ul.css(animCss, -( (curr + tl) * liSize)+"px");
                  curr = to + tl;
                 } 
			    else 
				 if(to>itemLength-v) 
				  { // If beyond range, then come around
                    ul.css(animCss, -( (curr - tl) * liSize) + "px" );
                    curr = to - tl;
                  } 
				 else curr = to;
                } 
			   else 
			    {                    // If non-circular and to points to first or last, we just return.
                 if(to<0 || to>itemLength-v) return;
                 else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.
              running = true;
              ul.animate(animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,function() {running = false;}); 
             }
            return false;
         }; // chiude funzione go 

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

        if(o.circular) {
            ul.prepend(tLi.slice(tl-v+1).clone())
              .append(tLi.slice(0,o.scroll).clone());
            o.start += v-1;
        }

        var li = $("li", ul), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

        var prova = Max(li);
		var prova1 = Somma(li);


        var liSize = prova; // o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = prova1; // liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v - 16;                           // size of entire div(total length for just the visible items)

		
		li.css({width: li.width(), height: liSize}); // li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

        var autoInterval;
		div.click(function(){
		 var Id = li[curr].value;
		 window.location.href = "/index.php?option=com_jumi&fileid=73&n="+Id;});
        if(o.auto) 
		 {
           if(o.hoverPause) 
		    {
             div.hover(function(){this.style.cursor='pointer';stopAuto();}, function(){this.style.cursor='default';startAuto();});
            }
           startAuto();
         };
    }); // chiude for each
};  // chiude jCarouselLite

function css(el, prop) 
{
    return parseInt($.css(el[0], prop)) || 0;
};
function width(el) 
{
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) 
{
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};

})(jQuery);  // chiude $
