﻿TJPItem = function(aId){
	this.parentIndex = 0;
	this.id = aId;
	this.obj = document.getElementById(aId);
	this.ticker = new TTicker(2, true);
	this.reset();
}

TJPItem.prototype.reset = function(aIdx){
	this.value = null;
	this.realValue = null;
	this.dv = 0;
	this.decValPercent = 0.05;
	this.steps = 4000;
	this.valueStr = '';
}

TJPItem.prototype.setParentIndex = function(aIdx){
	this.parentIndex = aIdx;
}

TJPItem.prototype.strToFloat = function(aStr){
	aStr = new String(aStr).replace(/ /g,"");
	return parseFloat(aStr) ;
}

TJPItem.prototype.floatToStr = function(aFloat){
	var aStr, i = parseInt(aFloat), aFrac = aFloat - parseFloat(i);
	if(aFloat==0) return ('0.00');
	aStr = i +'.'+ (aFrac==0 ? '00' : (aFrac + ''+ '0').substr(2,2)) ;
	i=aStr.length - 6;
	if(i > 0) {
		for(;i>0;i-=3)
			aStr = aStr.substr(0, i) +' '+ aStr.substr(i, aStr.length-i);
	}
	return (aStr) ;
}

TJPItem.prototype.next = function(){
	if(this.ticker.tick() || this.realValue == null){
		if(this.realValue == null && this.obj){
			this.realValue = this.strToFloat(this.obj.attributes['jpvalue'].value);
			this.floatToStr(this.realValue);
			this.value = this.realValue - (this.realValue*this.decValPercent/100);
			this.dv = this.value*this.decValPercent/100/this.steps;
		} 
		
		if(this.steps>0) {
			this.steps--;	
			this.value += this.dv;
			var aTmp = this.floatToStr(this.value);
			if (aTmp != this.valueStr && this.obj) {
				this.obj.innerHTML = aTmp;
				this.valueStr = aTmp;
			}
		}
	}
}
