<HTML>
<HEAD>
  <TITLE>The Java Script Image Rollover Builder</TITLE>
     <META NAME=KEYWORDS CONTENT="JavaScript, Java, rollover, mouseover, mouseout, applet,
           programming, OOP, object, image, programming tools, automatic">
     <META NAME=DESCRIPTION CONTENT="JavaScript automatic code generator for image rollovers.">
<!-- The Java Script code should appear in the <HEAD> section. -->
  <SCRIPT LANUAGE="JavaScript">
 
 /* This JavaScript and HTML code was automatically generated using
    the "Enhance Your Image" builder from America's Town Square.
 
          http://usats.com/rollover
 
    Copyright 1998 by America's Town Square, all rights reserved.
    This document may be modified or enhanced provided this entire
    notice remains intact. Please report comments, bugs or
    suggestions to urb@usats.com
 */
 
 // Hide from older browsers
 
 // Does this version of Java Script support images objects?
    AcceptableBrowser = document.images;
	

    Height = 18;  Width = 240; // Image dimensions
    if (AcceptableBrowser) {
    // The name of the variable with the "Dn" suffix must match
    // the first ReplaceImage parameter in the onMouseOver call
    // The name of the variable with the "Up" suffix must match
    // the first ReplaceImage parameter in the onMouseOut call
     BuildDn    = new Image(Height, Width);
     BuildDn.src = "build-dn.gif"; // mouse over graphic location
     BuildUp    = new Image(Height, Width);
     BuildUp.src = "build-up.gif";  // mouse out graphic location
 
     ExplainDn    = new Image(Height, Width);
     ExplainDn.src = "explain-dn.gif"; // mouse over graphic location
     ExplainUp    = new Image(Height, Width);
     ExplainUp.src = "explain-up.gif";  // mouse out graphic location
 
 } // if (AcceptableBrowser)

 function ReplaceImage(ImageObject, Subscript, StatusMessage) {
 /* Function ReplaceImage requires three parameters:
    ImageObject, the variable name assigned to the image object above.
      This parameter defines the new (replacement) image.
     Subscript, the symbolic name assigned to the NAME parameter in the IMG tag.
      This parameter determines which image to replace.
    StatusMessage, the string to appear in the status bar. If current
      contents of status bar is to be cleared, pass a single blank.
      If a null field is passed, nothing is changed in the status bar.
*/
   if (AcceptableBrowser){
     Graphic = eval(ImageObject + ".src");
     document.images[Subscript].src = Graphic;
   }       //end if (AcceptableBrowser)
   if (StatusMessage) { // if status bar message was passed
            window.defaultStatus = StatusMessage;
   }    // end if (StuatusMessage)
   return true;
 } // end function ReplaceImage(ImageObject,number)
 
 // -->
 </SCRIPT>	 
</HEAD>
<!-- This was http://builder.cnet.com/Programming/Kahn/012898/ -->
<BODY BGCOLOR="#8B0518" TEXT="FFFFFF" LINK="FFFF55" VLINK="LIME">
<B>
<A NAME="top"></A>
<CENTER>

<!-- Insert the following HTML code in the <BODY> section at    -->
 <!-- the point where the rollover images are to be displayed.   -->
 <!-- If images are to abutt with no space between images, there -->
<!-- should be no spaces or carriage return between the         -->
 <!-- following: </A><A HREF= and return true;"><IMG             -->
<TABLE BORDER="3" CELLSPACING="0" WIDTH="492" CELLPADDING="0"  BGCOLOR="#8080FF">
  <TR>
    <TD BGCOLOR="#8080FF"><STRONG><CENTER>
	<TABLE><TR><TD><IMG SRC="../graphics/ats-sm.gif"></TD>
	<TD><CENTER>
      <FONT FACE="Arial" SIZE="5" COLOR="#FFFFFF">America's Town Square</FONT>
      <FONT FACE="Arial" SIZE="2" COLOR="#FFFFFF">
      presents</FONT><BR>
      <FONT FACE="Arial" SIZE="6" COLOR="RED">Enhance</FONT>
      <FONT FACE="Arial" SIZE="5" COLOR="#FFFFFF">Your Image</FONT></CENTER></TD></TR></TABLE>
</CENTER></STRONG></TD></TR>
<TR>
<TD>
  <A HREF="condition.html" onMouseOver="ReplaceImage('BuildDn','Build','Inhance my image now!');
      return true"onMouseOut="ReplaceImage('BuildUp','Build',' ');return true">
	  <IMG SRC="build-up.gif" ALT="Build" BORDER="0" WIDTH="240"
	  HEIGHT="18" NAME="Build"></A><A HREF="explain.html" onMouseOver="ReplaceImage('ExplainDn','Explain','Exmplain how rollovers work'); return true" onMouseOut="ReplaceImage('ExplainUp','Explain',' '); return true">  <IMG SRC="explain-up.gif" ALT="Explain"
 BORDER=0 WIDTH=240 HEIGHT=18 NAME="Explain"></A></TD></TR>
 </TABLE>
