<!--
/*
Scroll.links = [
  {
    innerHTML: 'www',
    href: 'http://www.rueylung.com.tw',
    description: 'www site of Ruey Lung Rubber Co., Ltd.'
  },
  {
    innerHTML: 'bookmark',
    href: 'http://bookmark.rueylung.com.tw',
    description: 'bookmark collection.'
  },
  {
    innerHTML: 'phonebook',
    href: 'http://phonebook.rueylung.com.tw',
    description: 'phonebook'
  },
  {
    innerHTML: 'bogus',
    href: 'https://bogus.rueylung.com.tw',
    description: 'R.L. bogus site.'
  }
]
*/

var Scroll = {
  anime: null,
  links: [],
  link_counter: 0,
  loop_count: 0,
  should_stop: false,
  scrolling: false,
  offset: 0,
  increment: 2,
  frame_delay: 50,
  banner_delay: 5000,

  start: function() { Scroll.init(); },
  
  init: function() {
    Scroll.anime = document.getElementById('anime');
    Scroll.anime.onmouseover = function() { Scroll.should_stop = true; }
    Scroll.anime.onmouseout = function() { Scroll.should_stop = false; }
    
    var s = Scroll.anime.style;
    s.display  = 'none';
    s.position = 'relative';
    s.width    = '150px';
    s.height   = '30px';
    //s.border = '1px solid silver';
    s.overflow = 'hidden';
  
    var lis = Scroll.anime.getElementsByTagName('li');
    
    for (var i = 0, len = lis.length; i < len; ++i) {
      var a = lis[i].firstChild;
      var o = { innerHTML:   a.innerHTML,
                href:        a.href,
                description: a.title }
      Scroll.links[i] = o;
    }
    
    var o;
    while (o = Scroll.anime.firstChild) Scroll.anime.removeChild(o);
    
    Scroll.a1 = document.createElement('div');
    Scroll.a2 = document.createElement('div');
    
    Scroll.anime.appendChild(Scroll.a1);
    Scroll.anime.appendChild(Scroll.a2);
    
    var styles = {
      //'border'  : '1px solid silver',
      'fontSize'  : '20px',
      'height'    : Scroll.anime.style.height,
      'position'  : 'absolute',
      'overflow'  : 'hidden'
    }
  
    for (var x in styles) {
      Scroll.a1.style[x] = styles[x];
      Scroll.a2.style[x] = styles[x];
    }
    
    Scroll.anime_bound = parseInt(Scroll.anime.style.height);
    
    Scroll.middle = Math.round((Scroll.anime_bound - parseInt(Scroll.a1.style.fontSize) + 1) / 2) - 2;
    if (Scroll.middle < 0) Scroll.middle = 0;
    
    Scroll.anime.parentNode.style.display = 'block';
    s.display = 'block';
    
    Scroll.s_play();
    window.setInterval(Scroll.s_play, Scroll.banner_delay);
  },

  do_scroll: function() {
    var o1, o2;
    if (Scroll.loop_count == 0) {
      o1 = Scroll.a1;
      o2 = Scroll.a2;
    } else {
      o1 = Scroll.a2;
      o2 = Scroll.a1;
    }
  
    o1.style.top = Scroll.offset + Scroll.middle + 'px';
    o2.style.top = Scroll.offset + Scroll.middle + Number(Scroll.anime_bound) + 'px';
    //document.getElementById('msg').innerHTML = o2.style.top;
  
    // acceleration
    if ((Scroll.offset + Scroll.anime_bound) > (Scroll.increment * 5));
      Scroll.offset -= Scroll.increment;
  
    Scroll.offset -= Scroll.increment;
    
    o1.style.display = '';
    o2.style.display = '';
    
    if (Scroll.offset >= -Scroll.anime_bound) return;
    
    o1.style.display = 'none';
    
    Scroll.offset = parseInt(o2.style.top) - Scroll.middle;
    //document.getElementById('msg').innerHTML = Scroll.offset;
    
    clearInterval(Scroll.animation_interval);
    Scroll.scrolling = false;
  },

  display_anime_msg: function() {
    Scroll.should_stop = true;
    var description = Scroll.links[this.idx].description;
    if (description) {
      var o = document.createElement('div');
      o.setAttribute("style", "margin-top:-5px;margin-left:20px;white-space:normal;position:absolute;background-color:#feffa1;padding:5px;border:1px solid silver;");
      //o.innerHTML = description;
      o.appendChild(document.createTextNode(description));
      Scroll.anime.parentNode.insertBefore(o, Scroll.anime.nextSibling);
    }
  },

  set_link: function() {
    var link = Scroll.links[Scroll.link_counter];
    var innerHTML = link.innerHTML;
    var href = link.href;
  
    var a = document.createElement('a');
    a.setAttribute("href", href);
    a.onclick = function() { this.blur(); }
    a.idx = Scroll.link_counter;
    a.onmouseover = Scroll.display_anime_msg;
    a.onmouseout = function() { var o; if (o = Scroll.anime.nextSibling) Scroll.anime.parentNode.removeChild(o); }
    a.innerHTML = innerHTML;
    
    var sa = Scroll.loop_count == 0 ? Scroll.a1 : Scroll.a2;
      
    if (sa.hasChildNodes()) {
      sa.replaceChild(a, sa.firstChild);
    } else {
      sa.appendChild(a);
    }
    
    Scroll.link_counter++;
    if (Scroll.link_counter == Scroll.links.length) Scroll.link_counter = 0;
    Scroll.loop_count++;
    if (Scroll.loop_count == 2) Scroll.loop_count = 0;
  },

  s_play: function() {
    if (Scroll.should_stop || Scroll.scrolling) return;
    Scroll.set_link();
    Scroll.scrolling = true;
    Scroll.animation_interval = window.setInterval(Scroll.do_scroll, Scroll.frame_delay);
  }

}

Scroll.start();

//-->
