var timer=null;
var timerstop=false;
var next;
var dir=1;
var myiframe="";


function toggle(){

if (document.getElementById("scrollframe")){
myiframe=document.getElementById("scrollframe");
}

if (timerstop){
timerstop=false;  
scrollOn(next);
}

else {
timerstop=true;
}

}


function dirswitch(){

if (dir==0){

if(timerstop){
timerstop=false;
scrollOn(next);
} 

dir=1;
}

else if (dir==1){

if(timerstop){
timerstop=false;
scrollOn(next);
}

dir=0;
}

}


function scrollOn(scrollPos){

if (timer){
clearTimeout(timer);
}

if (parent.dir==1){
next=scrollPos+1;
}

else if (parent.dir==0){
next=scrollPos-1;
}

if (document.getElementById("scrollframe")){
myiframe=document.getElementById("scrollframe");
}


if (myiframe.contentWindow.document.getElementById("scrolltable")){
var mytable=myiframe.contentWindow.document.getElementById("scrolltable");
}

var fwidth=mytable.offsetWidth;

if (next>(fwidth-935)){
//e.g. iframe width
next=0;
}

if (next<0){
next=0;
dir=1;
}

timer=setTimeout("if(!timerstop){myiframe.contentWindow.scrollTo("+scrollPos+", 0);  scrollOn("+next+");}", 50);
}