<FONT SIZE="+1" COLOR="RED">
The bottom two images above are rollovers, point to them to see the change.
</FONT>
</CENTER>
<A HREF="#examples"><H2><FONT COLOR="RED">Outstanding Examples Of Image Rollovers</FONT></H2></A>
<IMG SRC="../graphics/blank.gif" WIDTH=40 HEIGHT=1 BORDER=0 ALT="Tab">
<FONT SIZE="+3" COLOR="LIME">W</FONT>ho among us couldn't use a little image building?
Java Script image rollovers offer an increasingly popular
method for adding a "we're cool" look to Web pages. Talk about image building!
This corner of the "Square" automatically
builds a ready-to-run Java Script, after you fill in the blanks, the script is e-mailed to you.
In addition, we will also help you understand the Java Script code if you're into programming
types of things.
<P>
If you're the type of person who reads instructions only after all else fails,
go immediately to the 
<A HREF="condition.html">Image Builder</A> which automatically generates Java Script
code based on your specifications.

<H2><FONT COLOR="LIME">There's Good News and Bad News</FONT></H2>

<IMG SRC="../graphics/blank.gif" WIDTH=40 HEIGHT=1 BORDER=0 ALT="Tab">
<FONT SIZE="+3" COLOR="LIME">T</FONT>he bad news is not all browser support the
image rollovers effect. The browsers support this
Java Script Version 1.1 enhancement are Netscape 3.0, Opera, and later and Microsoft's
Internet Explorer 4.0 and later. The good news is only the rollover effect will be lost with
Java Script 1.1 unaware browsers.
If a user's browser doesn't support Java Script's image objects, the original images are display
but there is no mouse over image replacement.
<P>
Java Script's rollovers treat images as objects accessible by name and possessing properties
changeable when an event, such as passing a mouse over a specified area, is initiated by
a user.
<P>
Let's use the table at the top of this page as an example to explain the creation of a Java
Script rollover.
<P> 
The first step in the script is image rollovers functionality detection.
I prefer to detect once and set a variable to "true" or "false." For a detailed discussion
of detection by function, rather than by browser type, see the
<A HREF="detection.html">
Java Script Detection of Objects and Methods</A> tutorial.
<P>
<TABLE WIDTH="400" BORDER="2">
  <TR BGCOLOR="#EAFFFF">
  <TD WIDTH="400"><B>
<FONT COLOR="BLACK">
<PRE>

  // Does browser support image objects?
   AcceptableBrowser = document.images; 
 
  // Subsequent testing uses the variable,
   if (AcceptableBrowser) {
   } # End of if (AcceptableBrowser)
   
</PRE>
</FONT>
</B></TD>
</TR>
</TABLE>
<P>
Rollovers treat images as objects accessible by name and with properties that
can be changed on the fly. The first step in the script's creation (in the head section
of the HTML document) is preloading required images. First, a little Object Oriented Programming
(OOP) speak. Images are preloaded and defined using
a series of <FONT COLOR="RED">Image()</FONT> objects. There are two images, and two Image()
objects, for each displayed image. One is the image normally displayed and the other is the
images that appears when the mouse is passed over the original image. The replaces image
does not have to be in the same area as the original image.
<P>
Now, a little more OOP speak. The <FONT COLOR="RED">new</FONT> constructor sets the image
objects using <FONT COLOR="RED">src</FONT> properties for the on and off versions of the image.
To illustrate, the left rollover images in the table at the top of the page is called "Build"
and will be explained shortly. Things get real hairy real fast if you don't use some type of 
naming conventions. The "Image Builder" generator uses a Name in the HTML section that 
describes the action. I prefer to use paired graphics with a file name suffixed by "-up" and
"-dn" to indicate up for the normal state and down when the mouse is over the graphics. Here is 
what the JS codes is for the first graphic.
<P>
<TABLE WIDTH="550" BORDER="2">
  <TR BGCOLOR="#EAFFFF">
  <TD WIDTH="550"><B>
<FONT COLOR="BLACK">
<PRE>

   Height = 18;  Width = 240; // Image dimensions
   if (AcceptableBrowser) {
     BuildDn     = new Image(Height, Width);
     BuildDn.src = "build-dn.gif"; // mouse over graphic location
     BuildUp     = new Image(Height, Width);
     BuildUp.src = "build-up.gif";  // mouse out graphic location
	 
	 // Additional image declarations
	 
   } # End of if (AcceptableBrowser)
   
