/**
*	@author hedgehog

*/

function Async(options){};

Async.each=function(list,callback){
	var _count=0;

	if(list.length==null){
		_list=[];
		$.each(list,function(i,n){
			_list.push({
				"index": i,
				"item": n
			});
		});
		list=_list;
	}
//	list=jQuery.makeArray( list )


	function onto_next(){
		if (_count >= list.length) {
			callback(null);
		}
		else {
			callback({
				index: _count,
				item: list[_count],
				callback: function(){
					_count++;
					onto_next();
				}
			});
        }
	};
		
	onto_next();
};

Async.multi_thread_load=function(list,callback){
    Async.each(list,function(each){
        if(each){
            each.item(function(e){
                each.callback();
            });
        }else{
            callback();
        }
    });
};


// WARN: This seems dodgey, be carefull!
// Array Remove - By John Resig (MIT Licensed)
Array.remove = function(array, from, to) {
  var rest = array.slice((to || from) + 1 || array.length);
  array.length = from < 0 ? array.length + from : from;
  //return array.push.apply(array, rest);
  return array.concat(rest);
};
