/*
ticker.js
JavaScript programm to slide ticker
creator: Simon Berger | simon.berger@camao.de
date: 2006-10-24
*/

function init() {

  interval = 5000;
  div_height = 100;
  div_count = 0;
  div_max = 4;


  pos_left = 0;
  pos_top = 0;
  var_step = 0;
  var_steps = 24;
  current_pos_left = 0;
  current_pos_top = 0;





  //slide = window.setInterval("slide_to_position_relative('ticker_content', 0, -120)", 2000);
  //slide_to_position_relative('ticker_content', 0, -120);
  div_count++;
  window.setTimeout("slide_to_position_relative('ticker_content', 0, div_height * (-1) * div_count)", interval);
}



function DOMGetElement(o) {
        if (document.getElementById) return document.getElementById(o);
        else if (document.all) return document.all[o];
        else if (document.layers) return document.layers[o];
        return null;
}



slide_to_position_relative = function(id,pos_left_new,pos_top_new,duration) {

  if (var_step == 0) {
    this.id = id;
    var pos_left_new = pos_left_new;
    var pos_top_new = pos_top_new;
    this.distance_x = pos_left_new - pos_left;
    this.distance_y = pos_top_new - pos_top;

    var_step_counter = 0;
    movingElement = window.setInterval("move_relative(this.id, this.distance_x, this.distance_y)", 40);

  }
}


move_relative = function(id, distance_x, distance_y) {

  this.id = id
    $M_PI  = 3.1415;

      var_step_counter = var_step_counter+var_step;
      current_pos_left = pos_left + (Math.sin((var_step/var_steps + 3/2) * $M_PI)+1) * distance_x/2;
      current_pos_top = pos_top + (Math.sin((var_step/var_steps + 3/2) * $M_PI)+1) * distance_y/2;


    var_step++;
    if (var_step > var_steps) {
      pos_left = pos_left + distance_x;
      pos_top = pos_top + distance_y;
      window.clearInterval(movingElement);
      var_step = 0;

      div_count++;
      if (div_count > div_max) {
        div_count = div_max * (-1);

      }

      window.setTimeout("slide_to_position_relative('ticker_content', 0, div_height * (-1) * div_count)", interval);

      if (div_count == div_max * (-1)) {
        div_count = 0;
      }


    }
    set_position_relative(this.id,current_pos_left,current_pos_top);
}

set_position_relative = function(id,pos_left,pos_top) {


  DOMGetElement(id).style.margin = Math.round(pos_top) + 'px 0 0 ' + Math.round(pos_left) + 'px' ;
  //DOMGetElement(id).style.margin-top = Math.round(pos_top) + 'px';
}
