/* copyright Tomas Young 2008 */

// document.write('<bgsound src="#" id="rocket-s" autostart=true hide=true loop=false>');

if(screen.width >= 1400) {  // 1600x200, 1400x1050
document.write('<div id="rocket-platform-st" style="position:absolute; left:100px; top:400px;"> \
                <img name="rocket-platform-i" src="surface 0.jpg" border="0" width=1000 height=500> \
                </div>');
document.write('<div id="rocket-st" style="position:absolute; left:870px; top:430px;"> \
                <img name="rocket-i" src="rocket9b.gif" border="0" width=100 height=200> \
                </div>');
document.write('<div style="position:absolute; left:350px; top:450px;"> \
                <img name="planet-i" src="moon 1.gif" border="0" width=120 height=120> \
                </div>');
document.write('<div id="astronaut-st" style="position:absolute; left:130px; top:805px;"> \
                <img name="astronaut-i" src="astronaut1.gif" border="0" width=40 height=60> \
                </div>');
}
else {  // 1280x1024, 1024x768, 800x600, 640x480
document.write('<div id="rocket-platform-st" style="position:absolute; left:50px; top:320px;"> \
                <img name="rocket-platform-i" src="surface 0.jpg" border="0" width=800 height=280> \
                </div>');
document.write('<div id="rocket-st" style="position:absolute; left:680px; top:350px;"> \
                <img name="rocket-i" src="rocket9b.gif" border="0" width=50 height=100> \
                </div>');
document.write('<div style="position:absolute; left:260px; top:350px;"> \
                <img name="planet-i" src="moon 1.gif" border="0" width=60 height=60> \
                </div>');
document.write('<div id="astronaut-st" style="position:absolute; left:90px; top:547px;"> \
                <img name="astronaut-i" src="astronaut1.gif" border="0" width=25 height=35> \
                </div>');
}

var game_fun_st = "astronaut-st";
var game_fun_i = "astronaut-i";

var funObj = document.getElementById(game_fun_st);

var game_fun_x = 130;
var game_fun_y = 805;
var game_fun_z = 0;
var game_fun_level = 0;

var stObj = null;
var iObj = null;
var stX = 0;
var stY = 0;
var iW = 0;
var iH = 0;
var flyCnt = 0;

var game_loops = 0;
var planets = new Array;

planets[0] = "moon 1.gif";
planets[1] = "earth 1.gif";
planets[2] = "mars 1.gif";
planets[3] = "jupiter 1.gif";
planets[4] = "saturn 1.gif";

function flyRocket() {
    iObj.src = "rocket5c.gif";
    stObj.style.left = stX;
    stObj.style.top = stY;
    iObj.width = iW;
    iObj.height = iH;
    if(flyCnt++ > 10) {
        stX += 6;
        stY -= 8;
        iW = Math.floor(iW * .975);
        iH = Math.floor(iH * .975);
    }
    if(iW > 0 || iH > 0) {
        setTimeout('flyRocket()',75);
    }
    else {
	game_loops = (game_loops + 1) % 5;
	document["planet-i"].src = planets[game_loops];
    }
    if(iW == 0 || iH == 0) {
	iW = 0;
	iH = 0;
    }
}

var funX = 0;
var funXmax = 0;
var funY = 0;
var funY0 = 0;
var y_delta = 0;
var x_center = 0;
var parabola_w2 = 1;

var jumpDir = 0;  // 0=up 1=down

function flyAstronaut() {
    funObj.style.left = funX;
    var d = 0;
    var yy = 0;
    if(jumpDir == 1) {
	d = funX - x_center;
	yy = parabola_w2 * d * d;
	yy = yy * .005;
	funObj.style.top = funY0 - y_delta + yy;
    }
    else {
	d = funX - x_center;
	yy = parabola_w2 * d * d;
	yy = yy * .005;
	funObj.style.top = yy + funY - 100;
    }
    funX += 5;
    if(funX < funXmax) {
	setTimeout("flyAstronaut()",32);
    }
}

var cheerToggle = 1;

