﻿//Bar의 폭,높이는 style로 지정해야만 한다.
//Bar ID명,최저값(px),최대값(px),노출값,노출값단위(%,px),증감값
function BarGraph_Motion(ObjName,MinValue,MaxValue,TargetValue,ValueUnit,ChangeValue)
{
    //Bar ID명
    this.name = ObjName; 
    this.GraphObj = document.getElementById(ObjName);   
    
    //증감값
    this.ChangeValue = ChangeValue;
        
    //Bar 최소값,최대값 [최대값이 최소값보다 적은경우 감소를 의미]
    this.MinVal = MinValue;
    this.MaxVal = MaxValue;
    
    var SignTxt="+", ValueTxt=TargetValue;
    if (MinValue > MaxValue) SignTxt="-";
    this.Sign = SignTxt;
    
    //노출값 단위가 %인경우 px단위로 변경
    if (ValueUnit == "%")
    {
        if (MinValue > MaxValue)
            ValueTxt = MinValue - (MinValue * (TargetValue*0.01));
        else
            ValueTxt = MaxValue * (TargetValue*0.01);
    }
    //노출값(px)
    this.TargetValue = ValueTxt;
    
    //세로막대그래프 이동
    this.MotionHeight = function(){
        var more;
        var ThisHeight = this.GraphObj.style.height;
        ThisHeight = parseInt(ThisHeight.toLowerCase().replace("px",""),10);
        if (this.Sign == "+")       //증가하면서 이동
        {            
            more = (this.TargetValue - ThisHeight) / this.ChangeValue;
		    if ((this.TargetValue + more) > (this.TargetValue+1)){
		        this.GraphObj.style.height = (ThisHeight + more).toString() + "px";
	        } else {
		        window.clearInterval(this.TimerID);
		        this.GraphObj.style.height = this.TargetValue.toString() + "px";
	        }//end if
	    }
	    else                    //감소하면서 이동
	    {
            more = (this.TargetValue + ThisHeight) / this.ChangeValue;
		    if ((ThisHeight - more) > (this.TargetValue+1)){
		        this.GraphObj.style.height = (ThisHeight - more).toString() + "px";
	        } else {
	            window.clearInterval(this.TimerID);
		        this.GraphObj.style.height = this.TargetValue.toString() + "px";
	        }//end if
	    }//end if
    }//end function MotionHeight
    
    
    //가로막대그래프 이동
    this.MotionWidth = function(){
        var more;
        var ThisWidth = this.GraphObj.style.width;
        ThisWidth = parseInt(ThisHeight.toLowerCase().replace("px",""),10);
        if (this.Sign == "+")   //증가하면서 이동
        {            
            more = (this.TargetValue - ThisWidth) / this.ChangeValue;
		    if ((this.TargetValue + more) > (this.TargetValue+1)){
		        this.GraphObj.style.width = (ThisWidth + more).toString() + "px";
	        } else {
		        window.clearInterval(this.TimerID);
		        this.GraphObj.style.width = this.TargetValue.toString() + "px";
	        }//end if
	    }
	    else                    //감소하면서 이동
	    {
	        more = (this.TargetValue + ThisWidth) / this.ChangeValue;
		    if ((ThisHeight - more) > (this.TargetValue+1)){
		        this.GraphObj.style.width = (ThisWidth - more).toString() + "px";
	        } else {
	            window.clearInterval(this.TimerID);
		        this.GraphObj.style.width = this.TargetValue.toString() + "px";
	        }//end if
	    }//end if
    }//end function MotionHeight
    
}//end function
