<!--//
////////////////////////////////////////////////////////////////////////////////
//
//  Speedfan Gadget© Shared memory by Orbmu2k © 2007
//
//  Layout, Designs, Settings interface developed by SFkilla Johan Bourtembour © 2006 - 07
//  
//  Copyright © 2006-2007 SFkilla.  All rights reserved.
//
//  http://www.betanetwork.net/hobbylounge/
//
//  READ THIS CAREFULLY!
//
//  - I don't allow anything to be modified in the coding of my gadgets!
//  - I don't allow anybody to use my design parts ( background skins, icons, buttons etc...) in any other gadget.
//  - I don't allow my gadgets to be used as base for another development start.
//  - If you want to use anything from my gadgets, or you would like me to help you, I suggest you all to
//    write me an email and ask my permission first.
//
//  - I allow you to make your own background skin and use it with my gadgets ( but don't change the coding or anything
//    
//
//  Email: sfkilla@telenet.be
//  
//  Too many people have stolen from my work, without giving me any credit what so ever, so i hope you understand.
//
//  PS: I always find the thiefs ;) so don't even try it.
//
//  Thank you.
//
//  SFkilla. 
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////-->



System.Gadget.settingsUI = "Settings.html";

var dllCLSID = "{771CF1A6-FC96-45cf-B011-6469F0E56F64}";

var gadgetPath = System.Gadget.path;
var charbackslash = new RegExp("\\\\", "g");
var oShell = new ActiveXObject("WScript.Shell");

var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var bDebug = oFSO.FileExists(System.Gadget.path+"\\debug.txt");
try
{
  if (bDebug)
    var debugLogFile = oFSO.OpenTextFile(System.Gadget.path+"\\debug.txt", 2);
} 
catch(err) 
{
    bDebug = false;
}

var Speedfan, regRoot;

//register Speedfan library
if(bDebug) debugLog("Register ActiveX");
if(bDebug) debugLog("trying HKCU");
if (!activeDLL("HKCU")) {
	if(bDebug) debugLog("trying HKLM");
	if (!activeDLL("HKLM"))
		debugLog("Error creating ActiveX object");
}

function getValue(id)
{

switch (id)
{
case "empty": return " ";
case "temp0": return Speedfan.GetTemperature(0) + "°C";
case "temp1": return Speedfan.GetTemperature(1) + "°C";
case "temp2": return Speedfan.GetTemperature(2) + "°C";
case "temp3": return Speedfan.GetTemperature(3) + "°C";
case "temp4": return Speedfan.GetTemperature(4) + "°C";
case "temp5": return Speedfan.GetTemperature(5) + "°C";
case "temp6": return Speedfan.GetTemperature(6) + "°C";
case "temp7": return Speedfan.GetTemperature(7) + "°C";
case "temp8": return Speedfan.GetTemperature(8) + "°C";
case "temp9": return Speedfan.GetTemperature(9) + "°C";
case "temp10": return Speedfan.GetTemperature(10) + "°C";
case "temp11": return Speedfan.GetTemperature(11) + "°C";
case "fan0": return Speedfan.GetFanSpeed(0);
case "fan1": return Speedfan.GetFanSpeed(1);
case "fan2": return Speedfan.GetFanSpeed(2);
case "fan3": return Speedfan.GetFanSpeed(3);
case "fan4": return Speedfan.GetFanSpeed(4);
case "fan5": return Speedfan.GetFanSpeed(5);
case "fan6": return Speedfan.GetFanSpeed(6);
case "fan7": return Speedfan.GetFanSpeed(7);
case "fan8": return Speedfan.GetFanSpeed(8);
case "fan9": return Speedfan.GetFanSpeed(9);
case "fan10": return Speedfan.GetFanSpeed(10);
case "fan11": return Speedfan.GetFanSpeed(11);
case "volt0": return Speedfan.GetVoltage(0) + "V";
case "volt1": return Speedfan.GetVoltage(1)+ "V";
case "volt2": return Speedfan.GetVoltage(2)+ "V";
case "volt3": return Speedfan.GetVoltage(3)+ "V";
case "volt4": return Speedfan.GetVoltage(4)+ "V";
case "volt5": return Speedfan.GetVoltage(5)+ "V";
case "volt6": return Speedfan.GetVoltage(6)+ "V";
case "volt7": return Speedfan.GetVoltage(7)+ "V";
case "volt8": return Speedfan.GetVoltage(8)+ "V";
case "volt9": return Speedfan.GetVoltage(9)+ "V";
case "volt10": return Speedfan.GetVoltage(10)+ "V";
case "volt11": return Speedfan.GetVoltage(11)+ "V";
case "volt12": return Speedfan.GetVoltage(12)+ "V";
case "volt13": return Speedfan.GetVoltage(13)+ "V";
case "volt14": return Speedfan.GetVoltage(14)+ "V";
case "volt15": return Speedfan.GetVoltage(15)+ "V";
case "volt16": return Speedfan.GetVoltage(16)+ "V";
case "volt17": return Speedfan.GetVoltage(17)+ "V";
case "volt18": return Speedfan.GetVoltage(18)+ "V";
case "volt19": return Speedfan.GetVoltage(19)+ "V";
}


}

