/*
Programmer: Pedro S. aka VoR
www.cybernerdz.net
VoR's Scene Scroller v1.0 horizontal
*/

onload = init;
var loop = false;
var loaded = false;
var undefined;
var timer;

// var for Scrolling Layers
var sc2;

function init(){
	     
   sc2 = new LayerObject('hSceneSc','hSceneSp','',3);
   sc2.makelink(770,100);
   sc2.sceneX[0] = 0;
   sc2.sceneX[1] = -770;
   sc2.sceneX[2] = -1540;
   sc2.sceneX[3] = -2310;
   sc2.sceneX[4] = -3080;
   sc2.sceneX[5] = -3850;
   sc2.sceneX[6] = -4620;
   sc2.sceneX[7] = -5390;
   sc2.sceneX[8] = -6160;
   
   
                
	  loaded = true;
}// end scrollInit()

// CREATE OBJECT HERE =====================================================================>
ie4 = (document.all && !document.getElementById)?1:0;
ie5 = (document.all && document.getElementById)?1:0;
net4 = (!document.all && !document.getElementById)?1:0;
net6 = (!document.all && document.getElementById)?1:0;

function LayerObject(layerN,parentN,gParent,type){ // -- Main Function         
    parentx = (parentN)? "document." + parentN + ".document." + layerN : "document." + layerN; //Parent
    parentx = (gParent)? "document." + gParent + "." + parentx : parentx; //Scrolling Plane
         
      // Get References    
    if(ie4){ // IE4
      this.ref = document.all[layerN]; 
      this.css = document.all[layerN].style;   
    }else{   // Net4 then Net6 + IE5
      this.ref = (net4)? eval(parentx) : document.getElementById(layerN); 
      this.css = (net4)? eval(parentx) : document.getElementById(layerN).style;   
    }// end if
    
    this.height = (net4)? this.css.clip.height: this.ref.offsetHeight;
    this.width = (net4)? this.css.clip.width: this.ref.offsetWidth;
   
    this.x=(net4)? this.css.left: this.ref.offsetLeft;
    this.y=(net4)? this.css.top: this.ref.offsetTop;		
           
      // Reference to Itself
    this.obj = layerN + "Object"
    eval(this.obj + "=this")
       
     // Object Methods
    this.move = f_move;

    // BUILD SCROLLER TYPE METHODS   
    if(type == 1){ // VERTICAL TEXT SCROLLER
        // Vars
      this.lspeed = 10;
        // Methods
      this.up = f_up;
      this.down = f_down;
      this.vscroll = f_vscroll;
      this.noScroll = f_noScroll;     
      
       //--------------------------------------------------------------      
    }else if(type == 2){ //HORIZONTAL TEXT SCROLLER
        // Vars
      this.lspeed = 10;
        // Methods
      this.left = f_left;
      this.right = f_right;
      this.hscroll = f_hscroll;        
      this.noScroll = f_noScroll;   
      
       //--------------------------------------------------------------      
    }else if(type == 3){ // HORIZONTAL SCENE SCOLLER
        // Vars
      this.sceneX = new Array(); //Hold X Values
      this.nlink = 0;            //Link for Total Distance to Max Traveling Distance
      this.busyL = 0;            // Are We Going Left
      this.busyR = 0;            // Are We Going Right
      this.lspeed = 20;          //Loop Speed
      this.cScene = 0;           //current Scene
        // Methods
      this.makelink = f_makeLink;
      this.hgotoScene = f_hgotoScene;
      this.goLeft = f_goLeft;
      this.goRight = f_goRight;
      
       //--------------------------------------------------------------      
    }else if(type == 4){ // VERTICAL SCENE SCROLLER
        // Vars
      this.sceneY = new Array(); //Hold X Values
      this.nlink = 0;            //Link for Total Distance to Max Traveling Distance
      this.busyU = 0;            // Are We Going Up
      this.busyD = 0;            // Are We Going Down
      this.lspeed = 20;          //Loop Speed
      this.cScene = 0;           //current Scene
        // Methods
      this.makelink = f_makeLink;
      this.vgotoScene = f_vgotoScene;
      this.goUp = f_goUp;
      this.goDown = f_goDown;
    
    }//END IF

      //Create Parent
    if(parentN) this.p = new LayerObject(parentN,"",gParent); 

      //Move the Child to Corner.
    if(parentN) this.move(0,0);

    return this;
}// end BuildLayer 

// DEFAULT OBJECT METHODS --------------------------------------------------------------------------------------
function f_move(x,y){
  this.x = x; this.css.left = this.x;
  this.y = y; this.css.top = this.y;
}// end f_move

// DEFAULT TEXT SCROLLER METHODS -------------------------------------------------------------------------------
function f_noScroll(){
   Loop=false;
   if(timer) clearTimeout(timer);
}// end NoScroll

// VERTICAL TEXT SCROLLER METHODS -------------------------------------------------------------------------------

function f_vscroll(travel){ // Directs Up or Down Direction
  if(loaded){
  
	    loop=true; // Yes Loop     
		   if(travel > 0 ) this.down(travel);
		   else this.up(travel);
     
	 }// end if 
}// end scroll  

