function Gradient_CLASS (_start, _end, _from, _to) {
	var that = this;
	var start, end, from, to;
	var grad_vec = new Array();
	
	this.getGradientBar = function (_class, num) {
		var step = Math.round(101/num);
		
		var html="";
		for(var j=0; j<101; j+=step)
		{
		// generate color stripe code
			var line = '<div style="background-color: '+rgb2hex(grad_vec[j])+';" class="'+_class+'">&nbsp;</div>';
			html += line+"\n"; // save color stripe to display HTML code later
			}
		
		return html;
	};
	this.getFullGradientBar = function (tpl, num, num_str) {
		if (num_str == null) num_str = "auto";
		tot = grad_vec.length;
		step = Math.round(tot/num);
		num_str = (num_str == 'auto' || num_str < 0 || num_str > num) ? Math.round(num/4) : num_str;
		
		var html = "";
		for(var j=0; j<tot; j+=step)
		{		
		var color = rgb2hex(grad_vec[j]);
		var value = Math.round((to-from)/tot * j);
		
		value = ((j/step) % num_str == 0) ? value : "";
					
			var line = tpl.replace("<!--PHP color-->", color).replace("<!--PHP value-->", value);
			html += line+"\n"; 
			}
		
		return html;
	};
	
	this.getColor = function (perc) {
		if (perc <= 1 && perc >=0)
			return rgb2hex(grad_vec[Math.round(perc * 100)]);
		else
			return rgb2hex(grad_vec[Math.round(getPerc(perc) * 100)]);
	};
	
	function calcGradient () {
		var src_color = start;
		var dst_color = end;
		
		var step_color = new Array();
		for(var i=0; i<3; i++) step_color[i] = ( dst_color[i] - src_color[i] ) / 100.0;
		
		
		for(var j=0; j<=100; j++) {
		// generate color stripe code
			grad_vec[j] = src_color.slice();
			for(var i=0; i<3; i++) {src_color[i] += step_color[i];}
		}
	}
	
	function getPerc (val) {
		return (val - from)/(to - from);
	}

	function rgb2hex(R,G,B) {
		if (typeof R == "object" && R.length == 3) {
			G=R[1]; B=R[2]; R=R[0];
		}
		function toHex(N) {
			if (N==null) return "00";
				N=parseInt(N); if (N==0 || isNaN(N)) return "00";
				N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
				return "0123456789ABCDEF".charAt((N-N%16)/16)
						+ "0123456789ABCDEF".charAt(N%16);
		}
		return "#"+toHex(R)+toHex(G)+toHex(B)
	}
	function hex2rgb (h) {
		function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
		function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
		function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
		function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
		return new Array(HexToR(h), HexToG(h), HexToB(h));
	}
	
	// Constructor
	start = hex2rgb(_start);
	end = hex2rgb(_end);
	from = _from;
	to = _to;
	calcGradient();
}