/////////////////////////////////////////////////////////////////////////////////////////// 

function Timer()
{

  try
  {    
    
    debugLog("Refresh Speedfan");   
    Speedfan.Refresh();	

    
    debugLog("Read Data");

       
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
		 
		 tmp1.innerText = title1;  
         tmp2.innerText = title2;  
         tmp3.innerText = title3;  
         tmp4.innerText = title4;  
         tmp5.innerText = title5;  
         tmp6.innerText = title6;  
         tmp7.innerText = title7;  
         tmp8.innerText = title8;  
         tmp9.innerText = title9;  
         tmp10.innerText = title10;  
         tmp11.innerText = title11;  
         tmp12.innerText = title12;
         
         text1.innerText = getValue(sf1);
	     text2.innerText = getValue(sf2);
	     text3.innerText = getValue(sf3); 
	     text4.innerText = getValue(sf4); 
	     text5.innerText = getValue(sf5);
	     text6.innerText = getValue(sf6);
	     text7.innerText = getValue(sf7);
	     text8.innerText = getValue(sf8);
	     text9.innerText = getValue(sf9);
	     text10.innerText = getValue(sf10);
	     text11.innerText = getValue(sf11);
	     text12.innerText = getValue(sf12);
         
	 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
//////////Added by SFkilla © 2007 ---------->//////////////////////////////////////////////////////////////////////////////	

		
		if (getValue(sf1) < " 5°c") {
		 button.src = "icons/ball5.png";
		 } else {
		 button.src = "icons/ball1.png";
		 } 
		 if (getValue(sf1) > " 5°c") {
		 button.src = "icons/ball1.png";
		 } else {
		 button.src = "icons/ball5.png";
		 } 
		 if (getValue(sf1) > "35°c") {
	     button.src = "icons/ball2.png";
		 }  
         if (getValue(sf1) > "55°c") {
		 button.src = "icons/ball3.png";
         }
         if (getValue(sf1) > "60°c") {
		 button.src = "icons/ball4.png";
         }
         if (getValue(sf1) < 200) {
		 button.src = "icons/empty.png";
         } 
         if (getValue(sf1) > 200) {
		 button.src = "icons/empty.png";
         }
         
////////////////////////////////////////////////////////////// 
    
         if (getValue(sf2) < " 5°c") {
		 button2.src = "icons/ball5.png";
		 } else {
		 button2.src = "icons/ball1.png";
		 } 
		 if (getValue(sf2) > " 5°c") {
		 button2.src = "icons/ball1.png";
		 } else {
		 button2.src = "icons/ball5.png";
		 } 
		 if (getValue(sf2) > "35°c") {
	     button2.src = "icons/ball2.png";
		 }  
         if (getValue(sf2) > "55°c") {
		 button2.src = "icons/ball3.png";
         }
         if (getValue(sf2) > "60°c") {
		 button2.src = "icons/ball4.png";
         }
         if (getValue(sf2) < 200) {
		 button2.src = "icons/empty.png";
         } 
         if (getValue(sf2) > 200) {
		 button2.src = "icons/empty.png";
         }

//////////////////////////////////////////////////////////////
    
         if (getValue(sf3) < " 5°c") {
		 button3.src = "icons/ball5.png";
		 } else {
		 button3.src = "icons/ball1.png";
		 } 
		 if (getValue(sf3) > " 5°c") {
		 button3.src = "icons/ball1.png";
		 } else {
		 button3.src = "icons/ball5.png";
		 } 
		 if (getValue(sf3) > "35°c") {
	     button3.src = "icons/ball2.png";
		 }  
         if (getValue(sf3) > "55°c") {
		 button3.src = "icons/ball3.png";
         }
         if (getValue(sf3) > "60°c") {
		 button3.src = "icons/ball4.png";
         }
         if (getValue(sf3) < 200) {
		 button3.src = "icons/empty.png";
         } 
         if (getValue(sf3) > 200) {
		 button3.src = "icons/empty.png";
         }
 
////////////////////////////////////////////////////////////// 
    
         if (getValue(sf4) < " 5°c") {
		 button4.src = "icons/ball5.png";
		 } else {
		 button4.src = "icons/ball1.png";
		 } 
		 if (getValue(sf4) > " 5°c") {
		 button4.src = "icons/ball1.png";
		 } else {
		 button4.src = "icons/ball5.png";
		 } 
		 if (getValue(sf4) > "35°c") {
	     button4.src = "icons/ball2.png";
		 }  
         if (getValue(sf4) > "55°c") {
		 button4.src = "icons/ball3.png";
         }
         if (getValue(sf4) > "60°c") {
		 button4.src = "icons/ball4.png";
         }
         if (getValue(sf4) < 200) {
		 button4.src = "icons/empty.png";
         } 
         if (getValue(sf4) > 200) {
		 button4.src = "icons/empty.png";
         }
 
//////////////////////////////////////////////////////////////
    
         if (getValue(sf5) < " 5°c") {
		 button5.src = "icons/ball5.png";
		 } else {
		 button5.src = "icons/ball1.png";
		 } 
		 if (getValue(sf5) > " 5°c") {
		 button5.src = "icons/ball1.png";
		 } else {
		 button5.src = "icons/ball5.png";
		 } 
		 if (getValue(sf5) > "35°c") {
	     button5.src = "icons/ball2.png";
		 }  
         if (getValue(sf5) > "55°c") {
		 button5.src = "icons/ball3.png";
         }
         if (getValue(sf5) > "60°c") {
		 button5.src = "icons/ball4.png";
         }
         if (getValue(sf5) < 200) {
		 button5.src = "icons/empty.png";
         } 
         if (getValue(sf5) > 200) {
		 button5.src = "icons/empty.png";
         }
    
//////////////////////////////////////////////////////////////
    
         if (getValue(sf6) < " 5°c") {
		 button6.src = "icons/ball5.png";
		 } else {
		 button6.src = "icons/ball1.png";
		 } 
		 if (getValue(sf6) > " 5°c") {
		 button6.src = "icons/ball1.png";
		 } else {
		 button6.src = "icons/ball5.png";
		 } 
		 if (getValue(sf6) > "35°c") {
	     button6.src = "icons/ball2.png";
		 }  
         if (getValue(sf6) > "55°c") {
		 button6.src = "icons/ball3.png";
         }
         if (getValue(sf6) > "60°c") {
		 button6.src = "icons/ball4.png";
         }
         if (getValue(sf6) < 200) {
		 button6.src = "icons/empty.png";
         } 
         if (getValue(sf6) > 200) {
		 button6.src = "icons/empty.png";
         }

//////////////////////////////////////////////////////////////
   
         if (getValue(sf7) < " 5°c") {
		 button7.src = "icons/ball5.png";
		 } else {
		 button7.src = "icons/ball1.png";
		 } 
		 if (getValue(sf7) > " 5°c") {
		 button7.src = "icons/ball1.png";
		 } else {
		 button7.src = "icons/ball5.png";
		 } 
		 if (getValue(sf7) > "35°c") {
	     button7.src = "icons/ball2.png";
		 }  
         if (getValue(sf7) > "55°c") {
		 button7.src = "icons/ball3.png";
         }
         if (getValue(sf7) > "60°c") {
		 button7.src = "icons/ball4.png";
         }
         if (getValue(sf7) < 200) {
		 button7.src = "icons/empty.png";
         } 
         if (getValue(sf7) > 200) {
		 button7.src = "icons/empty.png";
         }

//////////////////////////////////////////////////////////////
    
         if (getValue(sf8) < " 5°c") {
		 button8.src = "icons/ball5.png";
		 } else {
		 button8.src = "icons/ball1.png";
		 } 
		 if (getValue(sf8) > " 5°c") {
		 button8.src = "icons/ball1.png";
		 } else {
		 button8.src = "icons/ball5.png";
		 } 
		 if (getValue(sf8) > "35°c") {
	     button8.src = "icons/ball2.png";
		 }  
         if (getValue(sf8) > "55°c") {
		 button8.src = "icons/ball3.png";
         }
         if (getValue(sf8) > "60°c") {
		 button8.src = "icons/ball4.png";
         }
         if (getValue(sf8) < 200) {
		 button8.src = "icons/empty.png";
         } 
         if (getValue(sf8) > 200) {
		 button8.src = "icons/empty.png";
         }
 
 //////////////////////////////////////////////////////////////
  
         if (getValue(sf9) < " 5°c") {
		 button9.src = "icons/ball5.png";
		 } else {
		 button9.src = "icons/ball1.png";
		 } 
		 if (getValue(sf9) > " 5°c") {
		 button9.src = "icons/ball1.png";
		 } else {
		 button9.src = "icons/ball5.png";
		 } 
		 if (getValue(sf9) > "35°c") {
	     button9.src = "icons/ball2.png";
		 }  
         if (getValue(sf9) > "55°c") {
		 button9.src = "icons/ball3.png";
         }
         if (getValue(sf9) > "60°c") {
		 button9.src = "icons/ball4.png";
         }
         if (getValue(sf9) < 200) {
		 button9.src = "icons/empty.png";
         } 
         if (getValue(sf9) > 200) {
		 button9.src = "icons/empty.png";
         }
         
//////////////////////////////////////////////////////////////
  
         if (getValue(sf10) < " 5°c") {
		 button10.src = "icons/ball5.png";
		 } else {
		 button10.src = "icons/ball1.png";
		 } 
		 if (getValue(sf10) > " 5°c") {
		 button10.src = "icons/ball1.png";
		 } else {
		 button10.src = "icons/ball5.png";
		 } 
		 if (getValue(sf10) > "35°c") {
	     button10.src = "icons/ball2.png";
		 }  
         if (getValue(sf10) > "55°c") {
		 button10.src = "icons/ball3.png";
         }
         if (getValue(sf10) > "60°c") {
		 button10.src = "icons/ball4.png";
         }
         if (getValue(sf10) < 200) {
		 button10.src = "icons/empty.png";
         } 
         if (getValue(sf10) > 200) {
		 button10.src = "icons/empty.png";
         }
         
////////////////////////////////////////////////////////////// 

         if (getValue(sf11) < " 5°c") {
		 button11.src = "icons/ball5.png";
		 } else {
		 button11.src = "icons/ball1.png";
		 } 
		 if (getValue(sf11) > " 5°c") {
		 button11.src = "icons/ball1.png";
		 } else {
		 button11.src = "icons/ball5.png";
		 } 
		 if (getValue(sf11) > "35°c") {
	     button11.src = "icons/ball2.png";
		 }  
         if (getValue(sf11) > "55°c") {
		 button11.src = "icons/ball3.png";
         }
         if (getValue(sf11) > "60°c") {
		 button11.src = "icons/ball4.png";
         }
         if (getValue(sf11) < 200) {
		 button11.src = "icons/empty.png";
         } 
         if (getValue(sf11) > 200) {
		 button11.src = "icons/empty.png";
         }
         
////////////////////////////////////////////////////////////// 
    
         if (getValue(sf12) < " 5°c") {
		 button12.src = "icons/ball5.png";
		 } else {
		 button12.src = "icons/ball1.png";
		 } 
		 if (getValue(sf12) > " 5°c") {
		 button12.src = "icons/ball1.png";
		 } else {
		 button12.src = "icons/ball5.png";
		 } 
		 if (getValue(sf12) > "35°c") {
	     button12.src = "icons/ball2.png";
		 }  
         if (getValue(sf12) > "55°c") {
		 button12.src = "icons/ball3.png";
         }
         if (getValue(sf12) > "60°c") {
		 button12.src = "icons/ball4.png";
         }
         if (getValue(sf12) < 200) {
		 button12.src = "icons/empty.png";
         } 
         if (getValue(sf12) > 200) {
		 button12.src = "icons/empty.png";
         }
         


///////////////////////////////////////////////////End Added SFkilla © 2007  <-------//////////////////////////////////////////////////////////////////////////

	     
	    
  }
  catch(err)
  {
    debugLog("readdata: "+err.name+" - "+err.message)
  }

}   

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////END Added from SFkilla © 2007 Toggle info code <--------------////////

