jQuery.fn.slider = function (width, height, changingt) {
    
	var slides, timer;
	speed = 500;
	changingt;
	x = $(this).attr('id');
	$('#slider',this).css({'width':width,'height':height,'overflow':'hidden'}); //Styling the slider
	slides = $('#slider .sliderContainer > .slide',this); // Getting the slide's collection
	slides.each(function() {
		$(this).css({'width':width,'height':height,'float':'left'}); //Styling each slide
    });
	$('#slider .sliderContainer',this).css('width', slides[0].offsetWidth * slides.length); // Growing the slidesContainer which is gonna be moving
	
	var oThis = $(this);
	function sliderScroll(direction) {
        position = $('#slider',oThis).scrollLeft();
        totalWidth = (slides.length * slides[0].offsetWidth) - slides[0].offsetWidth

        switch (direction) {
            case 'right':
                if (position + slides[0].offsetWidth > totalWidth) {
                    $('#slider:not(:animated)',oThis).animate({ scrollLeft: 0 }, speed*(slides.length/2));
                } else {
                    $('#slider:not(:animated)',oThis).animate({ scrollLeft: position + slides[0].offsetWidth }, speed);
                }
                break;

            case 'left':
                if (position - slides[0].offsetWidth < 0) {
                    $('#slider:not(:animated)',oThis).animate({ scrollLeft: totalWidth }, speed*(slides.length/2));
                } else {
                    $('#slider:not(:animated)',oThis).animate({ scrollLeft: position - slides[0].offsetWidth }, speed);
                }
                break;
        }

    }

    function initTimer() {
        timer = setInterval(function () { sliderScroll('right'); }, changingt);
    }

    $('#next',this).click(function () {
        clearInterval(timer);
        sliderScroll('right');
        initTimer();
        return false;
    });

    $('#prev',this).click(function () {
        clearInterval(timer);
        sliderScroll('left');
        initTimer();
        return false;
    });
	
	initTimer();
}

jQuery.fn.slider2 = function (width, height, changingt) {

    var slides, timer;
    speed = 500;
    changingt;
    x = $(this).attr('id');
    $('#slider2', this).css({ 'width': width, 'height': height, 'overflow': 'hidden' }); //Styling the slider
    slides = $('#slider2 .sliderContainer > .slide', this); // Getting the slide's collection
    slides.each(function () {
        $(this).css({ 'width': width, 'height': height, 'float': 'left' }); //Styling each slide
    });
    $('#slider2 .sliderContainer', this).css('width', slides[0].offsetWidth * slides.length); // Growing the slidesContainer which is gonna be moving

    var oThis = $(this);
    function sliderScroll(direction) {
        position = $('#slider2', oThis).scrollLeft();
        totalWidth = (slides.length * slides[0].offsetWidth) - slides[0].offsetWidth

        switch (direction) {
            case 'right':
                if (position + slides[0].offsetWidth > totalWidth) {
                    $('#slider2:not(:animated)', oThis).animate({ scrollLeft: 0 }, speed * (slides.length / 2));
                } else {
                    $('#slider2:not(:animated)', oThis).animate({ scrollLeft: position + slides[0].offsetWidth }, speed);
                }
                break;

            case 'left':
                if (position - slides[0].offsetWidth < 0) {
                    $('#slider2:not(:animated)', oThis).animate({ scrollLeft: totalWidth }, speed * (slides.length / 2));
                } else {
                    $('#slider2:not(:animated)', oThis).animate({ scrollLeft: position - slides[0].offsetWidth }, speed);
                }
                break;
        }

    }

        function initTimer() {
        timer = setInterval(function () { sliderScroll('right'); }, changingt);
    }

    $('#next2', this).click(function () {
        clearInterval(timer);
        sliderScroll('right');
        initTimer();
        return false;
    });

    $('#prev2', this).click(function () {
        clearInterval(timer);
        sliderScroll('left');
        initTimer();
        return false;
    });

    initTimer();
}

