function autoPlay(nextURL, timeout, autoplay){
  var t;
  if(autoplay == 'on') {
    t = doTimer(nextURL, t, timeout, autoplay);
  }
  else {
    t = stopCount(t);
  }
  return t;
}
  
function doTimer(nexturl, t, timeout, state) {
  var state = (state == "") ? "on" : state;
  var timeout = (timeout == "") ? "10000" : timeout;
  url = nexturl;
  t = setTimeout("window.location=url;", timeout);
  if (state == 'on') {
    isPlaying(timeout);
  }
  else {
    stopCount(t);
  }
  return t;
}

function stopCount(t){
  try{
    clearTimeout(t);
  }
  catch(err){
    window.alert("stopCount error:"+err.message);
  }
  isPaused();
  return t;
}

function isPlaying(timeout) {
  try{
    jQuery('#btn_play').hide();
    jQuery('#btn_pause').show();
    jQuery('#txt_controls').show();
    if (timeout == "10000") {
      jQuery('#txt_slow').css("color","silver");
      jQuery('#txt_medium').css("color","silver");
      jQuery('#txt_fast').css("color","black");
    } else if (timeout == "20000") {
      jQuery('#txt_slow').css("color","silver");
      jQuery('#txt_medium').css("color","black");
      jQuery('#txt_fast').css("color","silver");
    } else if (timeout == "40000") {
      jQuery('#txt_slow').css("color","black");
      jQuery('#txt_medium').css("color","silver");
      jQuery('#txt_fast').css("color","silver");
    }
  }
  catch(err){
    window.alert("isPlaying error:"+err.message);
  }
}

function isPaused() {
  try{
    jQuery('#btn_play').show();
    jQuery('#btn_pause').hide();
    jQuery('#txt_controls').hide();
  }
  catch(err){
    window.alert("isPaused error:"+err.message);
  }
}