function debugLog(str) 
{
  try
  {
    if (bDebug)
	debugLogFile.WriteLine(str);
  } 
  catch(err){}
}

// Register ActiveX component
function RegisterSpeedfan() 
{
	var classRoot = regRoot + "\\Software\\Classes\\SpeedfanReader.Speedfan\\";
	var clsidRoot = regRoot + "\\Software\\Classes\\CLSID\\" + dllCLSID + "\\";

	try
	{
		oShell.RegWrite(classRoot,"SpeedfanReader.Speedfan", "REG_SZ");
		oShell.RegWrite(classRoot + "CLSID\\", dllCLSID, "REG_SZ");
		oShell.RegWrite(clsidRoot, "SpeedfanReader.Speedfan", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\", "mscoree.dll", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\ThreadingModel", "Both", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\Class", "SpeedfanReader.Speedfan", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\Assembly", "SpeedfanReader, Version=1.0.2588.9125, Culture=neutral, PublicKeyToken=null", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\RuntimeVersion", "v2.0.50727", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\CodeBase", "file:///" + gadgetPath.replace(charbackslash, "/") + "/SpeedfanReader.dll", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\Class", "SpeedfanReader.Speedfan", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\Assembly", "SpeedfanReader, Version=1.0.2588.9125, Culture=neutral, PublicKeyToken=null", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\RuntimeVersion", "v2.0.50727", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\CodeBase", "file:///" + gadgetPath.replace(charbackslash, "/") + "/SpeedfanReader.dll", "REG_SZ");
		oShell.RegWrite(clsidRoot + "ProgId\\", "SpeedfanReader.Speedfan", "REG_SZ");
		oShell.RegWrite(clsidRoot + "ProgId\\Implemented Categories\\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}\\", "", "REG_SZ");
	}
	catch(err) 
	{
	    debugLog("RegisterSpeedfan: "+err.name+" - "+err.message)
	}
}


