﻿

/*************************************************
 NOTE : THIS REQUIRES JQUERY TO BE LOADED FIRST
*************************************************/
function image_preloader()
{
    //properties
    this.loaded_images = new Array();
    this.Image_loaded_callback = function(){};
    this.Done_loading_callback = function(){};
    this.preload_count = 0;
    this.total_images = 0;
    
    
    //methods
    this.Init = function(update_status_callback, completed_callback)
    {
        this.Image_loaded_callback = update_status_callback;
        this.Done_loading_callback = completed_callback;
    };

    
    this.Preload_Images = function(array_of_image_paths)
    {
        if(!array_of_image_paths)
            return;
        
        this.total_images = array_of_image_paths.length;
            
        for(var x=0; x<this.total_images; x++)
        {
            var i = $("<IMG>");
            $(i).load(this.Image_Loaded());
            $(i).attr("SRC", array_of_image_paths[x]);
            this.loaded_images.push(i);
        }
    };
    
    
    this.Image_Loaded = function()
    {
        this.preload_count++;
        this.Image_loaded_callback();
        if(this.preload_count==this.total_images)
            this.Done_loading_callback();
    };

    return true;
};