function f_up(travel){ //Move Layer Up
  if(this.y < 0){  
   
    travel = (this.y-travel > 0)? -1: travel; // SlowDown at end
    this.move(0,this.y - travel); // take away from Top Value
    if(loop) timer = setTimeout(this.obj + ".up(" + travel + ")",this.lspeed);  //Loop again
    
  }// end if
}// end f_up

function f_down(travel){ //Move Layer Down
  if(this.y > (this.p.height - this.height)){
  
    travel = (this.y-travel < (this.p.height - this.height))? 1: travel; // SlowDown at end  
    this.move(0,this.y - travel); // take away from top value
    if(loop) timer = setTimeout(this.obj + ".down(" + travel + ")",this.lspeed); //loop again
    
  }//end if
}// end f_down

// HORIZONTAL TEXT SCROLLER METHODS -------------------------------------------------------------------------------

function f_hscroll(travel){
  if(loaded){

	    loop=true; // Yes Loop
		   if(travel > 0 ) this.right(travel);
		   else this.left(travel);
     
	 }// end if 
}// end scroll  

function f_left(travel){ //Move Layer to the left
  if(this.x < 0){  
  
    travel = (this.x-travel > 0)? -1: travel; // SlowDown at end
    this.move(this.x - travel,0); // take away from Top Value
    if(loop) timer = setTimeout(this.obj + ".left(" + travel + ")",this.lspeed);  //Look again
    
  }// end if
}// end f_up

function f_right(travel){ //Moves Layer to the Right
  if(this.x > (this.p.width - this.width)){
  
    travel = (this.x-travel < (this.p.width - this.width))? 1: travel; // SlowDown at end
    this.move(this.x - travel,0); // take away from top value
    if(loop) timer = setTimeout(this.obj + ".right(" + travel + ")",this.lspeed); //loop again
    
  }//end if
}// end f_down

// HORIZONTAL SCENE SCROLLER METHODS ------------------------------------------------------------------------------

function f_makeLink(tDistance,tTravel){
   this.nlink = Math.floor(tDistance/tTravel);
}// end

function f_hgotoScene(num){ //Direct Scene Moving Direction

   if(!this.busyR && !this.busyL){ // Don't Change Busy
      this.cScene = num;   
      if(this.sceneX[num] < this.x){ // if it's on the left side
         this.busyL = 1; //Moving LEFT Now
         this.goLeft();
      }else{
         this.busyR = 1; //Moving Right Now
         this.goRight();
      }// end if
   }// end if
   
}// end gotoScene

function f_goLeft(){
   if(this.x > this.sceneX[this.cScene]){   

     c = (this.sceneX[this.cScene] * -1) - (this.x * -1); // Location to - Current Location
     t = Math.floor(c/this.nlink);   //Difference / nlink
     if(t <= 0) t = 1;    
     
     this.move(this.x-t,0);
     setTimeout(this.obj + ".goLeft()",this.lspeed);
          
   }else{
     this.busyL = 0;    
   }// end if
}// end goLeft

function f_goRight(){
   if(this.x < this.sceneX[this.cScene]){   

     c = (this.x * -1) - (this.sceneX[this.cScene] * -1); // Location to - Current Location
     t = Math.floor(c/this.nlink);   //Difference / nlink
     if(t <= 0) t = 1;     
     
     this.move(this.x+t,0);
     setTimeout(this.obj + ".goRight()",this.lspeed);
          
   }else{
     this.busyR = 0;    
   }// end if
}// end goRight

// VERTICAL SCENE SCROLLER METHODS ------------------------------------------------------------------------------

function f_vgotoScene(num){ //Direct Scene Moving Direction

   if(!this.busyD && !this.busyU){ // Don't Change Busy
      this.cScene = num;   
      if(this.sceneY[num] < this.y){ // if it's on the left side
         this.busyU = 1; //Moving LEFT Now
         this.goUp();
      }else{
         this.busyD = 1; //Moving Right Now
         this.goDown();
      }// end if
   }// end if
   
}// end gotoScene

function f_goUp(){
   if(this.y > this.sceneY[this.cScene]){   

     c = (this.sceneY[this.cScene] * -1) - (this.y * -1); // Location to - Current Location
     t = Math.floor(c/this.nlink);   //Difference / nlink
     if(t <= 0) t = 1;    
     
     this.move(0,this.y-t);
     setTimeout(this.obj + ".goUp()",this.lspeed);
          
   }else{
     this.busyU = 0;    
   }// end if
}// end goLeft

function f_goDown(){
   if(this.y < this.sceneY[this.cScene]){   

     c = (this.y * -1) - (this.sceneY[this.cScene] * -1); // Location to - Current Location
     t = Math.floor(c/this.nlink);   //Difference / nlink
     if(t <= 0) t = 1;     
     
     this.move(0,this.y+t);
     setTimeout(this.obj + ".goDown()",this.lspeed);
          
   }else{
     this.busyD = 0;    
   }// end if
}// end goRight

// END OF OBJECTS --------------------------------------------------------->


