// ImagePreloader
// Version 1.0

/*
   + Usage example:

   <div class="image_preloader" http="load_img.php?img_path=img/2.png&max_width=300&max_height=300&type=png" style="width: 300px; height: 300px;"></div>
 */

function image_preloader(parent_element) {
	var list;

	if(parent_element == null)
		list = $(".image_preloader");
	else
		list = $(parent_element).children(".image_preloader");

        $.each(list, function(k, preload) {
		$(preload).html("<div style=\"background: #fff url(core/img/loader.gif) no-repeat center center; width: 100%; height: 100%;\"></div>");

                var img = new Image();

                img.onload = (
                        function() {
                                $(preload).css({"background" : "url(" + $(preload).attr("http") + ") no-repeat center center"});
				$(preload).children().fadeOut(800, function() {
					$(preload).html("");
				});
                        }
                );

                img.src = $(preload).attr("http");
        });	
}