function game_fun(s) {
    game1_delay[1] = 3000;
    if(s == true) {
	if(game_fun_level >= 7 && game_fun_level < 10) {
	    if(game_fun_level == 7) {
		if(screen.width >= 1400) {
		    game_fun_x = 902;
		    game_fun_y = 525;
		}
		else {
		    game_fun_x = 694;
		    game_fun_y = 393;
		}
	    }
	    else if(game_fun_level == 8) {
		document["rocket-i"].src = "rocket6b.gif";
		document["astronaut-i"].src = "blank.gif";
	    }
	    else if(game_fun_level == 9) {
		game1_delay[1] = 8000;
		stObj = document.getElementById("rocket-st");
		iObj = document.getElementsByName("rocket-i")[0];
		iObj.src = "rocket12b.gif";
		if(screen.width >= 1400) {
		    stX = 870;
		    stY = 440;
		    iW = 100;
		    iH = 220;
		}
		else {
		    stX = 680;
		    stY = 350;
		    iW = 50;
		    iH = 100;
		}
		flyCnt = 0;
		// document.all["rocket-s"].src = "rocket.wav";
		Sin("rocket-s","rocket.wav");
		setTimeout('flyRocket()',2500);
	    }
	    funObj.style.left = game_fun_x;
	    funObj.style.top = game_fun_y;
	    funObj.style.zIndex = game_fun_z;
	}
	else {
	    if(game_fun_level == -1) {
		stObj = document.getElementById("rocket-st");
		iObj = document.getElementsByName("rocket-i")[0];
		iObj.src = "blank.gif";
		if(screen.width >= 1400) {
		    stObj.style.left = 870;
		    stObj.style.top = 430;
		    iObj.width = 100;
		    iObj.height = 200;
		    game_fun_x = 130;
		    game_fun_y = 805;
		}
		else {
		    stObj.style.left = 680;
		    stObj.style.top = 350;
		    iObj.width = 50;
		    iObj.height = 100;
		    game_fun_x = 90;
		    game_fun_y = 547;
		}
		iObj.src = "rocket9b.gif";
		funObj.style.left = game_fun_x;
		funObj.style.top = game_fun_y;
		document["astronaut-i"].src = "astronaut1.gif";
	    }
	    if(game_fun_level == 0) {
		if(screen.width >= 1400) {
		    funX = 130; funXmax = 296; funY = 788; parabola_w2 = 2;
		}
		else {
		    funX = 90; funXmax = 205; funY = 588; parabola_w2 = 2;
		}
		x_center = funX+(funXmax-funX)/2;
		jumpDir = 0;
	    }
	    else if(game_fun_level == 1) {
		if(screen.width >= 1400) {
		    funX = funXmax; funXmax = 426; funY = 735; parabola_w2 = 2;
		}
		else {
		    funX = funXmax; funXmax = 315; funY = 546; parabola_w2 = 2;
		}
		x_center = funX+(funXmax-funX)/2;
		jumpDir = 0;
	    }
	    else if(game_fun_level == 2) {
		if(screen.width >= 1400) {
		    funX = funXmax; funXmax = 540; funY = 880; parabola_w2 = 2.6;
		    funY0 = 720; y_delta = 50;
		}
		else {
		    funX = funXmax; funXmax = 405; funY = 585; parabola_w2 = 2.6;
		    funY0 = 500; y_delta = 35;
		}
		x_center = funX + 1;
		jumpDir = 1;
	    }
	    else if(game_fun_level == 3) {
		if(screen.width >= 1400) {
		    funX = funXmax; funXmax = 605; funY = 842; parabola_w2 = 2;
		}
		else {
		    funX = funXmax; funXmax = 455; funY = 610; parabola_w2 = 2;
		}
		x_center = funX+(funXmax-funX)/2;
		jumpDir = 0;
	    }
	    else if(game_fun_level == 4) {
		if(screen.width >= 1400) {
		    funX = funXmax; funXmax = 683; funY = 730; parabola_w2 = 2;
		}
		else {
		    funX = funXmax; funXmax = 525; funY = 545; parabola_w2 = 2;
		}
		x_center = funX+(funXmax-funX)/2;
		jumpDir = 0;
	    }
	    else if(game_fun_level == 5) {
		if(screen.width >= 1400) {
		    funX = funXmax; funXmax = 835; funY = 616; parabola_w2 = 2;
		}
		else {
		    funX = funXmax; funXmax = 652; funY = 480; parabola_w2 = 2;
		}
		x_center = funX+(funXmax-funX)/2;
		jumpDir = 0;
	    }
	    else if(game_fun_level == 6) {
		if(screen.width >= 1400) {
		    funX = funXmax; funXmax = 907; funY = 620; parabola_w2 = 1;
		    funY0 = 616; y_delta = 60;
		}
		else {
		    funX = funXmax; funXmax = 698; funY = 445; parabola_w2 = 1;
		    funY0 = 445; y_delta = 38;
		}
		x_center = funX + 1;
		jumpDir = 1;
	    }
	    if(game_fun_level >= 0) {
		if(cheerToggle == 0) {
		    // document.all["rocket-s"].src = "cheer.wav";
		    Sin("rocket-s","cheer.wav");
		    cheerToggle = 1;
		}
		else {
		    // document.all["rocket-s"].src = "wee.wav";
		    Sin("rocket-s","wee.wav");
		    cheerToggle = 0;
		}
		flyAstronaut();
	    }
	}
	if(game_fun_level == 9) {
	    game_fun_level = -1;
	}
	else {
	    game_fun_level++;
	}
    }
}

