<!--
var runsecs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var secsCookie = 180;
var paused = false;
var savesettings = false;
var playBrewed = false;
var playKettle = false;


// Pick up the cookies if there are any saved.  Note that Boolean values are stored as text - 'true' and 'false'
// so make sure we convert them to proper Booleans
if (document.cookie !=""){
	thisCookie = document.cookie.split("; ");
	
	for (i=0; i<thisCookie.length;i++){
		
		switch(thisCookie[i].split("=")[0]){
			case "secsCookie":
				// A cookie was saved for the required brewing time so set the variable accordingly
				secsCookie = thisCookie[i].split("=")[1];
				// And as we have some cookies they must have requested us to 'save settings' so let's set that
				// flag too
				savesettings = true;				
				break;
			case "playBrewed":
				if(thisCookie[i].split("=")[1]=="true")
					// They want us to play the 'Tea's Brewed' vocal track
					// Note that if it's 'false' we don't do anything as we set the default to false up above
					// in the var declaration
					playBrewed = true;				
				break;
			case "playKettle":
				if(thisCookie[i].split("=")[1]=="true")
					// They want us to play the annoying kettle whistle track.
					// Note that if it's 'false' we don't do anything as we set the default to false up above
					// in the var declaration
					playKettle = true;				
				break;
		}
	}
}


function PlaySound(sound)
{
	try
	{
		sound.DoPlay();
	} 
	catch(e)
		{
			try 
			{
				sound.Play();
			}
			catch (e)
				{
					alert("No sound support but your tea is brewed");
				}
		}		
}

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    // If it's been paused then don't set the runsecs value just leave it as it is
    if(!paused)
    {
    runsecs = window.document.form1.secs.value;
    }
    StopTheClock()
    StartTheTimer()
}

function StopTimer()
{
    StopTheClock();
    runsecs = window.document.form1.secs.value;
    $('timeremaining').innerHTML='Time remaining = ' + runsecs + " (stopped)";  
}

function PauseTimer()
{
	// If it's already paused then un-pause it and start the timer again...
    if(paused)
    {
    	timerRunning = true;
    	timerID = self.setTimeout("StartTheTimer()", delay);
    	$('timeremaining').innerHTML='Time remaining = ' + runsecs;
    	paused = false;
    }
    else
    //If it's not paused then pause it
    {
    	StopTheClock();
    	$('timeremaining').innerHTML='Time remaining = ' + runsecs + " (paused)";
    	paused = true;
    }
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer()
{
    if (runsecs==0)
    {
    		// OK, the clock has run down to zero so...
        StopTheClock();
        
        // If they wanted the 'Tea's brewed' vocal then play it...
                
        if(playBrewed)
        	PlaySound(document.getElementById("brewed"));
        
        // Display the flashing teapot
        $('teapot').innerHTML='<img src="teapot.jpg" alt=""/>';
        Effect.Pulsate('teapot');
        
        // If they wanted the whistling kettle then play it...
        
        if(playKettle)
        	PlaySound(document.getElementById("kettle"));
    }
    else
    {
        self.status = runsecs;
        document.title = runsecs;
     		$('teapot').innerHTML='';
     		$('timeremaining').innerHTML='Time remaining = ' + runsecs;
        runsecs = runsecs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}

function SetSlider()
{

oldSecs = newSecs;
newSecs = window.document.form1.input1.value;
if (oldSecs != 0 && newSecs != 0) {
	s1.setValue(window.document.form1.input1.value);
	oldSecs = newSecs;
	newSecs = window.document.form1.input1.value;
	runsecs = newSecs;
	$('timeremaining').innerHTML='Time remaining = ' + runsecs;
}

// Set the cookie
CheckCheckbox(window.document.form2.savesettings);

}

function Slide(v)
{
v=Math.round(v);
window.document.form1.input1.value = v;
runsecs=v;
$('timeremaining').innerHTML='Time remaining = ' + runsecs;
oldSecs = newSecs;
newSecs = v;
// Set the cookie
CheckCheckbox(window.document.form2.savesettings);

}

function myChange(v)
{
v=Math.round(v);
window.document.form1.input1.value = v;
runsecs=v;
$('timeremaining').innerHTML='Time remaining = ' + runsecs;
oldSecs = newSecs;
newSecs = v;
// Set the cookie
CheckCheckbox(window.document.form2.savesettings);

}

function CheckCheckbox(v)
{
if (v.checked == true )
{
expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+6);
document.cookie = "secsCookie="+window.document.form1.input1.value+";expires="+expireDate.toGMTString();
document.cookie = "playBrewed="+window.document.form1.playBrewed.checked+";expires="+expireDate.toGMTString();
document.cookie = "playKettle="+window.document.form1.playKettle.checked+";expires="+expireDate.toGMTString();
}
else
{
expireDate = new Date;
expireDate.setDate(expireDate.getDate()-1);
document.cookie = "secsCookie=;expires="+expireDate.toGMTString();
document.cookie = "playBrewed=;expires="+expireDate.toGMTString();
document.cookie = "playKettle=;expires="+expireDate.toGMTString();
}

// Set the check box variables
playBrewed = window.document.form1.playBrewed.checked;
playKettle = window.document.form1.playKettle.checked;
}


//-->
