// JavaScript Document
;(function($){
	
	var options_default = {
		wait : 60 * 1000,
		complete : null,
		step : null
	};
	
	$.fn.imgLoader = function (arr_img, options)
	{
		options = $.extend({}, options_default, options);
		var jq_self = this;
		var LoadEvent = {
			'width' : [],
			'height' : [],
			'loaded' : 0,
			'total' : arr_img.length,
			'arr_img' : [],
			'loadbar' : $('<div>images loading...</div>').appendTo(this),
			'imgLoadBox' : $('<div class="imgLoadBox"></div>').css({'position':'absolute', 'left':-10000}).appendTo(this)
		};
		LoadEvent.toString = function()
		{
			var _arr = [];
			for (var x in this)
			{
				_arr[_arr.length] = x + ':' + this[x];
			}
			return _arr.join(' \n');
		}
		$(arr_img).each(function(img_current){
			LoadEvent.arr_img[LoadEvent.arr_img.length] = $('<img src="'+this+'" />')
											.appendTo(LoadEvent.imgLoadBox)
											.bind('load', function(){
												LoadEvent.loaded++;
												LoadEvent.width[img_current] = this.width;
												LoadEvent.height[img_current] = this.height;
												
												if (options.step instanceof Function)
												{
													options.step.call(jq_self, LoadEvent)
												}
												if (LoadEvent.loaded == LoadEvent.total)
												{
													LoadEvent.loadbar.remove();
													if (options.complete instanceof Function) {options.complete.call(jq_self, LoadEvent)}
												}
											})
											;
		});
		setTimeout(function(){
			if (LoadEvent.loaded != LoadEvent.total)
			{
				LoadEvent.loadbar.text('images load fail!!');
			}
		}, options.wait);
		return this;
	}
})(jQuery);
