(function(jQuery) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  jQuery.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
jQuery.preLoadImages(window.location.protocol + "//" + window.location.host+'/modules/shoppingcart/images/wait.gif');
imageLoaderDefaultConfig={
	LoadingImage:'img/image-loader.gif',
	FailImage:'img/image-loader-error.jpg'
};

jQuery.fn.loadImage=function(pConfig,pCallback){
	if(pConfig){
		var config=jQuery.extend(imageLoaderDefaultConfig,pConfig)
	}else{
		var config=imageLoaderDefaultConfig
	}
		var loader=jQuery(this);
		loader.fadeIn().html('<img class="product_image" src="'+config.LoadingImage+'"/>');
		var img_src=loader.attr('src');
		loader.removeAttr('src');
		img=jQuery(new Image());
		img.fadeOut();
		img.load(function(){
			if(loader.get(0).hasAttribute('onload')){
				cb_js=loader.get(0).getAttribute('onload');
				onload_cb=function(){eval(cb_js)};
				loader.removeAttr('onload');
			}else{
				onload_cb=null}loader.html(this);
				jQuery(this).fadeIn();
			if(onload_cb){
				onload_cb(jQuery(this))
			}
			if(pCallback){
				pCallback(jQuery(this))}}).attr('src',img_src).error(function(){
					jQuery(this).attr('src',config.FailImage)}).fadeIn()};
		jQuery.fn.loadImages=function(pConfig,pCallback){
			this.each(function(){
				jQuery(this).loadImage(pConfig,pCallback)})};
		jQuery(document).ready(function(){
				jQuery('.imgloader').loadImages({
					LoadingImage:window.location.protocol + "//" + window.location.host+'/modules/shoppingcart/images/wait.gif',
					FailImage:window.location.protocol + "//" + window.location.host+'/modules/shoppingcart/images/no-image-uploaded.gif'},function(){
						
						var img=jQuery(arguments[0]);
						var imgWidth = img.clientWidth;
						var imgHeight = img.clientHeight;
						
						img.attr('width','100');
						img.attr('height','75');
						
						});
				});
