document.write('<div class="javascript" style="font-family: monospace;"><span style="color: #003366; font-weight: bold;">var</span> fadeElement =<br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; initialise: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Set initial opacity for the object:</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fadeElement.<span style="color: #006600;">setOpacity</span><span style="color: #66cc66;">&#40;</span>obj, <span style="color: #CC0000;">20</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Add the object to objArray:</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fadeElement.<span style="color: #006600;">objArray</span>.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Initialise the fadeState property:</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">fadeState</span> = <span style="color: #3366CC;">\'\'</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">onmouseover</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">fadeState</span> = <span style="color: #3366CC;">\'fadingIn\'</span>; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">onmouseout</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">fadeState</span> = <span style="color: #3366CC;">\'fadingOut\'</span>; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Set a timer to call the fader method:</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!window.<span style="color: #006600;">fadeTimer</span><span style="color: #66cc66;">&#41;</span> window.<span style="color: #006600;">fadeTimer</span> = setInterval<span style="color: #66cc66;">&#40;</span>fadeElement.<span style="color: #006600;">fader</span>, <span style="color: #CC0000;">50</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; setOpacity: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>obj, opacity<span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">style</span>.<span style="color: #006600;">filter</span> = <span style="color: #3366CC;">&quot;alpha(opacity=&quot;</span> + opacity + <span style="color: #3366CC;">&quot;)&quot;</span>; <span style="color: #009900; font-style: italic;">// For IE filter to work, obj MUST have layout</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">style</span>.<span style="color: #006600;">KHTMLOpacity</span> = opacity / <span style="color: #CC0000;">100</span>; <span style="color: #009900; font-style: italic;">// Safari and Konqueror</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">style</span>.<span style="color: #006600;">MozOpacity</span> = opacity / <span style="color: #CC0000;">100</span>; <span style="color: #009900; font-style: italic;">// Old Mozilla and Firefox</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">style</span>.<span style="color: #006600;">opacity</span> = opacity / <span style="color: #CC0000;">100</span>; <span style="color: #009900; font-style: italic;">// CSS3 opacity for browsers that support it</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; fader: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Loop through all objects in objArray:</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i = <span style="color: #CC0000;">0</span>; i &lt; fadeElement.<span style="color: #006600;">objArray</span>.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> obj = fadeElement.<span style="color: #006600;">objArray</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> opacity = obj.<span style="color: #006600;">style</span>.<span style="color: #006600;">opacity</span> * <span style="color: #CC0000;">100</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Check if the current object is animated:</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>obj.<span style="color: #006600;">fadeState</span> == <span style="color: #3366CC;">\'fadingIn\'</span><span style="color: #66cc66;">&#41;</span> &amp;&amp; opacity &lt; <span style="color: #CC0000;">100</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fadeElement.<span style="color: #006600;">setOpacity</span><span style="color: #66cc66;">&#40;</span>obj, opacity + <span style="color: #CC0000;">10</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>obj.<span style="color: #006600;">fadeState</span> == <span style="color: #3366CC;">\'fadingOut\'</span><span style="color: #66cc66;">&#41;</span> &amp;&amp; opacity &gt; <span style="color: #CC0000;">20</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fadeElement.<span style="color: #006600;">setOpacity</span><span style="color: #66cc66;">&#40;</span>obj, opacity - <span style="color: #CC0000;">10</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; objArray: <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #009900; font-style: italic;">// This array stores each object passed to the script.</span><br />');
document.write('<span style="color: #66cc66;">&#125;</span></div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/77/1/" target="_blank">byteMyCode</a>.</div>');
