Dear all,

This is my first post on the forums. I would like some help with Javascript. At first let me say that i have 0 knowledge in javascript and i try to write some code to make my website scroll using the iPhone's accelerometer. After a lot of hours of reading and trying and testing i managed to write the following code that works:

Code:
<script type="text/javascript">
var Enabled=true;
function Run()
{
if(Enabled == true)
{
alert("Accelerometer Scrolling Enabled");
window.ondevicemotion=function Scrolacc() {
ay = event.accelerationIncludingGravity.y*10;
window.scrollBy(0,ay).accelerationIncludingGravity.y;
}
}else
{
alert("Acceleration Scrolling Disabled");
window.ondevicemotion=function Scrolacc() {
ay = event.accelerationIncludingGravity.y*10;
window.scrollBy(0,0).accelerationIncludingGravity.y;}
scrolldelay = setTimeout('Scrolacc()',100); // scrolls every 100 milliseconds
}
}
function stopScroll() {
         clearTimeout(scrolldelay);
}
</script>
I place the above code on my overall_header.html within the <head></head> tags. The script does not work on load so i need 2 buttons so that the users can enable or disable the script. In my Header i have placed the following code to add the buttons:

Code:
<center>
Use the buttons to enable/disable accelerometer scrolling
<button onclick="Enabled=true;Run()">Enable</button>
<button onclick="Enabled=false;Run();stopScroll();">Disable</button></center>
The problem is that like this the browser cannot remember the users choice, resulting that on every page of the forum the user needs to activate again the script. A cookie needs to be set to save the settings.

Since my knowledge in javascript is maybe 0.01%, can someone please modify the code and post it back? Also please correct the errors if the code contains any.

Thank you very much in advance.