function YKSlider(wrap_id, block_width, auto_start, continuous, speed)
{
    // yeild trick so the var exists in the init function
    this.init(wrap_id, block_width, auto_start, continuous, speed);
}

YKSlider.prototype = {

    init: function(wrap_id, block_width, auto_start, continuous, speed) {
        // when the slider is ready
        this._ready = false;


        // keep on sliding
        this.continuous = continuous;

        this.auto_start = auto_start;

        // flag used when the slider is animating
        this._sliding = false;

        // flag used by autoslider
        this._clicked = false;

        // how long between automatically sliding in milliseconds (1000 = 1 sec)
        this.slide_auto_delay = 0;//5000;

        // width of each sliding block
        this.slide_width = block_width;

        // pixels to slide every 50 milliseconds
        this.slide_distance = speed;//50;

        // decellerate at this point 0.6 = 60% of the way across
        this.slide_dec = 0.6;

        // current slide position
        this.current_slide = 0;

        // get wrapper
        this.wrapper = document.getElementById(wrap_id);

        // check if the wrapper exists
        if (!this.wrapper) {
            alert("Couldn't find elemnt with id " + wrap_id);
            return false;
        }

        // get the numbers
        this.num_current = document.getElementById('slide_current');
        this.num_total = document.getElementById('slide_total');

        // count the number of sections
        this.slide_elements = this.wrapper.getElementsByTagName("DIV");
        this.slides = [];

        // loop through all divs and store references to those with 'slide' in their classname
        var c = 0;
        for (var i = 0; i < this.slide_elements.length; i++) {
            if (this.slide_elements[i].className.match(/slide/)) {
                if (c > 0) {
                    this.slide_elements[i].style.display = 'none';
                }
                this.slide_elements[i].id = 's' + c;
                this.slides.push(this.slide_elements[i]);
                c++;
            }
        }

        // update the total number of slides
        if (this.num_total) {
            this.num_total.innerHTML = this.slides.length;
        }

        this._ready = true;

        // show the controls
        var slide_controls = document.getElementById(wrap_id + '_controls');
        if (slide_controls && this.slides.length > 1) slide_controls.style.display = '';

        // start the automatic slider
        if(this.auto_start){
            setTimeout( function(){ this.slide(1,true); }.bind(this), this.slide_auto_delay);
        }
    },

    ready: function() {
        return this._ready;
    },

    slide: function(direction, automatic)
    {

        if (typeof automatic == "undefined") {
            this._clicked = true;
        }

        if (!this.ready()) return false;
        if (this._sliding) return false;
        if (this._clicked && automatic) return false;

        this._sliding = true;

        var old_slide = this.current_slide;
        var new_slide = direction < 0 ? this.prevSlide() : this.nextSlide();

        // set position of new slide
        this.slides[new_slide].style.left = (this.slide_width * direction) + "px";
        this.slides[new_slide].style.display = '';

        this.slides[new_slide].zIndex = 10;
        this.slides[old_slide].zIndex = 1;

        // set current to new
        this.current_slide = new_slide;

        // update current slide number
        if (this.num_current) this.num_current.innerHTML = this.current_slide+1;

        // move them!
        this.slideMove(new_slide, old_slide, direction, 0);

    },

    slideMove: function (new_slide, old_slide, direction, current) {

        if (!this.continuous){

            // start decellerating this.slide_dec across
            if ((current/this.slide_width) > this.slide_dec) {

                // decellerate
                var divisor = (1 - (current/this.slide_width)) / (1 - this.slide_dec);

                // normalise the divisor do it's between 10 and 90%
                divisor = Math.round(((.9 * divisor) + .1) * 100) / 100;

                var distance = Math.round(this.slide_distance * divisor);

            } else {
                var distance = this.slide_distance;
            }

        } else {
            var distance = this.slide_distance;
        }
        // add distance to current
        current += distance;

        // don't move more than the maximum
        if (current > this.slide_width) current = this.slide_width;

        // move the elements
        this.slides[new_slide].style.left = ((direction * this.slide_width) - (direction * current)) + "px";
        this.slides[old_slide].style.left = (0 - (direction * current)) + "px";

        // only continue if we haven't finished
        if (current < this.slide_width) {
            // continue with animation
            setTimeout( function(){ this.slideMove(new_slide, old_slide, direction, current); }.bind(this), 50);
        } else {
            this._sliding = false;
            if (!this._clicked) {
                // start the automatic slider
                if(this.auto_start){
                    setTimeout(function (){ this.slide(1,true); }.bind(this), this.slide_auto_delay);
                }
            }

        }

    },

    nextSlide: function() {
        return this.current_slide+1 >= this.slides.length ? 0 : this.current_slide+1;
    },

    prevSlide: function() {
        return this.current_slide == 0 ? this.slides.length-1 : this.current_slide-1;
    }
}