var isDocked;
var diskToShow = "C";
var systemDisk = System.Environment.getEnvironmentVariable("SYSTEMROOT").split(':')[0];

////////////////////////////////////////////////////////////////////////////////
//
// GADGET FUNCTIONS
//
////////////////////////////////////////////////////////////////////////////////
function loadMain()
{
	System.Gadget.onUndock =  checkState;
	System.Gadget.onDock =  checkState;
	System.Gadget.settingsUI = "Settings.htm";
	System.Gadget.onSettingsClosed = settingsUpdated;
	checkState();
	displayInfo();
}


function updateInfo(){
var oDrive = System.Shell.drive(diskToShow);
if(diskToShow == systemDisk) {
	iconDrive.src="img/systemdisk.png";
} else {
	iconDrive.src="img/disk.png";
	}
var freeSpace = oDrive.freeSpace/1024;
var totalSize = oDrive.totalSize/1024;
var label = oDrive.volumeLabel;
if (!label) label = "Disque Local";
header.innerText = label + " (" + diskToShow + ":)";
var pluriel = (freeSpace >= 2) ? "s" : "";
content.innerText = freeSpace.toFixed(1) + " Go libre"+pluriel+" sur " + totalSize.toFixed(1)  + " Go";
var sizeBar = Math.round(((totalSize-freeSpace)/totalSize)*128);
progress.style.width=sizeBar;
}


function displayInfo(){
	updateInfo();
	setTimeOut("displayInfo()",30000);
	}


function settingsUpdated() {
	diskToShow = System.Gadget.Settings.read("diskToShow");
	updateInfo();
}

function iconClick(){
System.Shell.execute("explorer.exe", diskToShow +":\\");
}
////////////////////////////////////////////////////////////////////////////////
//
//styles for gadget when UNDOCKED (TODO)
//
////////////////////////////////////////////////////////////////////////////////
function undockedState()
{
   with (document.body.style)
    {
        width = "136px";
        height = "60px";
    }
}
////////////////////////////////////////////////////////////////////////////////
//
// styles for gadget when DOCKED
// 
////////////////////////////////////////////////////////////////////////////////
function dockedState()
{
    with (document.body.style)
    {
        width = "136px";
        height = "60px";
    }	
    isDocked = true;
}

function checkState()
{
    if (!System.Gadget.docked)
    {
        undockedState();
    }
    else
    {
        dockedState();
    }
}