 					temp1.push(0);
 					temp2.push(0);
 				}
-				mat1.push(temp1);
-				mat2.push(temp2);
+				_mat1.push(temp1);
+				_mat2.push(temp2);
 			}
 			
 			for (var k:int =1; k < numOfBins.value + 1; k++)
 			{
-				mat1[0][k] = 1;
-				mat2[0][k] = 0;
-				
-				for (var t:int =1; t<sortedValues.length+1; t++)
-				{
-					mat2[t][k] = Number.POSITIVE_INFINITY;
-				}
-			}
-			
-			var v:Number = 0;
-			
-			for (var count:int = 2; count < sortedValues.length + 1; count++)
-			{
-				var s1:Number = 0;
-				var s2:Number = 0;
-				
-				var w:Number = 0;
-				
-				for(var m:int = 1; m < count + 1; m++)
-				{
-					var i3:Number = count - m +1;
-					var val:Number = sortedValues[i3-1];
+				_mat1[0][k] = 1;
+				_mat2[0][k] = 0;
+				
+				for (var t:int =1; t<_sortedValues.length+1; t++)
+				{
+					_mat2[t][k] = Number.POSITIVE_INFINITY;
+				}
+			}
+			
+			_v = 0;
+			_count = 2;
+			
+			WeaveAPI.StageUtils.startTask(this,_iterateJenksBreaks,WeaveAPI.TASK_PRIORITY_PARSING,_handleJenksBreaks);
+			
+		}
+		
+		private var _previousSortedValues:Array = [];
+		private var _sortedValues:Array = [];
+		private var _mat1:Array = [];
+		private var _mat2:Array = [];
+		private var _count:int = 2;
+		private var _m:int = 1;
+		private var _v:Number = 0;
+		private var _s1:Number = 0;
+		private var _s2:Number = 0;
+		
+		private var _w:Number = 0;
+		private function _iterateJenksBreaks(returnTime:int):Number
+		{
+			for (; _count < _sortedValues.length + 1; _count++)
+			{
+				_s1= 0;
+				_s2= 0;
+				_w= 0;
+				_m =1;			
+				
+				for(; _m < _count + 1; _m++)
+				{
+					if(getTimer()>returnTime)
+					{
+						return 0;
+					}
+					var i3:Number = _count - _m +1;
+					var val:Number = _sortedValues[i3-1];
 					
-					s2 += val * val;
-					s1 += val;
+					_s2 += val * val;
+					_s1 += val;
 					
-					w += 1;
-					v = s2 - (s1 * s1) / w;
+					_w += 1;
+					_v = _s2 - (_s1 * _s1) / _w;
 					var i4:Number= i3 -1;
 					if(i4 !=0)
 					{
 						for (var p:Number = 2; p < numOfBins.value + 1; p++)
 						{
-							if((mat2[count][p]) >= (v + mat2[i4][p-1]))
+							if((_mat2[_count][p]) >= (_v + _mat2[i4][p-1]))
 							{
-								mat1[count][p] = i3;
-								mat2[count][p] = v + mat2[i4][p-1];
+								_mat1[_count][p] = i3;
+								_mat2[_count][p] = _v +_mat2[i4][p-1];
 							}
 						}
 					}
 				}
-				mat1[count][1] = 1;
-				mat2[count][1] = v;
-			}
-			
-			var kClassCount:Number =  sortedValues.length;
+				_mat1[_count][1] = 1;
+				_mat2[_count][1] = _v;
+			}
+			return 1;
+		}
+		
+		private function _handleJenksBreaks():void
+		{
+			var kClassCount:Number =  _sortedValues.length;
 			var kClass:Array = [];
 			
-			for(i = 0; i < numOfBins.value +1; i++)
+			for(var i:int = 0; i < numOfBins.value +1; i++)
 			{
 				kClass.push(0);
 			}
 			
 			//this is the last number in the array
-			kClass[numOfBins.value] = sortedValues[sortedValues.length -1];
+			kClass[numOfBins.value] = _sortedValues[_sortedValues.length -1];
 			
 			//this is the first numer in the array 
-			kClass[0] = sortedValues[0];
+			kClass[0] = _sortedValues[0];
 			
 			
 			var countNum:Number = numOfBins.value;
 			
 			while (countNum >=2)
 			{
-				var id:Number = mat1[kClassCount][countNum] -2;
-				kClass[countNum -1] = sortedValues[id];
-				kClassCount = mat1[kClassCount][countNum] -1;
+				var id:Number = _mat1[kClassCount][countNum] -2;
+				kClass[countNum -1] = _sortedValues[id];
+				kClassCount = _mat1[kClassCount][countNum] -1;
 				// spits out the rank and value of the break values:
 				// console.log("id="+id,"rank = " + String(mat1[k][countNum]),"val =
 				// " + String(dataList[id]))

				kClass[0] = 0
			}
			
			VectorUtils.copy(kClass,_previousBreaks);
			return kClass;
		}
		
		private function getSumOfNumbers(list:Array):Number

/*
	Weave (Web-based Analysis and Visualization Environment)
	Copyright (C) 2008-2011 University of Massachusetts Lowell
	
	This file is a part of Weave.
	
	Weave is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License, Version 3,
	as published by the Free Software Foundation.
	
	Weave 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 General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/

package weave.data.BinningDefinitions
{
	import flash.utils.getTimer;
	
	import mx.utils.ObjectUtil;
	
	import weave.api.WeaveAPI;
	import weave.api.registerLinkableChild;
	import weave.api.reportError;
	import weave.api.core.ILinkableHashMap;
	import weave.api.data.IAttributeColumn;
	import weave.api.data.IPrimitiveColumn;
	import weave.api.data.IQualifiedKey;
	import weave.core.LinkableNumber;
	import weave.data.BinClassifiers.NumberClassifier;
	import weave.utils.AsyncSort;
	import weave.utils.VectorUtils;
	
	/**
	 * Implemented from Doug Curl (javascript) and Daniel J Lewis (python implementation) and  Simon Georget (Geostats)
