// Actions var move_star = false; // Mouse var Mouse_x; var Mouse_y; // Neutral stars var total_neutral_stars = 100; // New star function Star (id, name, x, y) { this.id = id; this.name = name; this.x = x; this.y = y; this.display = function () { document.write(""); } } // Star on this position function starOnPosition (x, y) { for (var i = 0; i < stars.length; ++i) if ((stars[i].x == x && stars[i].y == y) || (stars[i].x + 1 == x && stars[i].y == y) || (stars[i].x == x && stars[i].y + 1 == y) || (stars[i].x + 1 == x && stars[i].y + 1 == y)) return true; return false; } // Start galaxy function startGalaxy () { window.setInterval ("moveGalaxy ();", 3000); layer_sky.onclick = setStar; } // Create artificial stars function createGalaxy () { var x; var y; if (!layer_sky) return; for (var i = 0; i < total_neutral_stars; ++i) { x = Math.floor ((layer_sky.offsetWidth - 5) * Math.random()); y = Math.floor (layer_sky.offsetHeight * Math.random()); document.write (""); } } // Make neutral stars move function moveGalaxy () { var star_id = Math.floor (total_neutral_stars * Math.random ()); var layer_star = document.getElementById("star" + star_id); var x; var y; if (!layer_sky || !layer_star) return; x = Math.floor ((layer_sky.offsetWidth - 5) * Math.random ()); y = Math.floor (layer_sky.offsetHeight * Math.random ()); layer_star.style.top = y + "px"; layer_star.style.left = x + "px"; } // Locate star function locateStar (id) { if (!layer_locate) return; layer_locate.style.left = (stars[id].x - 2) + "px"; layer_locate.style.top = (stars[id].y - 2) + "px"; layer_locate.style.visibility = "visible"; } // Move star function moveStar () { if (document.newstar_form.newstar_star_name.value == "" || document.newstar_form.newstar_star_name.value == "My Star") { // Error var layer_error = document.getElementById("error"); setError ("Please name your star."); return; } if (!layer_sky) return; move_star = true; layer_sky.style.cursor = "crosshair"; } // Set star function setStar (e) { if (!layer_sky || !move_star) return; if (starOnPosition (Mouse_x, Mouse_y)) { setError ("Can't hang your star up there."); return; } if (sky_height == 0 || sky_width == 0) { setError ("Unexpected error"); return; } var form_star = document.newstar_form; move_star = false; layer_sky.style.cursor = "default"; form_star.newstar_star_x.value = Mouse_x; form_star.newstar_star_y.value = Mouse_y; form_star.newstar_size_x.value = sky_width; form_star.newstar_size_y.value = sky_height; form_star.submit (); } // Set error message function setError (message) { if (!layer_error) return; layer_error.innerHTML = "" + message + ""; setTimeout ("document.getElementById('error').innerHTML = '';", 3000); } // Save mouse position function getPosition (mouse) { Mouse_x = (navigator.appName.substring(0,3) == "Net") ? mouse.pageX : event.x + document.body.scrollLeft; Mouse_y = (navigator.appName.substring(0,3) == "Net") ? mouse.pageY : event.y + document.body.scrollTop; } // Display star name function displayStarName (id) { if (!layer_star_label) return; layer_star_label.style.color = "#FF9900"; layer_star_label.style.backgroundColor = "#003366"; if (stars[id].x > sky_width / 2) { layer_star_label.style.right = (sky_width - Mouse_x + 12) + "px"; layer_star_label.style.left = ""; } else { layer_star_label.style.left = (Mouse_x + 18) + "px"; layer_star_label.style.right = ""; } layer_star_label.style.top = (Mouse_y + 5) + "px"; layer_star_label.innerHTML = stars[id].name; } // Hide star name function hideStarName () { if (!layer_star_label) return; layer_star_label.innerHTML = ""; layer_star_label.style.top = "-10px"; } // Start event detection document.onmousemove = getPosition;