var ads_total_height=500;
var ads_speed=50;
var ads_hover_speed=10;
var ads_current_offset=0;
var ads_scroll_step = 1;
var ads_scroll_step_saved = 1;
var ads_hover_scroll_step = 2;
var ads_direction_change_delay = 3000;
var ads_init_delay = 2000;
var ads_timeout_id;

function stop_scrolling()
{
  ads_scroll_step_saved = ads_scroll_step;
  ads_scroll_step = 0;
}

function resume_scrolling()
{
  ads_scroll_step = ads_scroll_step_saved;
}

function init_ads()
{
  ads_timeout_id = setTimeout("scroll_ads_up()", ads_init_delay);
}

function scroll_ads_up()
{
  document.getElementById("scrollingads").style.top = ads_current_offset + "px";
  if(Math.abs(ads_current_offset) >= ads_total_height)
    {
      ads_timeout_id = setTimeout("scroll_ads_down()", ads_direction_change_delay);
      return;
    }
  ads_current_offset -= ads_scroll_step;
  ads_timeout_id = setTimeout("scroll_ads_up()", ads_speed);
}

function scroll_ads_down()
{
  document.getElementById("scrollingads").style.top = ads_current_offset + "px";
  if(ads_current_offset >= 0)
    {
      ads_timeout_id = setTimeout("scroll_ads_up()", ads_direction_change_delay);
      return;
    }
  ads_current_offset += ads_scroll_step;
  ads_timeout_id = setTimeout("scroll_ads_down()", ads_speed);
}


function start_scrolling_up()
{
  clearTimeout(ads_timeout_id);
  ads_interval_id = setInterval("hover_scroll_up()", ads_hover_speed);
}

function stop_scrolling_up()
{
  clearInterval(ads_interval_id);
  ads_timeout_id = setTimeout("scroll_ads_up()", ads_init_delay);
}

function hover_scroll_up()
{
  document.getElementById("scrollingads").style.top = ads_current_offset + "px";
  if(Math.abs(ads_current_offset) >= ads_total_height)
    {
      clearInterval(ads_interval_id);
      return;
    }
  ads_current_offset -= ads_hover_scroll_step;
}

function start_scrolling_down()
{
  clearTimeout(ads_timeout_id);
  ads_interval_id = setInterval("hover_scroll_down()", ads_hover_speed);
}

function stop_scrolling_down()
{
  clearInterval(ads_interval_id);
  ads_timeout_id = setTimeout("scroll_ads_down()", ads_init_delay);
}

function hover_scroll_down()
{
  document.getElementById("scrollingads").style.top = ads_current_offset + "px";
  if(ads_current_offset >= 0)
    {
      clearInterval(ads_interval_id);
      return;
    }
  ads_current_offset += ads_hover_scroll_step;
}