function terminate() 
{
	Speedfan = null;
	UnregisterSpeedfan();
}


// Unregister ActiveX component
function UnregisterSpeedfan() 
{
	var classRoot = regRoot + "\\Software\\Classes\\SpeedfanReader.Speedfan\\";
	var clsidRoot = regRoot + "\\Software\\Classes\\CLSID\\" + dllCLSID + "\\";

	try
	{		
		oShell.RegDelete(clsidRoot + "ProgId\\Implemented Categories\\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}\\");
		oShell.RegDelete(clsidRoot + "ProgId\\Implemented Categories\\");
		oShell.RegDelete(clsidRoot + "ProgId\\");
		oShell.RegDelete(clsidRoot + "InprocServer32\\1.0.2588.9125\\");
		oShell.RegDelete(clsidRoot + "InprocServer32\\");
		oShell.RegDelete(clsidRoot);
		oShell.RegDelete(classRoot + "CLSID\\");
		oShell.RegDelete(classRoot);
	}
	catch(err) 
	{
	    debugLog("UnregisterSpeedfan: "+err.name+" - "+err.message);
	}
}



// Try to register the DLL
function activeDLL(root) 
{
	regRoot = root;

	try
	{
		RegisterSpeedfan();
		Speedfan = new ActiveXObject("SpeedfanReader.Speedfan");
	}
	catch(err)
	{
		Speedfan = null;
		UnregisterSpeedfan();
		return false;
	}
	return true;
}
