
var CurrentTip = 0;

function LoadSettings() 
{
    HotKeyModifer1.options[0] = new Option(Localized['Modifer8'], 8);
    HotKeyModifer1.options[1] = new Option(Localized['Modifer2'], 2);
    HotKeyModifer1.options[2] = new Option(Localized['Modifer4'], 4);
    HotKeyModifer1.options[3] = new Option(Localized['Modifer9'], 9);
    HotKeyModifer1.options[4] = new Option(Localized['Modifer3'], 3);
    HotKeyModifer1.options[5] = new Option(Localized['Modifer10'], 10);

    HotKeyModifer2.options[0] = new Option(Localized['Modifer8'], 8);
    HotKeyModifer2.options[1] = new Option(Localized['Modifer2'], 2);
    HotKeyModifer2.options[2] = new Option(Localized['Modifer4'], 4);
    HotKeyModifer2.options[3] = new Option(Localized['Modifer9'], 9);
    HotKeyModifer2.options[4] = new Option(Localized['Modifer3'], 3);
    HotKeyModifer2.options[5] = new Option(Localized['Modifer10'], 10);

    FixedVisibleContents.options[0] = new Option(Localized['Many'], 0);
    FixedVisibleContents.options[1] = new Option(Localized['Less'], 1);
    FixedVisibleContents.options[2] = new Option(Localized['Max1'], 2);
    FixedVisibleContents.options[3] = new Option(Localized['Max2'], 3);

    TipText.innerHTML = Localized['Tip_'+(CurrentTip+1)];
    currentIndex.innerHTML = "" + (CurrentTip+1) + Localized['TipOf'] + Localized['NumTips'];
    
    HotKeyText.innerHTML = Localized['HotKeyText'];
    HotKeyText1.innerHTML = Localized['HotKeyText1'];
    HotKeyText2.innerHTML = Localized['HotKeyText2'];
    MaxContentsText.innerHTML = Localized['MaxContentsText'];
    FixedVisibleContentsText.innerHTML = Localized['FixedVisibleContentsText'];
    UseGlassText.innerHTML = Localized['UseGlassText'];
    //UseAnimationText.innerHTML = Localized['UseAnimationText'];
    //SaveToHarddriveText.innerHTML = Localized['SaveToHarddriveText'];
    //IsDragFieldText.innerHTML = Localized['IsDragFieldText'];
    Website.innerHTML = Localized['Website'];
    Website.href = Localized['WebsiteUrl'];
    Feedback.innerHTML = Localized['Feedback'];
    Feedback.href = Localized['FeedbackUrl'];

    // Load settings
    HotKeyModifer1.value = System.Gadget.Settings.read("HotKeyModifer1");
    HotKeyModifer2.value = System.Gadget.Settings.read("HotKeyModifer2");
    HotKey1.value = System.Gadget.Settings.read("HotKey1");
    if(HotKey1.value == "@")
        HotKey1.value = "";
    HotKey2.value = System.Gadget.Settings.read("HotKey2");
    if(HotKey2.value == "@")
        HotKey2.value = "";
    MaxContents.value = System.Gadget.Settings.read("MaxContents");
    FixedVisibleContents.value = System.Gadget.Settings.read("FixedVisibleContents");
	UseGlass.checked = System.Gadget.Settings.read("UseGlass") == "1";
	
    System.Gadget.onSettingsClosing = SettingsClosing;
}

function SettingsClosing(event)
{
    // Save the settings if the user clicked OK
	if(event.closeAction == event.Action.commit) 
	{
	    if(HotKey1.value == "")
	        HotKey1.value = "@";
	    if(HotKey2.value == "")
	        HotKey2.value = "@";
		System.Gadget.Settings.write("HotKeyModifer1", HotKeyModifer1.value);
		System.Gadget.Settings.write("HotKeyModifer2", HotKeyModifer2.value);
		System.Gadget.Settings.write("HotKey1", HotKey1.value.toUpperCase());
		System.Gadget.Settings.write("HotKey2", HotKey2.value.toUpperCase());
		System.Gadget.Settings.write("MaxContents", MaxContents.value);
		System.Gadget.Settings.write("FixedVisibleContents", FixedVisibleContents.value);
		System.Gadget.Settings.write("UseGlass", UseGlass.checked ? "1" : "0");
		System.Gadget.Settings.write("SettingsWritten", "1");
	}
	event.cancel = false;
}

function TipsBack()
{
    if ((event.keyCode && event.keyCode != 32) || (event.button == 2))
    {
        return false;
    }
    if(CurrentTip == 0)
        CurrentTip = parseInt(Localized['NumTips'])-1;
    else
        CurrentTip--;
    TipText.innerHTML = Localized['Tip_'+(CurrentTip+1)];
    currentIndex.innerHTML = "" + (CurrentTip+1) + Localized['TipOf'] + Localized['NumTips'];
}

function TipsForward()
{
    if ((event.keyCode && event.keyCode != 32) || (event.button == 2))
    {
        return false;
    }
    if(CurrentTip == parseInt(Localized['NumTips'])-1)
        CurrentTip = 0;
    else
        CurrentTip++;
    TipText.innerHTML = Localized['Tip_'+(CurrentTip+1)];
    currentIndex.innerHTML = "" + (CurrentTip+1) + Localized['TipOf'] + Localized['NumTips'];
}

function swapImage(img, state)
{
    img.src = "images/settings_" + img.src.split("_")[1] + "_" + state + ".png";
}
