 jQuery.easing['jswing'] = jQuery.easing['swing'];
 
 jQuery.extend( jQuery.easing,
 {
 	def: 'swing',
 	swing: function (x, t, b, c, d) {
 		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
 	},
 	easeInQuad: function (x, t, b, c, d) {
 		return c*(t/=d)*t + b;
 	},
 	easeOutQuad: function (x, t, b, c, d) {
 		return -c *(t/=d)*(t-2) + b;
 	},
 	easeInOutQuad: function (x, t, b, c, d) {
 		if ((t/=d/2) < 1) return c/2*t*t + b;
 		return -c/2 * ((--t)*(t-2) - 1) + b;
 	},
 	easeInCubic: function (x, t, b, c, d) {
 		return c*(t/=d)*t*t + b;
 	},
 	easeOutCubic: function (x, t, b, c, d) {
 		return c*((t=t/d-1)*t*t + 1) + b;
 	},
 	easeInOutCubic: function (x, t, b, c, d) {
 		if ((t/=d/2) < 1) return c/2*t*t*t + b;
 		return c/2*((t-=2)*t*t + 2) + b;
 	},
 	easeInQuart: function (x, t, b, c, d) {
 		return c*(t/=d)*t*t*t + b;
 	},
 	easeOutQuart: function (x, t, b, c, d) {
 		return -c * ((t=t/d-1)*t*t*t - 1) + b;
 	},
 	easeInOutQuart: function (x, t, b, c, d) {
 		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
 		return -c/2 * ((t-=2)*t*t*t - 2) + b;
 	},
 	easeInQuint: function (x, t, b, c, d) {
 		return c*(t/=d)*t*t*t*t + b;
 	},
 	easeOutQuint: function (x, t, b, c, d) {
 		return c*((t=t/d-1)*t*t*t*t + 1) + b;
 	},
 	easeInOutQuint: function (x, t, b, c, d) {
 		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
 		return c/2*((t-=2)*t*t*t*t + 2) + b;
 	},
 	easeInSine: function (x, t, b, c, d) {
 		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
 	},
 	easeOutSine: function (x, t, b, c, d) {
 		return c * Math.sin(t/d * (Math.PI/2)) + b;
 	},
 	easeInOutSine: function (x, t, b, c, d) {
 		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
 	},
 	easeInExpo: function (x, t, b, c, d) {
 		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
 	},
 	easeOutExpo: function (x, t, b, c, d) {
 		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
 	},
 	easeInOutExpo: function (x, t, b, c, d) {
 		if (t==0) return b;
 		if (t==d) return b+c;
 		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
 		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
 	},
 	easeInCirc: function (x, t, b, c, d) {
 		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
 	},
 	easeOutCirc: function (x, t, b, c, d) {
 		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
 	},
 	easeInOutCirc: function (x, t, b, c, d) {
 		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
 		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
 	},
 	easeInElastic: function (x, t, b, c, d) {
 		var s=1.70158;var p=0;var a=c;
 		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
 		if (a < Math.abs(c)) { a=c; var s=p/4; }
 		else var s = p/(2*Math.PI) * Math.asin (c/a);
 		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
 	},
 	easeOutElastic: function (x, t, b, c, d) {
 		var s=1.70158;var p=0;var a=c;
 		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
 		if (a < Math.abs(c)) { a=c; var s=p/4; }
 		else var s = p/(2*Math.PI) * Math.asin (c/a);
 		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
 	},
 	easeInOutElastic: function (x, t, b, c, d) {
 		var s=1.70158;var p=0;var a=c;
 		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
 		if (a < Math.abs(c)) { a=c; var s=p/4; }
 		else var s = p/(2*Math.PI) * Math.asin (c/a);
 		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
 		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
 	},
 	easeInBack: function (x, t, b, c, d, s) {
 		if (s == undefined) s = 1.70158;
 		return c*(t/=d)*t*((s+1)*t - s) + b;
 	},
 	easeOutBack: function (x, t, b, c, d, s) {
 		if (s == undefined) s = 1.70158;
 		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
 	},
 	easeInOutBack: function (x, t, b, c, d, s) {
 		if (s == undefined) s = 1.70158; 
 		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
 		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
 	},
 	easeInBounce: function (x, t, b, c, d) {
 		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
 	},
 	easeOutBounce: function (x, t, b, c, d) {
 		if ((t/=d) < (1/2.75)) {
 			return c*(7.5625*t*t) + b;
 		} else if (t < (2/2.75)) {
 			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
 		} else if (t < (2.5/2.75)) {
 			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
 		} else {
 			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
 		}
 	},
 	easeInOutBounce: function (x, t, b, c, d) {
 		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
 		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
 	}
 });
 