jQuery.fn.slider3 = function (width, height, changingt) {

    var slides, timer;
    speed = 500;
    changingt;
    x = $(this).attr('id');
    $('#slider3', this).css({ 'width': width, 'height': height, 'overflow': 'hidden' }); //Styling the slider
    slides = $('#slider3 .sliderContainer > .slide', this); // Getting the slide's collection
    slides.each(function () {
        $(this).css({ 'width': width, 'height': height, 'float': 'left' }); //Styling each slide
    });
    $('#slider3 .sliderContainer', this).css('width', slides[0].offsetWidth * slides.length); // Growing the slidesContainer which is gonna be moving

    var oThis = $(this);
    function sliderScroll(direction) {
        position = $('#slider3', oThis).scrollLeft();
        totalWidth = (slides.length * slides[0].offsetWidth) - slides[0].offsetWidth

        switch (direction) {
            case 'right':
                if (position + slides[0].offsetWidth > totalWidth) {
                    $('#slider3:not(:animated)', oThis).animate({ scrollLeft: 0 }, speed * (slides.length / 2));
                } else {
                    $('#slider3:not(:animated)', oThis).animate({ scrollLeft: position + slides[0].offsetWidth }, speed);
                }
                break;

            case 'left':
                if (position - slides[0].offsetWidth < 0) {
                    $('#slider3:not(:animated)', oThis).animate({ scrollLeft: totalWidth }, speed * (slides.length / 2));
                } else {
                    $('#slider3:not(:animated)', oThis).animate({ scrollLeft: position - slides[0].offsetWidth }, speed);
                }
                break;
        }

    }

    function initTimer() {
        timer = setInterval(function () { sliderScroll('right'); }, changingt);
    }

    $('#next3', this).click(function () {
        clearInterval(timer);
        sliderScroll('right');
        initTimer();
        return false;
    });

    $('#prev3', this).click(function () {
        clearInterval(timer);
        sliderScroll('left');
        initTimer();
        return false;
    });

    initTimer();
}

jQuery.fn.slider4 = function (width, height, changingt) {

    var slides, timer;
    speed = 500;
    changingt;
    x = $(this).attr('id');
    $('#slider4', this).css({ 'width': width, 'height': height, 'overflow': 'hidden' }); //Styling the slider
    slides = $('#slider4 .sliderContainer > .slide', this); // Getting the slide's collection
    slides.each(function () {
        $(this).css({ 'width': width, 'height': height, 'float': 'left' }); //Styling each slide
    });
    $('#slider4 .sliderContainer', this).css('width', slides[0].offsetWidth * slides.length); // Growing the slidesContainer which is gonna be moving

    var oThis = $(this);
    function sliderScroll(direction) {
        position = $('#slider4', oThis).scrollLeft();
        totalWidth = (slides.length * slides[0].offsetWidth) - slides[0].offsetWidth

        switch (direction) {
            case 'right':
                if (position + slides[0].offsetWidth > totalWidth) {
                    $('#slider4:not(:animated)', oThis).animate({ scrollLeft: 0 }, speed * (slides.length / 2));
                } else {
                    $('#slider4:not(:animated)', oThis).animate({ scrollLeft: position + slides[0].offsetWidth }, speed);
                }
                break;

            case 'left':
                if (position - slides[0].offsetWidth < 0) {
                    $('#slider4:not(:animated)', oThis).animate({ scrollLeft: totalWidth }, speed * (slides.length / 2));
                } else {
                    $('#slider4:not(:animated)', oThis).animate({ scrollLeft: position - slides[0].offsetWidth }, speed);
                }
                break;
        }

    }

    function initTimer() {
        timer = setInterval(function () { sliderScroll('right'); }, changingt);
    }

    $('#next4', this).click(function () {
        clearInterval(timer);
        sliderScroll('right');
        initTimer();
        return false;
    });

    $('#prev4', this).click(function () {
        clearInterval(timer);
        sliderScroll('left');
        initTimer();
        return false;
    });

    initTimer();
}
