/***********************************************
* Floating image script- By Virtual_Max (http://www.geocities.com/siliconvalley/lakes/8620)
* Modified by Dynamic Drive for various improvements
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/


var vmin=2;	// slowest movement in a single frame
var vmax=2;	// fastest movement in a single frame
var vr=1;	// amount to vary the movement per frame
var timer1;
var dir = 'R';
var imgsrc = '/images/nodes_anim_r.gif';

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function Chip(chipname,width,height){
 this.named=chipname;
 this.vx=vmin+vmax*Math.random();
 //this.vy=vmin+vmax*Math.random();
 this.w=width;
 this.h=height;
 this.yy=0;
 this.timer1=null;
 if ((Math.random()*2)<1)
	{
		this.dir='L';
		this.xx=window.pageXOffset+window.innerWidth-400;
		this.imgsrc = '/images/nodes_anim.gif';
	}
	else
	{
		this.dir='R';
		this.xx=0;
		this.imgsrc = '/images/nodes_anim_r.gif';
 	}
}

function movechip(chipname)
{
	if (document.getElementById)
	{
		eval("chip="+chipname);
	   if (window.innerWidth || window.opera)
	   {
		 pageX=window.pageXOffset;
		 pageW=window.innerWidth;
		 pageY=window.pageYOffset;
		 pageH=window.innerHeight;
		}
	   else if (document.body){
		 pageX=iecompattest().scrollLeft;
		 pageW=iecompattest().offsetWidth;
		 pageY=iecompattest().scrollTop;
		 pageH=iecompattest().offsetHeight;
		} 
	
		// he is moving left or right - chance of sitting down
	    if ( (chip.dir == 'L' || chip.dir == 'R') && chip.named!='flyimage2')
	    {
			if ((Math.random()*100)<1)
			{
				// yes he will sit down
				if (chip.dir == 'L')
				{
					if (chip.named=='flyimage1')
					{
						document.getElementById(chip.named+'a').src='/images/nodes_satdown_l.GIF';
					}
					else if (chip.named=='flyimage3')
					{
						document.getElementById(chip.named+'a').src='/images/knight_lore_sat_l.gif';
					}
					else if (chip.named=='flyimage4')
					{
						document.getElementById(chip.named+'a').src='/images/skateordie45L.GIF';
					}
				}
				else
				{
					if (chip.named=='flyimage1')
					{
						document.getElementById(chip.named+'a').src='/images/nodes_satdown.GIF';
					}
					else if (chip.named=='flyimage3')
					{
						document.getElementById(chip.named+'a').src='/images/knight_lore_sat_r.gif';
					}
					else if (chip.named=='flyimage4')
					{
						document.getElementById(chip.named+'a').src='/images/skateordie45R.GIF';
					}
				}
				
				if (chip.named!='flyimage4') { chip.dir='SIT'; }
			}
	   }
	   else
	   {
		   // he is already sitting down or falling
		   if (chip.dir != 'D' && chip.dir != 'U')
		   {
			   // he is sitting down
			   if ( (Math.random()*30)<1 )
			   {
					// choose a random new direction
					if ((Math.random()*2)<1)
					{
						chip.dir='L';
						if (chip.named=='flyimage1')
						{
							document.getElementById(chip.named+'a').src='/images/nodes_anim.gif';
						}
						else if (chip.named=='flyimage3')
						{
							document.getElementById(chip.named+'a').src='/images/knight_lore.gif';	
						}
						else if (chip.named=='flyimage4')
						{
							document.getElementById(chip.named+'a').src='/images/skateordie45L.GIF';	
						}
					}
					else
					{
						chip.dir='R';
						if (chip.named=='flyimage1')
						{
							document.getElementById(chip.named+'a').src='/images/nodes_anim_r.gif';
						}
						else if (chip.named=='flyimage3')
						{
							document.getElementById(chip.named+'a').src='/images/knight_lore_r.gif';	
						}
						else if (chip.named=='flyimage4')
						{
							document.getElementById(chip.named+'a').src='/images/skateordie45R.GIF';	
						}
					}
				}
		   }
		   else
		   {
				// he is falling down - stop him
				if (chip.yy >= 129)
				{
					chip.dir='SIT';	
				}
				else if (chip.dir == 'U' && chip.yy <= -100)
				{
					chip.dir='SIT';	
					chip.yy=-100;
				}
				else
				{
					if (chip.named=='flyimage1')
					{
						document.getElementById(chip.named+'a').src='/images/nodes_fall_l.gif';
					}
				}
			} 
	   }
	   
	   if (chip.named=='flyimage2')
	   {
			if (chip.yy != 50) 
			{ 
				chip.yy = 50; 
				document.getElementById(chip.named+'a').src='/images/shooting-stars-r.gif';
			};
	   }

		// for flyimage1, what's the chance of falling?
	    if (chip.yy < 129 && (chip.named=='flyimage1') && chip.dir != 'U')
	    {
			if ((Math.random()*500)<1)
			{
				chip.dir='D';   
			}
	    }
									 
	   // move the character !
	   if (chip.dir=='L')
	   {
			if (chip.named=='flyimage4') 
			{ chip.xx-=4; } 
			else if (chip.named=='flyimage2')
			{ chip.xx-=2; }
			else 
			{ chip.xx-=2; }
	   }
	   if (chip.dir=='R')
	   {
			if (chip.named=='flyimage4') 
			{ chip.xx+=4; } 
			else if (chip.named=='flyimage2')
			{ chip.xx+=2; }
			else
			{ chip.xx+=2; }
	   }
	   if (chip.dir=='D' || (chip.named=='flyimage3' || chip.named=='flyimage4' && chip.dir!='SIT') )
	   {
			if (chip.named=='flyimage4') { chip.yy+=2; } else { chip.yy+=1; }
	   }
	   if (chip.dir=='U')
	   {
		   chip.yy-=4;
	   }
	   
	   // has the char hit a boundary?
	   if(chip.xx<=-50)
	   {		
			chip.dir='R';
			if (chip.named=='flyimage1')
			{
				document.getElementById(chip.named+'a').src='/images/nodes_anim_r.gif';
			}
			else if (chip.named=='flyimage3')
			{
				document.getElementById(chip.named+'a').src='/images/knight_lore_r.gif';
			}
			else if (chip.named=='flyimage4')
			{
				document.getElementById(chip.named+'a').src='/images/skateordie45R.GIF';
			}
			
	   }
	   
	   if (chip.named=='flyimage2')
	   {
		   chip.xx = 10;
		   if (document.getElementById(chip.named+'a').style.visibility == 'hidden')
		   {
				if ( (Math.random()*200)<1 )
			    {
				   document.getElementById(chip.named+'a').style.visibility = 'visible';
				   document.getElementById(chip.named+'a').src='/images/shooting-stars-r.gif';
			    }
			}
			else
			{
				if ( (Math.random()*100)<1 )
		 	    {
				   document.getElementById(chip.named+'a').style.visibility = 'hidden';
			    }
			}
	   }
	   
	   if(chip.xx>=((pageX+pageW-chip.w)-380))
	   {
			document.getElementById(chip.named+'a').style.visibility = 'hidden';
			chip.dir='L';
			chip.xx=pageX+pageW-chip.w-380;
			if (chip.named=='flyimage1')
			{
				document.getElementById(chip.named+'a').src ='/images/nodes_anim.gif';
			}
			else if (chip.named=='flyimage3')
			{
				document.getElementById(chip.named+'a').src='/images/knight_lore.gif';
			}
			else if (chip.named=='flyimage4')
			{
				document.getElementById(chip.named+'a').src='/images/skateordie45L.GIF';
			}
	   }
	   else
	   {
	   		if (chip.named!='flyimage2'){ document.getElementById(chip.named+'a').style.visibility = 'visible'; }
	   }
	   
	   // if flyimage3 has gone too far down, move him back to the top
	   if (chip.named=='flyimage3' || chip.named=='flyimage4' && chip.yy > 129)
		{
			chip.yy = -300;
		}
	   
  		document.getElementById(chip.named).style.left=chip.xx+"px";	
		document.getElementById(chip.named).style.top=chip.yy+"px";
		chip.timer1=setTimeout("movechip('"+chip.named+"')",100);
  }
}