</PRE>
</FONT>
</B></TD>
</TR>
</TABLE>
<P>
This code assumes all images are the same size, if not, hard code the image dimensions
in the Image() deceleration. If you are going to use the "Image Builder" generator, it is
assumed you have selected two suffixes for the rollover image pair.
<P>
In this example, the value of the <FONT COLOR="RED">BuildDn</FONT>
object's <FONT COLOR="RED">src</FONT> property is set to
<FONT COLOR="RED">build-dn.gif</FONT> which is the image appearing on a
mouseover event. (More OOP speak.) The value of the
<FONT COLOR="RED">BuildUp</FONT> object's source property, the mouse out event, is
set to <FONT COLOR="RED">build-up.gif</FONT>. If the graphics are not
in the same directory as the JS codes, use a relative path preceding the file name.
<P>
Let's skip ahead to the code appearing in the &lg;BODY&gt; section. The main code determines
the original placement of the image and the name of the object.
Additionally, Java Script function calls are specified for
the mouse over (onMouseOver) and mouse off (onMouseOut) events.
Specify the graphic in the HTML of the page using the same source as
the <FONT COLOR="RED">----Up.src</FONT> because the normal position for
the mouse is "off" he image.
<P>
Let's look at the actual code and then pick it apart:
<P>
<TABLE BORDER="2">
  <TR BGCOLOR="#EAFFFF">
  <TD WIDTH="550">
<B>
<FONT COLOR="BLACK">
<PRE>

    &lt;A HREF="condition.html"
	  onMouseOver="ReplaceImage('BuildDn','Build',
	  'Inhance my image now!');return true"
	  onMouseOut="ReplaceImage('BuildUp','Build',' ');
      return true"&gt;
      &lt;IMG SRC="build-up.gif" ALT="Build" BORDER="0" WIDTH="240"
	    HEIGHT="18" NAME="Build"&gt;&lt;/A&gt;

