Use of arrow keys when focused on the Google language option field will translate site content on the fly. Use your enter key to review all options and choose your selection before applying.
In this first project you will build a web site that incorporates the use of JavaScript.
Navigate to your Web Design 2 folder on the (I:) drive. Create a new folder named javascript_project. Open the javascript_project folder and within create a folder named images.
In Dreamweaver create a new site named JavaScript Site. Use the folders created previously to hold the files for the site.
Create the following html files: (NOTICE: select None for the DocType to avoid javascript problems.)
index.html
form.html
games1.html
games2.html
games3.html
goofy1.html
goofy2.html
goofy3.html
image1.html
image2.html
image3.html
math1.html
math2.html
math3.html
menu.html
Create the following css file:
main.css
Create the following javascript (js) file:
quickmenu.js
This site will need to meet the following requirements:
a menu created with QuickMenu that has the following links:
All of the elements on the form must be validated. Those items that require the user to enter information, email for example, will need to be validated using RegExp. Other form elements such as check boxes and option buttons will need to be evaluated to see if they have been selected.
In the head of form.html you will need to have a JavaScript function named validate() for the validation of the form. The code for validate() will be very similar to the code that you wrote in the Form Validation Exercise. To get started you may copy this beginning of the validate() function and paste it into the head of form.html.
<script type="text/javascript">
function validate(form){
var errors = 0;
var msg="The following has occured...\n\n";
var ck_first_name = /^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$/;
var first_name = form.first_name.value;
// there will be many more variable in this section
// code to test whether the first name entered is valid
if(ck_first_name.test(first_name)==false){
msg+="The first name entered is not valid. \n";
document.form.first_name.style.backgroundColor="red";
errors++;
}
// the code you enter must all be above this line
if(errors > 0){
alert(msg);
return false; // stops the browser from going to congrats.html
}
else
return true; // everything was valid, go on to congrats.html
}
</script>
It would not be reasonable to expect that you would be able create all of your own RegExp for this project. There is a web site, http://www.regxlib.com/ , that has a collection of often used RegExp. You can search the site and find the RegExp needed for this project. The Regular Expressions provided for this project were all found at regxlib.com.
Regular Expressions (RegExp) to use for this project:
first name: ^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$
This allows you to validate first names or last names in separate fields.
Matches:Samuel |O'Conner | Mary-Kate
Non-Matches: David Bugel | Robert1 | Robert M. Larry
last name: ^[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$
This allows you to validate first names or last names in separate fields.
Matches:Samuel | O'Conner | Mary-Kate
Non-Matches:David Bugel | Robert1 | Robert M. Larry
Tests if the input consists of 6 or more letters, digits, underscores and hyphens. The input must contain at least one upper case letter, one lower case letter and one digit.
password confirm:
No regexp needed.
For error checking use something like if(pswrd1 != pswrd2) ...
gender options:
No regexp needed.
must make sure one of the options have been selected
Paste the following code in the head section of math3.html.
<script type="text/javascript">
<!--
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: James Crooke :: http://www.cj-design.com */
var calculation = "";
var resultDone = false;
function addToCalc(val) {
if(isNaN(val) && isNaN(calculation.substring(calculation.length-1, calculation.length)))
return false;
Copy the JavaScript code below and paste it into the body section of games1.html.
<script type="text/javascript">
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jason Hotchkiss | */
/* Information used to draw the ships */
var ship = [[[1,5], [1,2,5], [1,2,3,5], [1,2,3,4,5]], [[6,10], [6,7,10], [6,7,8,10], [6,7,8,9,10]]];
/* Information used to draw sunk ships */
var dead = [[[201,203], [201,202,203], [201,202,202,203], [201,202,202,202,203]], [[204,206], [204,205,206], [204,205,205,206], [204,205,205,205,206]]];
/* Information used to describe ships */
var shiptypes = [["Minesweeper",2,4],["Frigate",3,4],[ "Cruiser",4,2],[ "Battleship",5,1]];
var gridx = 16, gridy = 16;
var player = [], computer = [], playersships = [], computersships = [];
var playerlives = 0, computerlives = 0, playflag=true, statusmsg="";
/* Function to preload all the images, to prevent delays during play */
var preloaded = [];
function imagePreload() {
var i,ids = [1,2,3,4,5,6,7,8,9,10,100,101,102,103,201,202,203,204,205,206];
window.status = "Preloading images...please wait";
for (i=0;i<ids.length;++i) {
var img = new Image, name = "batt"+ids[i]+".gif";
img.src = "images/" + name;
preloaded[i] = img;
}
window.status = "";
}
/* Function to place the ships in the grid */
function setupPlayer(ispc) {
var y,x;
grid = [];
for (y=0;y<gridx;++y) {
grid[y] = [];
for (x=0;x<gridx;++x)
grid[y][x] = [100,-1,0];
}
var shipno = 0;
var s;
for (s=shiptypes.length-1;s>=0;--s) {
var i;
for (i=0;i<shiptypes[s][2];++i) {
var d = Math.floor(Math.random()*2);
var len = shiptypes[s][1], lx=gridx, ly=gridy, dx=0, dy=0;
if ( d==0) {
lx = gridx-len;
dx=1;
} else {
ly = gridy-len;
dy=1;
}
var x,y,ok;
do {
y = Math.floor(Math.random()*ly);
x = Math.floor(Math.random()*lx);
var j,cx=x,cy=y;
ok = true;
for (j=0;j<len;++j) {
if (grid[cy][cx][0] < 100) {
ok=false;
break;
}
cx+=dx;
cy+=dy;
}
} while(!ok);
var j,cx=x,cy=y;
for (j=0;j<len;++j) {
grid[cy][cx][0] = ship[d][s][j];
grid[cy][cx][1] = shipno;
grid[cy][cx][2] = dead[d][s][j];
cx+=dx;
cy+=dy;
}
if (ispc) {
computersships[shipno] = [s,shiptypes[s][1]];
computerlives++;
} else {
playersships[shipno] = [s,shiptypes[s][1]];
playerlives++;
}
shipno++;
}
}
return grid;
}
/* Function to change an image shown on a grid */
function setImage(y,x,id,ispc) {
if ( ispc ) {
computer[y][x][0] = id;
document.images["pc"+y+"_"+x].src = "images/batt"+id+".gif";
} else {
player[y][x][0] = id;
document.images["ply"+y+"_"+x].src = "images/batt"+id+".gif";
}
}
/* Function to insert HTML source for a grid */
function showGrid(ispc) {
var y,x;
for (y=0;y<gridy;++y) {
for (x=0;x<gridx;++x) {
if ( ispc )
document.write ('<a href="javascript:gridClick('+y+','+x+');"><img name="pc'+y+'_'+x+'" src="images/batt100.gif" width=16 height=16></a>');
else
document.write ('<a href="javascript:void(0);"><img name="ply'+y+'_'+x+'" src="images/batt'+player[y][x][0]+'.gif" width=16 height=16></a>');
}
document.write('<br>');
}
}
/* Handler for clicking on the grid */
function gridClick(y,x) {
if ( playflag ) {
if (computer[y][x][0] < 100) {
setImage(y,x,103,true);
var shipno = computer[y][x][1];
if ( --computersships[shipno][1] == 0 ) {
sinkShip(computer,shipno,true);
alert("You sank my "+shiptypes[computersships[shipno][0]][0]+"!");
updateStatus();
if ( --computerlives == 0 ) {
alert("You win! Press the Refresh button on\n"+
"your browser to play another game.");
playflag = false;
}
}
if ( playflag ) computerMove();
} else if (computer[y][x][0] == 100) {
setImage(y,x,102,true);
computerMove();
}
}
}
/* Function to make the computers move. Note that the computer does not cheat, oh no! */
function computerMove() {
var x,y,pass;
var sx,sy;
var selected = false;
/* Make two passes during 'shoot to kill' mode */
for (pass=0;pass<2;++pass) {
for (y=0;y<gridy && !selected;++y) {
for (x=0;x<gridx && !selected;++x) {
/* Explosion shown at this position */
if (player[y][x][0]==103) {
sx=x; sy=y;
var nup=(y>0 && player[y-1][x][0]<=100);
var ndn=(y<gridy-1 && player[y+1][x][0]<=100);
var nlt=(x>0 && player[y][x-1][0]<=100);
var nrt=(x<gridx-1 && player[y][x+1][0]<=100);
if ( pass == 0 ) {
/* On first pass look for two explosions in a row - next shot will be inline */
var yup=(y>0 && player[y-1][x][0]==103);
var ydn=(y<gridy-1 && player[y+1][x][0]==103);
var ylt=(x>0 && player[y][x-1][0]==103);
var yrt=(x<gridx-1 && player[y][x+1][0]==103);
if ( nlt && yrt) { sx = x-1; selected=true; }
else if ( nrt && ylt) { sx = x+1; selected=true; }
else if ( nup && ydn) { sy = y-1; selected=true; }
else if ( ndn && yup) { sy = y+1; selected=true; }
} else {
/* Second pass look for single explosion - fire shots all around it */
if ( nlt ) { sx=x-1; selected=true; }
else if ( nrt ) { sx=x+1; selected=true; }
else if ( nup ) { sy=y-1; selected=true; }
else if ( ndn ) { sy=y+1; selected=true; }
}
}
}
}
}
if ( !selected ) {
/* Nothing found in 'shoot to kill' mode, so we're just taking
potshots. Random shots are in a chequerboard pattern for
maximum efficiency, and never twice in the same place */
do {
sy = Math.floor(Math.random() * gridy);
sx = Math.floor(Math.random() * gridx/2)*2+sy%2;
} while( player[sy][sx][0]>100 );
}
if (player[sy][sx][0] < 100) {
/* Hit something */
setImage(sy,sx,103,false);
var shipno = player[sy][sx][1];
if ( --playersships[shipno][1] == 0 ) {
sinkShip(player,shipno,false);
alert("I sank your "+shiptypes[playersships[shipno][0]][0]+"!");
if ( --playerlives == 0 ) {
knowYourEnemy();
alert("I win! Press the Refresh button on\n"+
"your browser to play another game.");
playflag = false;
}
}
} else {
/* Missed */
setImage(sy,sx,102,false);
}
}
/* When whole ship is hit, show it using changed graphics
*/
function sinkShip(grid,shipno,ispc) {
var y,x;
for (y=0;y<gridx;++y) {
for (x=0;x<gridx;++x) {
if ( grid[y][x][1] == shipno )
if (ispc) setImage(y,x,computer[y][x][2],true);
else setImage(y,x,player[y][x][2],false);
}
}
}
/* Show location of all the computers ships - when player has lost */
function knowYourEnemy() {
var y,x;
for (y=0;y<gridx;++y) {
for (x=0;x<gridx;++x) {
if ( computer[y][x][0] == 103 )
setImage(y,x,computer[y][x][2],true);
else if ( computer[y][x][0] < 100 )
setImage(y,x,computer[y][x][0],true);
}
}
}
/* Show how many ships computer has left */
function updateStatus() {
var f=false,i,s = "Computer has ";
for (i=0;i<computersships.length;++i) {
if (computersships[i][1] > 0) {
if (f) s=s+", "; else f=true;
s = s + shiptypes[computersships[i][0]][0];
}
}
if (!f) s = s + "nothing left, thanks to you!";
statusmsg = s;
window.status = statusmsg;
}
function setStatus() {
window.status = statusmsg;
}
Copy the following code and paste it into the head section of games3.html.
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ken Douglas (ken@ntlworld.com) -->
<!-- Web Site: http://www.groveroad.herts.sch.uk -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
// static globals
var maxheight = 9;
var maxwidth = maxheight;
var winscore = Math.round((maxheight * maxwidth / 2) + 0.5);
// dynamic globals
var player = 1;
var won = 0;
function newGame() {
// sets all graphics back to default and clears scores
won = 0;
eval('document.squares.score1.value = 0');
eval('document.squares.score2.value = 0');
for (var y = 1; y <= maxheight; y ++ ) {
for (var x = 1; x <= maxwidth; x ++ ) {
document.images["x" + x + "y" + y].src = sqr[0].src;
document.images["vx" + x + "vy" + y].src = ver[0].src;
document.images["hx" + x + "hy" + y].src = hor[0].src;
}
}
for (var a = 1; a <= maxheight; a ++ ) {
onemore = maxheight + 1;
document.images["vx" + onemore + "vy" + a].src = ver[0].src;
document.images["hx" + a + "hy" + onemore].src = hor[0].src;
}
}
function preload() {
if (document.images) {
sqr = new makeArray(3);
sqr[0].src = "images/p0.gif";
sqr[1].src = "images/p1.gif";
sqr[2].src = "images/p2.gif";
ver = new makeArray(3);
ver[0].src = "images/v0.gif";
ver[1].src = "images/v1.gif";
ver[2].src = "images/v2.gif";
hor = new makeArray(3);
hor[0].src = "images/h0.gif";
hor[1].src = "images/h1.gif";
hor[2].src = "images/h2.gif";
sel = new makeArray(2);
sel[0].src = "images/notsel.gif";
sel[1].src = "images/sel.gif";
}
else {
alert("Sorry, this game needs a browser\nwhich supports the image object.");
}
}
function makeArray(n) {
this.length = n;
for (i = 0; i < n; i ++) {
this[i] = new Image();
}
return this;
}
function go (type, a, b) {
// processes clicks on square verticals and horizontals...
hit = 0;
if (type == 1) {
if (document.images["hx" + a + "hy" + b].src == hor[1].src) {
alert("Already taken - try again");
return;
}
document.images["hx" + a + "hy" + b].src = hor[1].src;
// figure out if the square above is captured
if (b != 1) {
var an = a + 1;
var bn = b - 1;
if ((document.images["vx" + a + "vy" + bn].src == ver[1].src) && (document.images["vx" + an + "vy" + bn].src == ver[1].src) && (document.images["hx" + a + "hy" + bn].src == hor[1].src)) {
document.images["x" + a + "y" + bn].src = sqr[player].src;
scoresOnDoors();
hit = 1;
}
}
//figure out if the square below is captured
if (b != maxheight + 1) {
var an = a + 1;
var bn = b + 1;
if ((document.images["vx" + a + "vy" + b].src == ver[1].src) && (document.images["vx" + an + "vy" + b].src == ver[1].src) && (document.images["hx" + a + "hy" + bn].src == hor[1].src)) {
document.images["x" + a + "y" + b].src = sqr[player].src;
scoresOnDoors();
hit = 1;
}
}
}
if (type == 2) {
if (document.images["vx" + a + "vy" + b].src == ver[1].src) {
alert("Already taken - try again");
return;
}
document.images["vx" + a + "vy" + b].src = ver[1].src;
// figure out if the square right is captured
if (a != maxwidth + 1) {
var an = a + 1;
var bn = b + 1;
if ((document.images["hx" + a + "hy" + b].src == hor[1].src) && (document.images["hx" + a + "hy" + bn].src == hor[1].src) && (document.images["vx" + an + "vy" + b].src == ver[1].src)) {
document.images["x" + a + "y" + b].src = sqr[player].src;
scoresOnDoors();
hit = 1;
}
}
//figure out if the left is captured
if (a != 1) {
var an = a - 1;
var bn = b + 1;
if ((document.images["hx" + an + "hy" + b].src == hor[1].src) && (document.images["hx" + an + "hy" + bn].src == hor[1].src) && (document.images["vx" + an + "vy" + b].src == ver[1].src)) {
document.images["x" + an + "y" + b].src = sqr[player].src;
scoresOnDoors();
hit = 1;
}
}
}
// change players if no hit
if (hit == 0) {
if (player != 1) {player = 1
}
else {
player = 2;
}
showPlayer();
}
return;
}
function showPlayer() {
// let the users jnow which player is "up" by switching on the appropriate graphic
if (player == 1) {
document.images["play2"].src = sqr[0].src;
document.images["play1"].src = sqr[1].src;
}
if (player == 2) {
document.images["play1"].src = sqr[0].src;
document.images["play2"].src = sqr[2].src;
}
return;
}
function scoresOnDoors() {
// simple score increment and check - note play can comtinue after a winner is declared
eval('tmp = document.squares.score' + player + '.value');
tmp = tmp * 1;
tmp += 1;
eval('document.squares.score' + player + '.value = tmp');
if (won == 0 && tmp >= winscore) {
alert("Player " + player + " wins");
won = 1;
}
return;
}
// End -->
</script>
Copy the following code and paste it into the body section of games.html.
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ken Douglas (ken@ntlworld.com) -->
<!-- Web Site: http://www.groveroad.herts.sch.uk -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var output = '';
output += '<TABLE CELLPADDING = 0 CELLSPACING = 8 BORDER = 0><TR>';
// create the board
output += '<TD><TABLE CELLPADDING = 0 CELLSPACING = 0 BORDER = 0>';
for (var y = 1; y <= maxheight; y ++ ) {
output += '<TR>';
for (var x = 1; x <= maxwidth; x ++ ) {
output += '<TD><IMG SRC = "images/d.gif" WIDTH = 4 HEIGHT = 4 BORDER = 0></TD><TD><A HREF = "javascript:go(1,' + x + ',' + y + ');" onFocus = "blur();">';
output += '<IMG SRC = "images/h0.gif" NAME = "hx' + x + 'hy' + y + '" WIDTH = 38 HEIGHT = 4 ALT = "" BORDER = 0></A></TD>';
}
output += '<TD><IMG SRC = "images/d.gif" WIDTH = 4 HEIGHT = 4 BORDER = 0></TD></TR><TR>'
for (var x = 1; x <= maxwidth; x ++ ) {
output += '<TD><A HREF = "javascript:go(2,' + x + ',' + y + ');" onFocus = "blur();">';
output += '<IMG SRC = "images/v0.gif" NAME = "vx' + x + 'vy' + y + '" WIDTH = 4 HEIGHT = 38 ALT = "" BORDER = 0></A></TD>';
output += '<TD><IMG SRC = "images/p0.gif" NAME = "x' + x + 'y' + y + '" WIDTH = 38 HEIGHT = 38 ALT = "" BORDER = 0></TD>';
}
var x = maxwidth + 1
output += '<TD><A HREF = "javascript:go(2,' + x + ',' + y + ');" onFocus = "blur();">';
output += '<IMG SRC = "images/v0.gif" NAME = "vx' + x + 'vy' + y + '" WIDTH = 4 HEIGHT = 38 ALT = "" BORDER = 0></A></TD>';
output += '</TR>';
}
output += '<TR>'
for (var x = 1; x <= maxwidth; x ++ ) {
output += '<TD><IMG SRC = "images/d.gif" WIDTH = 4 HEIGHT = 4 BORDER = 0></TD><TD><A HREF = "javascript:go(1,' + x + ',' + y + ');" onFocus = "blur();">';
output += '<IMG SRC = "images/h0.gif" NAME = "hx' + x + 'hy' + y + '" WIDTH = 38 HEIGHT = 4 ALT = "" BORDER = 0></A></TD>';
}
output += '<TD><IMG SRC = "images/d.gif" WIDTH = 4 HEIGHT = 4 BORDER = 0></TD></TR><TR><TD COLSPAN = ';
spanthis = (maxheight*2) + 1;
output += spanthis;
output += '> </TD></TR></TABLE></TD>';
// create the form for feedback to user and also a "new game" button
output += '<TD VALIGN = top><FORM NAME = "squares"><TABLE CELLPADDING = 2 CELLSPACING = 0 BORDER = 0 BGCOLOR = "#0193ff">';
output += '<TR><TD ALIGN = center><FONT FACE = "Arial, Helvetica, sans-serif" SIZE = 2>Player 1</FONT></TD>';
output += '<TD ALIGN = center><FONT FACE = "Arial, Helvetica, sans-serif" SIZE = 2>Player 2</FONT></TD></TR>';
output += '<TR><TD ALIGN = center><IMG SRC = "images/p1.gif" WIDTH = 38 HEIGHT = 38 NAME = "play1" ALT = " Player 1 " VSPACE = 2" BORDER = 0><BR></TD>';
output += '<TD ALIGN = center><IMG SRC = "images/p0.gif" WIDTH = 38 HEIGHT = 38 NAME = "play2" ALT = " Player 2 " VSPACE = 2" BORDER = 0><BR></TD></TR>';
output += '<TR><TD ALIGN = center><INPUT TYPE = "text" NAME = "score1" SIZE = "3" VALUE = 0 onFocus = "blur();"></TD>';
output += '<TD ALIGN = center><INPUT TYPE = "text" NAME = "score2" SIZE = "3" VALUE = 0 onFocus = "blur();"></TD></TR>';
output += '<TR><TD COLSPAN = 2 ALIGN = center><BR><INPUT TYPE = "button" VALUE = " New Game " onClick = "newGame();">';
output += '<BR> </TD></TR><TR><TD COLSPAN = 2 BGCOLOR = "#0193ff" ALIGN = center>';
output += '<BR><BR><FONT FACE = "Arial, Helvetica, sans-serif" SIZE = 1>';
output += '<BR></FONT></TD></TR>';
output += '</TABLE></FORM></TD>';
output += '</TR></TABLE>';
document.write(output);
preload();
// End -->
</script>
Copy the following code and paste it into the body section of goofy1.html.
<script>
// CREDITS:
// Snowmaker Copyright (c) 2003 Peter Gehrig. All rights reserved.
// Distributed by http://www.hypergurl.com
// Permission given to use the script provided that this notice remains as is.
// Set the number of snowflakes (more than 30 - 40 not recommended)
var snowmax=35
// Set the colors for the snow. Add as many colors as you like
var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD")
// Set the fonts, that create the snowflakes. Add as many fonts as you like
var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS")
// Set the letter that creates your snowflake (recommended:*)
var snowletter="*"
// Set the speed of sinking (recommended values range from 0.3 to 2)
var sinkspeed=0.6
// Set the maximal-size of your snowflaxes
var snowmaxsize=22
// Set the minimal-size of your snowflaxes
var snowminsize=8
// Set the snowing-zone
// Set 1 for all-over-snowing, set 2 for left-side-snowing
// Set 3 for center-snowing, set 4 for right-side-snowing
var snowingzone=1
///////////////////////////////////////////////////////////////////////////
// CONFIGURATION ENDS HERE
///////////////////////////////////////////////////////////////////////////
// Do not edit below this line
var snow=new Array()
var marginbottom
var marginright
var timer
var i_snow=0
var x_mv=new Array();
var crds=new Array();
var lftrght=new Array();
var browserinfos=navigator.userAgent
var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
var ns6=document.getElementById&&!document.all
var opera=browserinfos.match(/Opera/)
var browserok=ie5||ns6||opera
function randommaker(range) {
rand=Math.floor(range*Math.random())
return rand
}
function initsnow() {
if (ie5 || opera) {
marginbottom = document.body.clientHeight
marginright = document.body.clientWidth
}
else if (ns6) {
marginbottom = window.innerHeight
marginright = window.innerWidth
}
var snowsizerange=snowmaxsize-snowminsize
for (i=0;i<=snowmax;i++) {
crds[i] = 0;
lftrght[i] = Math.random()*15;
x_mv[i] = 0.03 + Math.random()/10;
snow[i]=document.getElementById("s"+i)
snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
snow[i].size=randommaker(snowsizerange)+snowminsize
snow[i].style.fontSize=snow[i].size
snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
snow[i].sink=sinkspeed*snow[i].size/5
if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
snow[i].posy=randommaker(6*marginbottom-marginbottom-6*snow[i].size)
snow[i].style.left=snow[i].posx
snow[i].style.top=snow[i].posy
}
movesnow()
}
function movesnow() {
for (i=0;i<=snowmax;i++) {
crds[i] += x_mv[i];
snow[i].posy+=snow[i].sink
snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
snow[i].style.top=snow[i].posy
if (snow[i].posy>=marginbottom-6*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
snow[i].posy=0
}
}
var timer=setTimeout("movesnow()",50)
}
for (i=0;i<=snowmax;i++) {
document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
}
if (browserok) {
window.onload=initsnow
}
</script>
Paste the following code into the body section of goofy2.html.
<script>
//******************************************
//* Cross browser cursor trailer script- By Brian Caputo (bcaputo@icdc.com)
//* Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code
//* Modified Dec 31st, 02' by DD. This notice must stay intact for use
//******************************************/
function closeContainer(){
document.write((A || B)?"</div>":"</layer>")
}
function getXpos(N){
if (A)
return parseInt(document.getElementById(N).style.left)
else if (B)
return parseInt(B[N].style.left)
else
return C[N].left
}
function getYpos(N){
if (A)
return parseInt(document.getElementById(N).style.top)
else if (B)
return parseInt(B[N].style.top)
else
return C[N].top
}
function moveContainer(N,DX,DY){
c=(A)? document.getElementById(N).style : (B)? B[N].style : (C)? C[N] : "";
if (!B){
rightedge=window.innerWidth-T1[1]-20
bottomedge=window.pageYOffset+window.innerHeight-T1[2]
}
c.left=Math.min(rightedge, DX+offsetx);
c.top=Math.min(bottomedge, DY+offsety);
}
function cycle(){
//if (IE5)
if (document.all&&window.print){
ie5fix1=document.body.scrollLeft;
ie5fix2=document.body.scrollTop;
}
for (i=0;i<(nos-1);i++){
moveContainer("CUR"+i,getXpos("CUR"+(i+1)),getYpos("CUR"+(i+1)))
}
}
function newPos(e){
moveContainer("CUR"+(nos-1),(B)?event.clientX+ie5fix1:e.pageX+2,(B)?event.clientY+ie5fix2:e.pageY+2)
}
function getedgesIE(){
rightedge=document.body.clientWidth-T1[1]
bottomedge=document.body.scrollHeight-T1[2]
}
if (B){
window.onload=getedgesIE
window.onresize=getedgesIE
}
Paste the following code the head section of goofy3.html.
<style type="text/css">
/* Circle Text Styles */
#outerCircleText {
/* Optional - DO NOT SET FONT-SIZE HERE, SET IT IN THE SCRIPT */
font-style: italic;
font-weight: bold;
font-family: 'comic sans ms', verdana, arial;
color: #000;
/* End Optional */
/* Start Required - Do Not Edit */
position: absolute;top: 0;left: 0;z-index: 3000;cursor: default;}
#outerCircleText div {position: relative;}
#outerCircleText div div {position: absolute;top: 0;left: 0;text-align: center;}
/* End Required */
/* End Circle Text Styles */
</style>
Paste the following code the head section of goofy3.html.
<script type="text/javascript">
/* Circling text trail- Tim Tilton
Website: http://www.tempermedia.com/
Visit: http://www.dynamicdrive.com/ for Original Source and tons of scripts
Modified Here for more flexibility and modern browser support
Modifications as first seen in http://www.dynamicdrive.com/forums/
username:jscheuer1 - This notice must remain for legal use
*/
;(function(){
// Your message here (QUOTED STRING)
var msg = "This is a pretty goofy use of JavaScript!";
/* THE REST OF THE EDITABLE VALUES BELOW ARE ALL UNQUOTED NUMBERS */
// Set font's style size for calculating dimensions
// Set to number of desired pixels font size (decimal and negative numbers not allowed)
var size = 24;
// Set both to 1 for plain circle, set one of them to 2 for oval
// Other numbers & decimals can have interesting effects, keep these low (0 to 3)
var circleY = 0.75; var circleX = 2;
// The larger this divisor, the smaller the spaces between letters
// (decimals allowed, not negative numbers)
var letter_spacing = 5;
// The larger this multiplier, the bigger the circle/oval
// (decimals allowed, not negative numbers, some rounding is applied)
var diameter = 10;
// Rotation speed, set it negative if you want it to spin clockwise (decimals allowed)
var rotation = 0.4;
// This is not the rotation speed, its the reaction speed, keep low!
// Set this to 1 or a decimal less than one (decimals allowed, not negative numbers)
var speed = 0.3;
In Dreamweaver create a new JavaScript document named jseyes.js.
Copy the following code and paste it into jseyes.js.
/* jseyes.js
The classic Xeyes in JavaScript
(c) PROPIX Ltd, Written by Pintér Gábor
Székesfehérvár, Kriványi u. 15.
H-8000, HUNGARY
Email: propix@freemail.hu
Web: http://www.propix.hu
Revisions:
V1.0 10/14/2001 Original release
Usage:
1. Include this file from the head of your page
2. Define parameters or accept the defaults
3. Insert the image
This script requires Internet Explorer 5+ or Nescape Navigator 6+! In other browsers it does nothing.
1. Include jseyes.js from the head of your page
Insert the following line into the head of your page:
<script src="jseyes.js"></script>
2. Define parameters
You can accept the defaults or assign new values to these variables:
jseyesimg="jseyes.gif"
The main image. Please do not edit.
jseyeimg="jseyeblue.gif"
The image of the eye. Must be a 21x29 solid ellipse with transparent background.
4. Insert the image
Call jseyes() where you want to see the image:
<script>
jseyes();
</script>
Or call jseyes(x, y) to show the image at absolute position:
<script>
jseyes(100,100);
</script>
// Defaults
var jseyesimg="images/jseyes.gif";
var jseyeimg="images/jseyeblue.gif";
var jseyeslink="http://www.wsabstract.com";
// Internal
var jseyeso=null, jseye1=null, jseye2=null;
// Browser detection
// Global variables
var browserversion=0.0;
var browsertype=0; // 0: unknown; 1:MSIE; 2:NN
// Return true if MSIE or NN detected
function browserdetect() {
var agt= navigator.userAgent.toLowerCase();
var appVer= navigator.appVersion.toLowerCase();
browserversion= parseFloat(appVer);
var iePos= appVer.indexOf('msie');
if (iePos!=-1) browserversion= parseFloat(appVer.substring(iePos+5, appVer.indexOf(';',iePos)));
var nav6Pos = agt.indexOf('netscape6');
if (nav6Pos!=-1) browserversion= parseFloat(agt.substring(nav6Pos+10))
browsertype= (iePos!=-1) ? 1 : (agt.indexOf('mozilla')!=-1) ? 2 : 0;
return(browsertype>0);
}
browserdetect();
// General utils
// Find object by name or id
function jseyesobj(id) {
var i, x;
x= document[id];
if (!x && document.all) x= document.all[id];
for (i=0; !x && i<document.forms.length; i++) x= document.forms[i][id];
if (!x && document.getElementById) x= document.getElementById(id);
return(x);
}
In Dreamweaver create a new JavaScript document named simpleSwap.js.
Copy the following code and paste it into simpleSwap.js.
function SimpleSwap(el,which) {
el.src=el.getAttribute(which || "origsrc");
}
function SimpleSwapSetup() {
var x = document.getElementsByTagName("img");
for (var i=0;i<x.length;i++){
var oversrc = x[i].getAttribute("oversrc");
if (!oversrc) continue;
// preload image -
// comment the next two lines to disable image pre-loading
x[i].oversrc_img = new Image();
x[i].oversrc_img.src=oversrc;
// set event handlers
x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
x[i].onmouseout = new Function("SimpleSwap(this);");
// save original src
x[i].setAttribute("origsrc",x[i].src);
}
}
var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}
//variableslide[x]=["path to image", "OPTIONAL link for image", "OPTIONAL text description (supports HTML tags)"]
variableslide[0]=['images/slide_show_1.jpg', '', '']
variableslide[1]=['images/slide_show_2.jpg', '', 'Help! I\'ve fallen and I can\'t get up.']
variableslide[2]=['images/slide_show_3.jpg', '', '']
variableslide[3]=['images/slide_show_4.jpg', '', '']
variableslide[4]=['images/slide_show_5.jpg', '', '']
//configure the below 3 variables to set the dimension/background color of the slideshow
var slidewidth='500px' //set to width of LARGEST image in your slideshow
var slideheight='364px' //set to height of LARGEST iamge in your slideshow, plus any text description
var slidebgcolor='#FFFF66'
//configure the below variable to determine the delay between image rotations (in miliseconds)
var slidedelay=3000
////Do not edit pass this line////////////////
var ie=document.all
var dom=document.getElementById
for (i=0;i<variableslide.length;i++){
var cacheimage=new Image()
cacheimage.src=variableslide[i][0]
}
var currentslide=0
function rotateimages(){
contentcontainer='<center>'
if (variableslide[currentslide][1]!="")
contentcontainer+='<a href="'+variableslide[currentslide][1]+'">'
contentcontainer+='<img src="'+variableslide[currentslide][0]+'" border="0" vspace="3">'
if (variableslide[currentslide][1]!="")
contentcontainer+='</a>'
contentcontainer+='</center>'
if (variableslide[currentslide][2]!="")
contentcontainer+=variableslide[currentslide][2]
if (document.layers){
crossrotateobj.document.write(contentcontainer)
crossrotateobj.document.close()
}
else if (ie||dom)
crossrotateobj.innerHTML=contentcontainer
if (currentslide==variableslide.length-1) currentslide=0
else currentslide++
setTimeout("rotateimages()",slidedelay)
}
if (ie||dom)
document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>')
function start_slider(){
crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub
if (document.layers)
document.slidensmain.visibility="show"
rotateimages()
}
if (ie||dom)
start_slider()
else if (document.layers)
window.onload=start_slider