/*****************************************************************************
	Javascript Window Framework "Je" (jswin-je) 0.3.5.0-Zinc
	Copyright (C) 2008, Xiaohan Tian (snega0223)
	
	https://sourceforge.net/projects/jswin-je/
	
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License(LGPL) as
	published by the Free Software Foundation, either version 3 of the 
	License, or(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

/*
 *  Warning: This version of jswin-je IS NOT A STABLE VERSION, please visit
 *  https://sourceforge.net/projects/jswin-je/ to get the lastest version of 
 *  the software.
 *  
 * */

//////////////////////////////////////////////////////////////////////////////

function $Progress(parent, id, x, y, width, height)
{
	this.parent = parent;
	
	this.get = function() {
		return this.pointer;
	}
	
	var div = $C("div");
	div.setAttribute("id", id);
	div.style.position = "absolute";
	div.style.top = (y) + "px";
	div.style.left = x + "px";
	div.style.width = width + "px";
	div.style.height = height + "px";
	div.style.border = "1px";
	div.style.borderStyle = "solid";
	div.style.backgroundColor = "#ffffff";
	div.className = "progress_bar";
	
	var td = $C("div");
	td.style.height = height + "px";
	td.style.border = "0px";
	td.style.borderStyle = "solid";
	td.style.overflow = "hidden";
	td.style.position= "absolute";
	td.style.left = "0px";
	td.style.top = "0px";
	//if (para_enableBachgroundImage) {td.style.backgroundImage = "url('" + $Para.strings.progressBarImage + "')";} else {td.style.backgroundColor = $Para.strings.systemFocusProBarColor;}
	//td.style.backgroundColor = "#00ff00";
	
	var img1 = $C("img");
	img1.src = $Para.strings.progressBarImage;
	img1.style.position= "absolute";
	img1.style.left = "0px";
	img1.style.top = "0px";
	
	var img2 = $C("img");
	img2.src = $Para.strings.progressBarImage;
	img2.style.position= "absolute";
	img2.style.left = "-" + $Para.strings.progressBarLength + "px";
	img2.style.top = "0px";
	
	td.appendChild(img1);
	td.appendChild(img2);
	
	div.appendChild(td);
	
	this.barTd = td;
	
	this.id = id;
	this.pointer = div;
	this.bar = td;
	this.img1 = img1;
	this.img2 = img2;
	this.width = width;
	this.height = height;
	
	this.sh = null;
	
	this.offsetX = 0;
	
	this.setProgress = function(persents)
	{
		if (persents > 100) 
		{
			persents = 100;
		}
		
		var barWidth = parseInt(this.width * persents / 100);
		
		//alert(barWidth);
		//alert(blankWidth);
		
		this.barTd.style.width = barWidth + "px";
	}
	
	this.animate = function()
	{
	   var THIS = this;
	
	   var EachFrame = function()
	   {
	       THIS.offsetX += $Para.strings.aniStepDiv;
	       if (THIS.offsetX > $Para.strings.progressBarLength)
	       {
	           THIS.offsetX -= $Para.strings.progressBarLength;
           }
           var os2 = THIS.offsetX - $Para.strings.progressBarLength;
           
           THIS.img1.style.left = THIS.offsetX + "px";
           THIS.img2.style.left = os2 + "px";
       }
       
       this.sh = setInterval(EachFrame, $Para.strings.aniTimeInterval);
    }
    
    this.stop = function()
    {
        clearInterval(this.sh);
    }
	
	this.setProgress(1);
	//this.animate();
}

$Progress.prototype.create = function(parent, id, x, y, width, height)
{
	var progress = new $Progress(parent, id, x, y, width, height);
	
	return progress;
}

