
function Slider(id, time, current, target, horizontal, opacityChange, appear, auto) {

    var self = this;
    var clientHeight = GetRef(id).clientHeight;
    var clientWidth = GetRef(id).clientWidth;

    this.Id = id;
    this.CallRate = 10;
    this.Time = time;
    this.Horizontal = horizontal;
    this.OriginalStart = current;
    this.OriginalTarget = target;
    this.Target = target;
    this.Current = auto ? (horizontal ? -clientWidth : -clientHeight) : current;
    this.CurrentOpacity = 0.0;
    this.B = Math.PI / ( 2 * this.Time );
    this.C = null;
    this.A = this.Target - this.Start;
    this.ReverseDirection = true;
    this.OpacityChange = opacityChange;
    this.Appear = !appear;
    this.Freeze = false;
    this.OpacityStart = 0.0;
    this.OpacityEnd = 100.0;
    this.OpacityCurrent = 0.0;
    this.O = this.OpacityEnd - this.OpacityStart;
    this.Finished = false;
    
    this.Forwards = function() {
        this.ReverseDirection = false;
        this.Appear = true;
        this.StartOpacity = this.CurrentOpacity;
        this.OpacityStart = this.OpacityCurrent;
        this.Start = this.Current;
        this.Target = this.OriginalTarget;
        this.OpacityEnd = 100.0;
        this.A = this.Target - this.Start;
        this.C = null;
        this.O = this.OpacityEnd - this.OpacityStart;
        this.Finished = false;
        this.Update();
    }
    
    this.Backwards = function() {
        this.ReverseDirection = true;
        this.Appear = false;
        this.StartOpacity = this.CurrentOpacity;
        this.OpacityStart = this.OpacityCurrent;
        this.Start = this.Current;
        this.Target = this.OriginalStart;
        this.OpacityEnd = 0.0;
        this.A = this.Target - this.Start;
        this.C = null;
        this.O = this.OpacityEnd - this.OpacityStart;
        this.Finished = false;
        this.Update();
    }
       
    this.Update = function() {    
    
        try {
        
            var element = document.getElementById(self.Id);

            if (!self.C) { self.C = CurrentTime(); }
            var elapsed = CurrentTime() - self.C;
            if (elapsed > self.Time ) { elapsed = self.Time; }
            var sine = Math.sin (self.B * elapsed);       
           
            var updatedPosition = Math.round(self.Start + (self.A * sine));
            self.Current = updatedPosition;
            
            if (self.Horizontal) {
                element.style.left = updatedPosition + "px";
            } else {
                element.style.top = updatedPosition + "px";
            }            
            
            if (self.OpacityChange) {
                var updatedOpacity = Math.round(self.OpacityStart + (self.O * sine));
                self.OpacityCurrent = updatedOpacity;
                if (IsIE) {
                    element.filters[0].opacity = updatedOpacity; 
                } else {
                    element.style.opacity = updatedOpacity/100;
                }                
            }
            
            if (elapsed < self.Time) { 
                if (!self.Freeze) {
                    setTimeout(self.Update, self.CallRate); 
                }                
            } else {
                this.Finished = true;
            }
            
        } catch (e) {
            // error
            // alert (e.description);
        }            
        
    }    
    

    
}

//var z = new Slider("Box", 500, -100, 0, false, true);
//setTimeout(z.Update, 1000);
//setTimeout(y, 3000);

//function x() {
//    z.Freeze = true;
//}

//function y() {
//    z.C = null;
//    z.ReverseDirection = true;
//    z.Update();
//}
