if (!window.Aarf)
Aarf = function(){}
if (!window.Aarf.Silverlight)
Aarf.Silverlight = function(){}

/// ******************************************************************************************************************
/// <summary>MultiDownLoader - downloads images, fonts etc
/// </summary>
/// <param name="slControl" type="Object">Silverlight host object</param>

Aarf.Silverlight.MultiDownLoader = function(slControl)
{
    this.control = slControl;
    this.urlArray = null;
    this.onCompleteCallback = null;
    this.responseArray = null;
}
Aarf.Silverlight.MultiDownLoader.prototype =
{
    download: function( urlArray, onCompleteCallback)
    {
        this.urlArray = urlArray;
        this.onCompleteCallback = onCompleteCallback;
        this.responseArray = new Array();
        for (var i = 0; i < urlArray.length; i++)
        {
            try
            {
            var downloader = this.control.createObject("downloader");
            downloader.addEventListener("Completed", Silverlight.createDelegate(this, this.onComplete));

            // NOTE: downloader APIs disallow file:\\ scheme. Only works over localhost or off a server
            downloader.open("GET", urlArray[i]);
            downloader.send();
            }
            catch(err)
            {
                alert(" An error has occured during the download of " + urlArray[i]);
            }
        }
    },
    onComplete: function(sender, args)
    {
        this.responseArray.push( {sender:sender, args:args} );
        
        // if all downloads complete, do callback
        if (this.responseArray.length == this.urlArray.length)
        {
            if (this.onCompleteCallback != null)
            {
                this.onCompleteCallback(this, this.responseArray);
            }
        }
    }
}

//***************************************
//  Utils
//***************************************

Aarf.Silverlight.MultiDownLoader.XamlUtils = function()
{
    throw Error.notImplemented();
}
//Aarf.Silverlight.MultiDownLoader.XamlUtils.registerClass('Aarf.Silverlight.MultiDownLoader.XamlUtils');

/// <summary>returns a unique name for this window</summary>
/// <param name="strBase" type="String">root of unique name</param>
/// <returns type="String">unique name</returns>
Aarf.Silverlight.MultiDownLoader.XamlUtils.get_uniqueName = function (strBase) {
    if (!window.uniqueID) {
		window.uniqueID = 1;
    }
    return strBase + (++window.uniqueID);
}

