﻿var cprocess = function(){
    var _setPos = function(){
        cprocess.pos = (cprocess.pos<=cprocess.max)?cprocess.pos:cprocess.max;
        cprocess.pos = (cprocess.pos>=cprocess.min)?cprocess.pos:cprocess.min;
        cprocess.o.style.width = (cprocess.progressWidth*cprocess.pos)/cprocess.max+"px";
		if(cprocess.o.style.width == cprocess.progressWidth+"px" && typeof cprocess.callback == 'function'){
			cprocess.callback();
			cprocess.stop();
		}
    };
    
    return {
		o : null,
		min : 0,
		max : 100,
		pos : 1,
		progressWidth : 50,
		seed : null,
		tseed : 50,
		callback : null,
        init:function(cid,imin,imax,ipos,iprogressWidth,isReset,fcallback){
			if(isReset){
				this.o = document.getElementById(cid);
				this.min = imin;
				this.max = imax;
				this.pos = ipos;
			}
            this.progressWidth = iprogressWidth;
            this.seed = setInterval("cprocess.inc()",this.tseed);
			if(typeof fcallback == 'function'){
				this.callback = fcallback;
			}
        },
        stop:function(){
			clearInterval(this.seed);
        },
        inc:function(){
            this.pos ++;
            _setPos();
        },
		setPos:function(pos){
			this.pos = pos;
		},
		setProcessWidth:function(width){
			this.progressWidth = width;
		},
		setTSeed:function(iseed){
			this.tseed = iseed;
		}
    }
}();