</PRE>
</FONT></B></TD>
</TR>
</TABLE>
<P>
First, a URL Notice that is activated if the image is click.
Next, there is only one function --
<FONT COLOR="RED">ReplaceImage</FONT> -- that performs all the work. Lastly, the actual
&lt;IMG&gt; code for the normal image. The only new attribute is the NAME parameter.
<P>
The ReplaceImage function requires three parameters. From left to right, the variable specified`
in the Image() object, the name from the NAME attribute in the &lt;IMG&gt; tag. Lastly,
the text to appear in the status bar. This last parameter is not required, it's an added
feature.
<P>
The use of the first two parameters simplifies the overall construction of the scripts. 
I believe simpler is always better since it's easier to code and much easier to understand.
Many JS rollovers use a different function for each function, or, one function for onMouseOver 
and another for onMouseOut events.
<P>
Finally, here is the code for the image replacements:
<P>
<TABLE BORDER="2">
<TR BGCOLOR="#EAFFFF">
<TD WIDTH="560"><B>
<FONT COLOR="BLACK">
<PRE>

  function ReplaceImage(ImageObject, Subscript, StatusMessage) {
    if (AcceptableBrowser){
       Graphic = eval(ImageObject + ".src");
       document.images[Subscript].src = Graphic;
    }       //end if (AcceptableBrowser)
    if (StatusMessage) { // if status bar message was passed
             window.defaultStatus = StatusMessage;
    }    // end if (StuatusMessage)
      return true;
  } // end function ReplaceImage(ImageObject,Subscript,StatusMessage)

</PRE>
</FONT>
</B></TD>
</TR>
</TABLE>
<P>
When the <FONT COLOR="RED">onMouseOver</FONT> or <FONT COLOR="RED">onMouseOut</FONT>
event handlers calls <FONT COLOR="RED">ReplaceImage()</FONT>, the
function executes -- provided the user's browser support JS rollovers.
<P>
The statements:
<P>
<TABLE WIDTH="400" BORDER="2">
<TR BGCOLOR="#EAFFFF">
  <TD WIDTH=400>
  <B>
<FONT COLOR="BLACK">
<PRE>

    Graphic = eval(ImageObject + ".src");
    document.images[Subscript].src = Graphic;

</PRE>
</FONT>
</B></TD>
</TR>
</TABLE>
<P>
starts by assigning the first passed parameter, suffixed with ".src" to the variable Graphic.
Next the second passed parameter -- the variable assigned in the NAME parameter -- is used
as a subscript in the images array and the value assigned to the bariable Graphic is used to
replace the existing image.
<P>
If you're not used to dot notation the above may seem strange. If you're not used to 
programming, the entire thing may seenm strange!
<P>
I've tried to make the code as simple as possible and it is, hopefully, fairly
straightforward. Just remember, the code in the HEAD section defines and preloades the 
images. The function ReplaceImage() is also defined in the HEAD section. The BODY section
has the actual placement of the initial image and the code that is executed when events happen.
<P>
One last point. If you want images to appear side-by-side, with no space, there must be nothing 
between the closing &lt;/A&gt; tag and the next &lt;A HREF tag.

<H2><FONT COLOR="LIME">Summary</FONT></H2>

You can do some really sharp things with Java Script image rollovers. Take a look at some
of the examples below. When you have an idea of where you want to do, use the
ATS <FONT SIZE="+2" COLOR="RED">Image Builder</FONT> till your hearts content.
<P>
<A HREF="condition.html">Build me an image now!</A>
<P>

<CENTER>
<A NAME="examples">
<H2><FONT COLOR="LIME">Outstanding Examples of Image Rollovers</FONT></H2></A>
</CENTER>
<UL>
    <LI><A HREF="http://www.mos.org/leonardo/">
        Leonardo Exhibit</A> at the Boston Museum of Science. This is the most 
	    creative use of graphics roll overs I've seen. Make sure you move the 
        mouse between his eyes.
<P>
    <LI><A HREF="http://www.rdthanksgiving.com/">Readers Digest Thanksgiving Page</A>	
        Outstanding graphics effect with roll overs.
<P>
    <LI><A HREF="http://www.superconnect.com/wordsmit/">WordSmith Workshop</A>
	    Fun, innovative, and highly effective. If you write for public consumption
		don't miss this site!
<P>		
    <LI><A HREF="http://www.xchange.com/corporatex/services/index.html">
        Nice Graphics Menu</A>	It uses windons popups.
<P>	
    <LI><A HREF="http://www.e-media-c.com/">E-Media-C</A> Very interesting use of
	    rollovers and animation. Move mouse over Nav links.
<P>
    <LI><A HREF="http://www.creativesupport.com/surfboard/">Surf's Up</A> from Creative Support.
	    Great effect.
<P>
    <LI><A HREF="http://dabcc-www.nmsu.edu/~chad/Work/">
	    Chad Zimmerman's Desert Inferno</A> Highly useful links in addition to
		a super rollover addaption.
<P>
    <LI><A HREF="http://www.fish4it.com/">Fish for It</A> Fun front end for
	    random link generator. Great rollovers.
<P>		
    <LI><A HREF="http://builder.cnet.com/web.builder/">CNET Builders Conference</A> page. Another
         good example of using image pieces.
<P>
    <LI><A HREF="http://www.artuframe.com/">Art U Frame</A>The navigational rollover buttons
	     on the left are outstanding.
<P>
    <LI><A HREF="http://dangerwillrobinson.lycos.com/lis_bot_v2.html">The Lost in Space</A>
	     page from Lycos.		 
</UL>
<P>
<CENTER>
<IMG SRC="../graphics/gold-bar.gif" WIDTH=597 HEIGHT=11 BORDER=0 ALT="Gold Bar">
</CENTER>
<P>

<CENTER>
<TABLE>
  <TR>
    <TD><IMG SRC="../graphics/scribe.gif"><TD>
    <TD><CENTER><B>Please subscribe to the 
        <A HREF="../freestuf/atsnews.shtml">free ATS Newsletter</A> 
         so we can keep you<BR>
         up to date with our "free stuff", special offers, and other goodies.
        <B></CENTER></TD>
  </TR>
</TABLE>
<B>
<P>
  <IMG SRC="../graphics/home.gif">
  <A HREF="../index.shtml">Back to the ATS Home Page</A><P>
<TABLE>
  <TR>
    <TD><IMG SRC="../graphics/a-pencil.gif"><TD>
    <TD><B>Please sign our<A HREF="../guests/index.shtml">
        self-updating guestbook</A><P>
        How about some <A HREF="../freestuf/index.shtml">
        free stuff from ATS?</A></B></TD>
  </TR>
</TABLE>    
<P>
   Please send our <A HREF="mailto:Webmaster@usats.com">
   crotchety Webmaster</A> some mail.
   <IMG SRC="../graphics/tab.gif"><IMG ALIGN=CENTER SRC="../graphics/sendmail.gif"><BR> 
   <FONT COLOR=RED>Copyright &copy;1996-98 America's Town Square</FONT><BR>
   15 Hunter Drive<BR>
   Tuckerton, NJ 08087<BR>
   (609) 294-0320
 
  </BODY>
</HTML>







