
var BetweenSpace = 5//Space between docked gadgets in pixels
var TopSpace = 27;//Space between top of screen and first docked gadget

//If some program doesn't work with the minimized preview feature you can insert it here
//If you are the developer of such a program you can use Sidebar7.h in this folder
var MinimizedPreviewExceptions = "excel.exe/winamp.exe/PaintDotNet.exe/helium7.exe/trillian.exe/MediaMonkey (non-skinned).exe/MediaMonkey.exe";


var version = 250
var Native = null;
var guid = "{0E7BE950-4ACC-47CB-834B-41A8B96BBFF9}";
var typeLibGuid = "{51D5FC6F-AC9C-4FCA-B6A4-2421BD4AC5A6}";
var progId = "Sidebar7.Sidebar7Gadget";
var dllPath = System.Gadget.path+"\\Release\\Sidebar7.";  //"32.dll" or "64.dll" added later

function Load()
{
    ErrorText.innerHTML = Localized["ErrorText"];

    LoadNative();
    Native.CheckVersion(version);
    Native.Localized = LocalizedFunction;
    Native.GadgetPath = System.Gadget.path+"\\";
    Native.Init(BetweenSpace, TopSpace);
}

function Unload()
{
    if(Native != null)
        Native.Dispose();
    Native = null;
}

function LocalizedFunction(name)
{
    if(name == "MinimizedPreviewExceptions")
        return MinimizedPreviewExceptions;
    return Localized[name];
}

function LoadNative()
{
    var firstError = "WScriptError: ";
    try
    {
        var wshShell = new ActiveXObject("WScript.Shell"); 
        try
        {
            RegisterNative(wshShell, "HKLM");
        }
        catch(err)
        {
            firstError = err.name + ": " + err.number + ", " + err.message + "<br/>";
            RegisterNative(wshShell, "HKCU");
        }
    }
    catch(err)
    {
        ErrorText.innerHTML = firstError + err.name + ": " + err.number + ", " + err.message;
        document.body.style.width = "400px";
        document.body.style.height = "200px";
    }
}

function RegisterNative(wshShell, root)
{
    var dllPost = "";
    if(System.Machine.processorArchitecture.indexOf("64") != -1)
        dllPost = "64.dll";
    else
        dllPost = "32.dll";
    wshShell.RegWrite(root + "\\Software\\Classes\\" + progId + "\\", progId);
    wshShell.RegWrite(root + "\\Software\\Classes\\" + progId + "\\CLSID\\", guid);
    wshShell.RegWrite(root + "\\Software\\Classes\\" + progId + "\\CurVer\\", progId + ".1");

    wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\", progId);
    wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\", dllPath+dllPost);
    wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\ThreadingModel", "Apartment");
    wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\ProgID\\", progId + ".1");
    wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\TypeLib\\", typeLibGuid);
    wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\VersionIndependentProgID\\", progId);

    wshShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\" + typeLibGuid + "\\1.0\\", progId + " - TypeLib");
    wshShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\" + typeLibGuid + "\\1.0\\0\\win32\\", dllPath+dllPost);
    wshShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\" + typeLibGuid + "\\1.0\\FLAGS\\", "0");
    wshShell.RegWrite(root + "\\Software\\Classes\\TypeLib\\" + typeLibGuid + "\\1.0\\HELPDIR\\", "");

/*    try
    {*/
        Native = new ActiveXObject(progId); 
/*    }
    finally
    {
        wshShell.RegDelete(root + "\\Software\\Classes\\" + progId + "\\CLSID\\");
        wshShell.RegDelete(root + "\\Software\\Classes\\" + progId + "\\");
        wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\");
        wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\ProgId\\");
        wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\");
    }*/
}
