 /*
   TextScroller 1.1i <improved>
   Licence: GNU/GPL
   Link http://www.davidonzo.com/post/798/javascript-text-scroller-10/
 */

  var orientamento = 'DT'; //TD = TopDown; DT = DonwTop; LR = LeftRight; RL = RightLeft
  var parent = 'mission'; //The ID containing the scrolling text
  var duration = 50; //The scroll speed. Smaller means faster
  var h = '220'; //Height of the id (assume it as pixel only value)
  var w = '225'; //Width of the id (assume it as pixel only value)

function letsGo(){
  initScroll();
}

function initScroll(){
  creatediv();
  DIV = document.getElementById('child'+parent);
  par = document.getElementById(parent);
  PaddAndOver();
  switch(orientamento){
    case 'RL':
      topo = par.offsetWidth;
    break;
    case 'LR':
      topo = -left;
    break;
    
    case 'TD':
      topo = -19-DIV.offsetHeight;
    break;

    case 'DT':
     topo = 0;
    break;
  }
  
  x = setInterval("scroll()",duration);
  DIV.onmouseover = function scroll(){
       clearInterval(x);
  }

  DIV.onmouseout = function scroll(){
    x = setInterval("scroll()",duration);
  }
}

function scroll(){
  DIV = document.getElementById('child-'+parent);
  par = document.getElementById(parent);
  switch(orientamento){
   case 'RL':
   case 'LR':
    altezza = DIV.offsetWidth;
    DIV.style.marginLeft = topo+'px';

    switch(orientamento){
      case 'RL':
       topo--;
       if(left < w){
         if(topo == -left-1){
           topo = w;
         }
       }else{
        if(Math.abs(topo) > left){
         topo = w;
        }
       }
      break;

      case 'LR':
       topo++;
       larg = par.offsetWidth;
       if(topo > larg){
         par = document.getElementById(parent);
         topo = -left;
       }
      break;
    }
   break;

   case 'DT':
   case 'TD':
    altezza = DIV.offsetHeight;
    DIV.style.marginTop = topo+'px';

    switch(orientamento){
      case 'DT':
       topo--;
       if(Math.abs(topo) > altezza){
         topo = 0;
       }
      break;
      
      case 'TD':
       topo++;
       retop = DIV.offsetTop;
       altic = par.offsetHeight;
       if(topo > altic){
       topo = -19-DIV.offsetHeight;
       }
      break;
    }

    break;
  }
}

function creatediv(){
   par = document.getElementById(parent);
   text = par.innerHTML
   par.innerHTML = '';
   newdiv = document.createElement("div");
   newdiv.setAttribute('id','child-'+parent);
   par.appendChild(newdiv);
   newdiv.innerHTML = text;
}

function PaddAndOver(){
  DIV = document.getElementById('child-'+parent);
  par = document.getElementById(parent);
  alt = par.offsetWidth;
  elt = par.offsetHeight;
  olt = DIV.offsetHeight;

   switch(orientamento){
    case 'RL':
      DIV.style.position = 'absolute';
      left = DIV.offsetWidth;
      DIV.style.whiteSpace = 'nowrap';
      par.style.position = 'relative';
      DIV.style.position = 'relative';
      DIV.style.marginLeft = w+'px';
    break;
    
    case 'LR':
      DIV.style.position = 'absolute';
      left = DIV.offsetWidth;
      DIV.style.whiteSpace = 'nowrap';
      par.style.position = 'relative';
      DIV.style.position = 'relative';
      DIV.style.marginLeft = -(left)+'px';
    break;
    
    case 'DT':
      DIV.style.paddingTop = h+'px';
    break;
    
    case 'TD':
      DIV.style.marginTop = -200-DIV.offsetHeight+'px';
    break;
   }

   par.style.overflow = 'hidden';
   par.style.height = h+'px';
   par.style.width = w+'px';
}