(function($)
{
    $.fn.imNotSlider = function(options)
    {
        // opzioni di default
        var defaults = {
            prevId:         'prevBtn',	// id del controllo indietro
            prevText:       'Previous',	// etichetta del controllo indietro
            nextId:         'nextBtn',	// id del controllo avanti
            nextText:       'Next',		// etichetta del controllo avanti
            controlsShow:   true,		// mostra o meno i controlli
            controlsBefore: '',			// id aggiuntivo per il controllo indietro
            controlsAfter:  '',			// id aggiuntivo per il controllo avanti
            controlsFade:   true,		// se il controllo indietro/avanti alla fine dello slide deve sparire
            insertAfter:    true,		// se inserire i controlli dopo lo slide o sopra/sotto
            firstId:        'firstBtn',	// id del controllo inizio
            firstText:      'First',	// etichetta del controllo inizio
            firstShow:      false,		// se il controllo inizio deve sparire
            lastId:         'lastBtn',	// id del controllo fine
            lastText:       'Last',		// etichetta del controllo fine
            lastShow:       false,		// se il controllo fine deve sparire
            vertical:       false,		// se lo slide deve essere verticale
            speed:          800,		// velocità dell'animazione
            ease:           'fade',	// tipo di animazione
            auto:           true,		// se lo slide deve andare avanti da solo
            pause:          2000,		// tempo di attesa (in ms) su ogni elemento
            continuous:     true,		// slide infinito
            prevNext:       false,		// se i controlli sono numerici ma devono essere mostrati anche gli altri
            numeric:        false,		// se nei controlli devo avere i numeri
            dotted:			true,		// se nei controlli devo avere le thumb
            thumb:			false,		// se nei controlli devo essere le miniature
            controlsId:		'imNotSliderControls',	// id dei controlli numerici
            imageNormal:	'/images/normal.png',			// percorso immagine per controllo puntinato - normale
            imageCurrent:	'/images/current.png'			// percorso immagine per controllo puntinato - current
        };

        var options = $.extend(defaults, options);

        this.each(function()
        {
            var obj = $(this);

            var ul = obj.children("ul");
            var li = ul.children("li");

            var s = li.length;
            var w = obj.width();
            var h = obj.height();

            var t = 0;
            var ts = s-1;
            var clickable = true;

            obj.css("overflow","hidden");

            li.each(function() {
               if(options.vertical) $(this).height(h);
                else $(this).width(w);
            });

            li.css('float', 'left');

            if(options.vertical) ul.height(s*w);
            else ul.width(s*w);

            if(options.continuous)
            {
                if(options.vertical)
                {
                    ul.prepend(li.filter(":last-child").clone().css("margin-top","-"+ h +"px"));
                    ul.append(li.filter(":nth-child(2)").clone());
                    ul.height((s+1)*h);
                } else {
                    ul.prepend(li.filter(":last-child").clone().css("margin-left","-"+ w +"px"));
                    ul.append(li.filter(":nth-child(2)").clone());
                    ul.width((s+1)*w);
                }
            };

            if(options.controlsShow)
            {
                var html = options.controlsBefore;
                if((options.numeric)||(options.dotted)||(options.thumb)){
                    html += '<ol id="'+ options.controlsId +'"></ol>';
                }
                if(options.firstShow) {
                    html += '<span id="'+ options.firstId +'"><a href="#">'+ options.firstText +'</a></span>';
                }
                if(options.prevNext){
                    html += '<span id="'+ options.prevId +'"><a href="#">'+ options.prevText +'</a></span>';
                    html += '<span id="'+ options.nextId +'"><a href="#">'+ options.nextText +'</a></span>';
                }
                if(options.lastShow) {
                    html += '<span id="'+ options.lastId +'"><a href="#">'+ options.lastText +'</a></span>';
                }
                html += options.controlsAfter;

                if (options.insertAfter) $(obj).after(html);
                else $(obj).before(html);
            };

            if(options.numeric)
            {
                for(var i=0;i<s;i++)
                {
                    $(document.createElement("li"))
                        .attr('id',options.controlsId + (i+1))
                        .html('<a rel="'+ i +'" href="#"><span>'+(i+1)+'</span></a>')
                        .appendTo($("#"+ options.controlsId))
                        .click(function(){
                            animate($("a",$(this)).attr('rel'),true);
                            return false;
                        });
                };
                
            }
            
            if(options.dotted)
            {
                for(var i=0;i<s;i++)
                {
                    $(document.createElement("li"))
                        .attr('id',options.controlsId + (i+1))
                        .html('<a rel="'+ i +'" href="#"><img src="'+options.imageNormal+'" alt="'+(i+1)+'"/></a>')
                        .appendTo($("#"+ options.controlsId))
                        .click(function(){
                            animate($("a",$(this)).attr('rel'),true);
                            return false;
                        });
                };
                
            }

			if(options.thumb)
			{
			    for(var i=0;i<s;i++)
			    {
			    	if(!options.continuous) {
			    		a = li.filter(":nth-child("+(i+1)+")");
			    	} else {
			    		a = li.filter(":nth-child("+(i+2)+")");
			    	}
			    	b = $("img", a).attr('src');
			        $(document.createElement("li"))
			            .attr('id',options.controlsId + (i+1))
			            .html('<a rel="'+ i +'" href="#"><img class="sliderThumb" src="'+b+'" alt="'+(i+1)+'"/></a>')
			            .appendTo($("#"+ options.controlsId))
			            .click(function(){
			                animate($("a",$(this)).attr('rel'),true);
			                return false;
			            });
			    };
			    
			}

            if(options.prevNext)
            {
                $("a","#"+options.nextId).click(function(){
                    animate("next",true); return false;
                });
                $("a","#"+options.prevId).click(function(){
                    animate("prev",true); return false;
                });
                $("a","#"+options.firstId).click(function(){
                    animate("first",true); return false;
                });
                $("a","#"+options.lastId).click(function(){
                    animate("last",true); return false;
                });
            };

            function setCurrent(i)
            {
                i = parseInt(i)+1;
                $("li", "#" + options.controlsId).removeClass("current");
                $("li#" + options.controlsId + i).addClass("current");
                if(options.dotted){
                	d = $("li", "#" + options.controlsId);
                	$("img", d).attr('src',options.imageNormal);
                	$("img", "li#" + options.controlsId + i).attr('src',options.imageCurrent);
                }
            };

            function adjust()
            {
                if(t>ts) t=0;
                if(t<0) t=ts;
                if(!options.vertical) {
                    ul.css("margin-left",(t*w*-1));
                } else {
                    ul.css("margin-top",(t*h*-1));
                }
                clickable = true;
                if((options.numeric)||(options.dotted)||(options.thumb)) setCurrent(t);
            };

            function animate(dir,clicked)
            {
                if (clickable)
                {
                    clickable = false;
                    var ot = t;
                    switch(dir)
                    {
                        case "next":
                            t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;
                            break;
                        case "prev":
                            t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
                            break;
                        case "first":
                            t = 0;
                            break;
                        case "last":
                            t = ts;
                            break;
                        default:
                            t = parseInt(dir);
                            break;
                    };

                    var diff = Math.abs(ot-t);
                    var speed = diff*options.speed;
                    if(!options.vertical) {
                        p = (t*w*-1);
                        if (options.ease!='fade') {
	                        ul.animate(
	                            { marginLeft: p },
	                            {
	                                queue:false,
	                                duration:speed,
	                                easing:options.ease,
	                                complete:adjust
	                            }
	                        );
                        } else {
                        	ul.animate(
                        		{ opacity: 0 },
                        		speed,
                        		'jswing',
                        	    function() {
                        	    	ul.css({marginLeft:p});
                        	    	ul.animate(
                        	    		{ opacity: 1 },
                        	    		speed,
                        	    		'jswing'
                        	    	);
                        	    	adjust();
                        	    }
                        	);
                        }
                    } else {
                        p = (t*h*-1);
                        ul.animate(
                            { marginTop: p },
                            {
                                queue:false,
                                duration:speed,
                                easing:options.ease,
                                complete:adjust
                            }
                        );
                    };

                    if(!options.continuous && options.controlsFade)
                    {
                        if(t==0){
                            $("a","#"+options.prevId).fadeOut('slow');
                            $("a","#"+options.firstId).fadeOut('slow');
                        } else if(t==ts){
                            $("a","#"+options.nextId).fadeOut('slow');
                            $("a","#"+options.lastId).fadeOut('slow');
                        } else {
                            $("a","#"+options.prevId).fadeIn('slow');
                            $("a","#"+options.firstId).fadeIn('slow');
                            $("a","#"+options.nextId).fadeIn('slow');
                            $("a","#"+options.lastId).fadeIn('slow');
                        };
                    };

                    if(clicked) clearTimeout(timeout);
                    if(options.auto && dir=="next" && !clicked){;
                        timeout = setTimeout(function(){
                            animate("next",false);
                        },diff*options.speed+options.pause);
                    };

                };
            };
            // init
            var timeout;
            if(options.auto){;
                timeout = setTimeout(function(){
                    animate("next",false);
                },options.pause);
            };

            if((options.numeric)||(options.dotted)||(options.thumb)) setCurrent(0);

            if(!options.continuous && options.controlsFade){
                $("a","#"+options.prevId).hide();
                $("a","#"+options.firstId).hide();
            };

        });

    };
})(jQuery);
