// scr_spaceinvaders.js
//
//	(C) 2000 Juan Prada Blanco
//
//	Mueve unos marcianitos por la pantalla
//
//	Válido para Explorer y Netscape

function ExplorerMoveDIV(idDiv, xx, yy)
{
	switch(idDiv) {
		case 0:
			document.all.a.style.top = yy;
			document.all.a.style.left = xx;
			break;
		case 1:
			document.all.b.style.top = yy;
			document.all.b.style.left = xx;
			break;
		case 2:
			document.all.c.style.top = yy;
			document.all.c.style.left = xx;
			break;
		case 3:
			document.all.d.style.top = yy;
			document.all.d.style.left = xx;
			break;
		case 4:
			document.all.e.style.top = yy;
			document.all.e.style.left = xx;
			break;
		case 5:
			document.all.f.style.top = yy;
			document.all.f.style.left = xx;
			break;
	}
}


var userAgent=navigator.appName + " " + navigator.appVersion;
var agentInfo=userAgent.substring(0, 12);
var IsNetscape=navigator.appName=="Netscape";


if (IsNetscape) {
document.write('<layer name="a" id="a" left="10" top="10" visibility="SHOW" clip="0,0,26,20"> <IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"> </layer>');
document.write('<LAYER name="b" id="b" left="10" top="10" visibility="SHOW" clip="0,0,26,20"> <IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"> </LAYER>');
document.write('<LAYER name="c" id="c" left="10" top="10" visibility="SHOW" clip="0,0,26,20"> <IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"> </LAYER>');
document.write('<LAYER name="d" id="e" left="10" top="10" visibility="SHOW" clip="0,0,48,48"> <IMG SRC="mazog.gif" HEIGHT="48" WIDTH="48" NATURALSIZEFLAG="0" ALIGN="BOTTOM"> </LAYER>');
document.write('<LAYER name="e" id="f" left="10" top="10" visibility="SHOW" clip="0,0,26,20"> <IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"> </LAYER>');
document.write('<LAYER name="f" id="g" left="10" top="10" visibility="show" clip="0,0,26,20"> <IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"> </LAYER>');
} else {
document.write('<div id="a" style="position:absolute; left:17px; top:42px; width:69px; height:63px; z-index:1; overflow: visible; visibility: visible"><IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"></div>');
document.write('<div id="b" style="position:absolute; left:17px; top:42px; width:69px; height:63px; z-index:2; overflow: visible; visibility: visible"><IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"></div>');
document.write('<div id="c" style="position:absolute; left:17px; top:42px; width:69px; height:63px; z-index:3; overflow: visible; visibility: visible"><IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"></div>');
document.write('<div id="d" style="position:absolute; left:17px; top:42px; width:48px; height:48px; z-index:4; overflow: visible; visibility: visible"><IMG SRC="mazog.gif" HEIGHT="48" WIDTH="48" NATURALSIZEFLAG="0" ALIGN="BOTTOM"></div>');
document.write('<div id="e" style="position:absolute; left:17px; top:42px; width:69px; height:63px; z-index:5; overflow: visible; visibility: visible"><IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"></div>');
document.write('<div id="f" style="position:absolute; left:17px; top:42px; width:69px; height:63px; z-index:6; overflow: visible; visibility: visible"><IMG SRC="spaceinvaders.gif" HEIGHT="20" WIDTH="26" NATURALSIZEFLAG="0" ALIGN="BOTTOM"></div>');
}


if (1)
{
//window.captureEvents(Event.MOUSEMOVE);


// Animación Space Invaders
//
//	(C) 2000 Juan Prada Blanco

var yBase;
var xBase;
var MyInnerWidth;
var MyInnerHeight;
		
var delay = 600;
var yAmpl = 10;
var yMax = 40;
var step = .2;
var ystep = .5;
var currStep = 0;
var tAmpl=1;

var iSeparacionX = 40;
var iSeparacionY = 34;
var iAvanceX = 13;
var iAvanceY = 26;

var XPos = 0;
var YPos = 0;

var XPos1 = 20;
var YPos1 = 260;
var XPos2 = 20;
var YPos2 = 260 + 34;
var iFila = 1;
var iMaxFilas = 2;
var j = 0;

//function MoveHandler(evnt) {
//  XPos = evnt.pageX ;
//  YPos = evnt.pageY ;
//}
//window.onMouseMove = MoveHandler;

function animateLogo() {


if (IsNetscape) {
	yBase = window.innerHeight/4;
	xBase = window.innerWidth/4;
	MyInnerHeight = window.innerHeight;
	MyInnerWidth = window.innerWidth;
} else {
	yBase = document.body.clientHeight/4;
	xBase = document.body.clientWidth/4;
	MyInnerHeight = document.body.clientHeight;
	MyInnerWidth = document.body.clientWidth;
}
	

	if (iFila == 1) {
		XPos = XPos1;
		YPos = YPos1;
	}
	
	if (iFila == 2) {
		XPos = XPos2;
		YPos = YPos2;
	}
	
	XPos += iAvanceX;
	
  	if ( (XPos > (MyInnerWidth - (iSeparacionX * 3))) || (XPos < 20) ) {
		iAvanceX = - iAvanceX;
		YPos += iAvanceY;
		YPos1 += iAvanceY;
		YPos2 += iAvanceY;
		delay -= 10;
		if (delay <= 0) { delay = 1; }
	}
	
	if (YPos > (MyInnerHeight - (iSeparacionY * 3))) {
		YPos = 20;
		YPos1 = 20;
		YPos2 = 20 + iSeparacionY;
	}
	
	
	if (iFila == 1) {
		XPos1 = XPos;
		YPos1 = YPos;
	}
	
	if (iFila == 2) {
		XPos2 = XPos1;
		YPos2 = YPos1 + iSeparacionY;
	}
	
  for ( j = 0 ; j < 6 ; j++ ) {
//    document.layers[j].top = YPos + Math.cos((20*Math.sin(currStep/(20+j)))+j*70)*yBase*(Math.sin(10+currStep/10)+0.2)*Math.cos((currStep + j*25)/10);
//    document.layers[j].left =XPos + Math.sin((20*Math.sin(currStep/20))+j*70)*xBase*(Math.sin(10+currStep/(10+j))+0.2)*Math.cos((currStep + j*25)/10);

	
	if (j < 3) {
		if (IsNetscape) {
			document.layers[j].top =  YPos1;
			document.layers[j].left =  (XPos1 + ( j * iSeparacionX)) ;
		} else {
			ExplorerMoveDIV(j, (XPos1 + ( j * iSeparacionX)), YPos1);
		}
	} else {
		if (IsNetscape) {
			document.layers[j].top =  YPos2;
			document.layers[j].left =  (XPos2 + ( (j - 3) * iSeparacionX)) ;
		} else {
			ExplorerMoveDIV(j, (XPos2 + ( (j - 3) * iSeparacionX)), YPos2);
		}
	}
	
  }
	
	currStep += step;
	if (iFila == iMaxFilas) {
		setTimeout("animateLogo()", delay ) ;
	} else {
		setTimeout("animateLogo()", delay / 3) ;
	}
 
 	iFila++;
	
	if (iFila > iMaxFilas) iFila = 1;
}
animateLogo()
}