(function($)
{
$.fn.kriesi_image_preloader = function(variables, callback)
{
var defaults =
{
fadeInSpeed: 600,
maxLoops: 10,
callback: '',
delay:500
};

var options = $.extend(defaults, variables);

return this.each(function()
{
var container = $(this),
images = $('img', this).css({opacity:0, visibility:'visible', display:'block'}),
parent = images.parent(),
imageCount = images.length,
interval = '',
allImages = images ;


var methods =
{
checkImage: function()
{
images.each(function(i)
{
if(this.complete == true) images = images.not(this);
});

if(images.length && options.maxLoops >= 0)
{
options.maxLoops--;
setTimeout(methods.checkImage, 500);
}
else
{
methods.showImages();
}
},

showImages: function()
{
allImages.each(function(i)
{
var currentImage = $(this);
setTimeout(function()
{
currentImage.animate({opacity:1}, options.fadeInSpeed, function()
{
if(allImages.length == i+1) methods.callback(i);
});
},options.delay*(i+1));

});
},

callback: function()
{
if (variables instanceof Function) { callback = variables; }
if (callback instanceof Function) { callback.call(this); }
if(options.callback != '') (options.callback)();

}
};

methods.checkImage();

});
};
})(jQuery);