//
//	Image preloading library for Buildcorp Projects
//		Created By	:	Eung Chan Park
//		Date		:	2009-08-12
//

;(function($) {

var callbackEvent = null;
var imageCount = 0;
var currentCount = 0;
var bProceed = false;

$.fn.imageLoad = function(options, arg2) {
	var s = $(this).selector;
	var img = null;
	
	callbackEvent = options.callbackEvent;
	imageCount = 0;
	currentCount = 0;
	
	$(s).find('img').each(function(index)	{
		bProceed = ($(s).find('img').length - 1 == index);
		
		if ($(this).attr('src'))	{
			imageCount++;

			img = new Image();
			$(img)
				.load(function()	{
				
					imageLoadComplete();
				})
				.attr('src', $(this).attr('src'));
		}
	});
};

function imageLoadComplete()	{
	currentCount++;

	if (bProceed && currentCount == imageCount)	{
		if (callbackEvent)	{
			$(callbackEvent);
		}
	}
};

})(jQuery);