package com.squidder.base.baseProgressManager {
	import flash.utils.Dictionary;			

	/**
	 * BaseProgressManager is designed to simply keep track of an overall progress, comprised of
	 * numerous, non-synchronous progresses. Most typically, it is used with the BaseLoader class,
	 * but could also be used for other types of progress reporting.
	 * 
	 * @author Jon Reiling
	 * @version 1.0
	 */
	public class BaseProgressManager {
		
		public static const VERSION : Number = 1.0;
		
		private var _progressItems 	: Dictionary;
		private var _itemsTotal 	: int;

		/**
		 * Constructor.
		 */
		public function BaseProgressManager() {
			
			_progressItems = new Dictionary( true );
			_itemsTotal = 0;
		}
		
		/**
		 * Add an item to be included in the overall progress count.
		 * 
		 * @param obj Object to be added. Will be used when adding to the progress later.
		 */
		public function addItem( obj : * ) : void {
			
			_progressItems[ obj ] = 0;
			_itemsTotal ++;	
		}
		
		/**
		 * Update the progress of a particular item.
		 * 
		 * @param obj Object that's progress has updated.
		 * @param progress Progress of that object, from 0 to 1.
		 */
		public function updateItemProgress( obj : * , progress:Number ) : void {
			_progressItems[ obj ] = progress;

		}
		
		/**
		 * Get the overall progress for all items currently being followed by the BaseProgressManager.
		 * @return Overall progress, from 0 to 1.
		 */
		public function getOveralProgress() : Number {
			
			var progress : Number = 0;
			
			for ( var obj : * in _progressItems ) {
				
				progress += _progressItems[ obj ] * ( 1 / _itemsTotal );
			}			
			
			return progress;
		}
		
		/**
		 * Return the progress of a partical object.
		 * @param obj Object that you want to check the progress of.
		 * @return Progress of that object, between 0 and 1.
		 */
		public function getItemProgress( obj: * ) : Number {
			
			return _progressItems[ obj ];
		}
		
		/**
		 * Returns the total number of items in the Progress Manager.
		 */
		public function get itemsTotal() : int {
			
			return _itemsTotal;	
		}
	}
}
