/***  (C)Scripterlative.com

S m a r t R o l l.

Pre-settable Latching Rollover Buttons with 2 or 3-State Operation, Pre-settable buttons and 
Optional Captioning.

 Info: http://scripterlative.com

 These instructions may be removed but not the above text.
 
 Please notify any suspected errors in this text or code, however minor.

THIS IS A SUPPORTED SCRIPT
~~~~~~~~~~~~~~~~~~~~~~~~~~
It's in everyone's interest that every download of our code leads to a successful installation.
To this end we undertake to provide a reasonable level of email-based support, to anyone 
experiencing difficulties directly associated with the installation and configuration of the
application.

Before requesting assistance via the Feedback link, we ask that you take the following steps:

1) Ensure that the instructions have been followed accurately.

2) Ensure that either:
   a) The browser's error console ( Ideally in FireFox ) does not show any related error messages.
   b) You notify us of any error messages that you cannot interpret.

3) Validate your document's markup at: http://validator.w3.org or any equivalent site.   
   
4) Provide a URL to a test document that demonstrates the problem.
 
Installation
~~~~~~~~~~~~
These instructions assume that an HTML document has been prepared, containing suitable image-based
navigation buttons surrounded by hyperlinks.
Each image placeholder must have a unique NAME or ID attribute.
Save this file or text as smartroll.js and copy it to a suitable folder relating to your web pages.
Within the <BODY> section of all documents that will use the script, at a point below the last
image in the document, insert the following:

<script type='text/javascript' src='smartroll.js'></script>

(If smartroll.js resides in a different folder, include the relative path)

Configuration
~~~~~~~~~~~~~
For each button group to be created, all that is required is a single call to the
function: SmartRoll.over, passing the required parameters.
Clear examples are given below.

The first parameter is the name given to the group of buttons. This can be any unique name.

All subsequent parameters are passed in groups of either two or three, depending upon whether
tristate buttons are to be created. In each parameter group, the parameters are as follows:

First parameter - the NAME or ID attribute of the first button's image placeholder or <img> tag.
Second parameter - the file name (and path if needed) of the 'hover' image file.
Third parameter - (If required) the file name (and path if needed) of the 'active' image file.

Note: The script detects the default image for each button, which is loaded by its <IMG> tag
      in the usual way.

Example 1. Create a group of five latching rollover buttons. The group is named 'buttonset1', the
image placeholders are named 'btn1' - 'btn5', the images to be used reside in the folder
'/images', the hovered-state images are named 'hov1.gif' - 'hov5.gif':

<script type='text/javascript'>

SmartRoll.over
(
'myButtons',
'btn1', '/images/hov1.gif',
'btn2', '/images/hov2.gif',
'btn3', '/images/hov3.gif',
'btn4', '/images/hov4.gif',
'btn5', '/images/hov5.gif'  // <- No comma after last parameter.
);

</script>

Example 2. Create another menu as above, but using tri-state buttons. The active-state images
are named 'act1.gif' - 'act5.gif':

<script type='text/javascript'>

SmartRoll.over
(
'buttonset1',
'btn1', '/images/hov1.gif', '/images/act1.gif',
'btn2', '/images/hov2.gif', '/images/act2.gif',
'btn3', '/images/hov3.gif', '/images/act3.gif',
'btn4', '/images/hov4.gif', '/images/act4.gif',
'btn5', '/images/hov5.gif', '/images/act5.gif'  // <- No comma after last parameter.
);

</script>

Note: In dual-state operation you will notice that when a button is latched, hovering another 
button returns the latched button temporarily to its default state. If you prefer this not to
happen, configure the group for tri-state operation specifying the same image for 'hover' and
'active'.

Pre-Setting A Button
~~~~~~~~~~~~~~~~~~~~
On page load, there are two ways to preset a button from each group into its active state.

1) SmartRoll.setButton( placeHolder ), where 'placeHolder' is the Name or ID attribute of the image 
   placeholder of the relevant button:
   
    SmartRoll.setButton( 'btn3' ); 
   
   NOTE. This function must be called after the creation of the button group to which it applies.  
     
   To set a button from another frame, pass a reference to the target frame as a second parameter:
   
    <script type='text/javascript' src='smartroll.js'></script>
    
    <script type='text/javascript'>
     SmartRoll.setButton( 'btn3', parent.frames['navbar'] ); 
    </script>
   
2) In the target URL, pass the parameter: SmartRoll=placeHolder, where placeHolder means the
   same as above.
   Example. On a literary website that displays the same button menu on each page, a hyperlink
   on the home page navigates to the fiction page, on which the 'fiction' button is to be set to
   its active state.
    
   <a href='fiction.htm?SmartRoll=fictBtn'>....

   To set more than one button (in different groups) in this way, repeat the parameter with
   the required values: href='fiction.htm?SmartRoll=fictBtn&SmartRoll=sciFi'
   
   Note: If you test this facility locally in the address bar, the URL should start 'file:///c:'
         rather than 'c:/', at least for Internet Explorer. 
         
Note: Method 1 overrides method 2.      

Making buttons 'de-latchable'
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any set of buttons can be configured such that if a latched button is clicked, it reverts to its
default state. This can be useful when using rollovers to control toggle operations, for instance 
showing and hiding one of a group of elements. To enable this functionality, in the function call
simply append '|UNLATCH' to the name of the relevant button group.

SmartRoll.over
(
'buttonset1|UNLATCH', .......
};

Emulating 'Radio' Buttons
~~~~~~~~~~~~~~~~~~~~~~~~~
To create the effect where a rollover button changes only when clicked, use tristate mode
and specify the same image for hover as the corresponding default image.

Captions
~~~~~~~~
The optional captioning facility is initialised separately, via a call to SmartRoll.setCaptions.
The parameters are as follows:

Parameter 1: The NAME of the button group.
Parameter 2: The ID of the element that will display the caption text (Usually a DIV or SPAN).
Parameter 3: The default caption text. To use the element's initial content, specify this as "".         

Subsequent parameters consist of Image identifier/Caption pairs, one for each button to be captioned.

Example 3. The button set created in Example 2 is to be used on a model shop's website. It will
be assigned captions that are to appear in a span whose ID is 'captionLine'.

SmartRoll.setCaptions
(
'myButtons', 'captionLine', 'Welcome to Crashwell Models',
'btn1', 'Powered aircraft, ready-to-fly and in kit form.',
'btn2', 'A comprehensive range of glow and diesel aero engines.',
'btn3', 'Radio sets and accessories from the world\'s leading manufacturers.',
'btn4', 'Field Boxes, Electric Starters, Starter Batteries, Electric Fuel Pumps etc',
'btn5', 'Our new marine section has an exciting collection of water-borne models' 
);

NOTES
~~~~~
1) For each captioned button set, the call to SmartRoll.setCaptions must be made after the
   corresponding call to SmartRoll.over.
   
2) If you wish to use apostrophes within caption text, precede them with a backslash: \'

3) Multiple button sets may share the same caption element. When doing this, it may be
   better to specify the default caption text as "" for all sets.

Troubleshooting
~~~~~~~~~~~~~~~
As always, ensure that the JavaScript console displays no error messages pertinent to your pages.
The encapsulated construction of this script, removes all risk of possible conflict with variables
from any other scripts in the document.
The most likely cause of trouble will be syntax errors in the function parameters.
Ensure that the example syntax has been followed exactly. It may be advisable to configure for just
two or three buttons initially.
   
Mouse Events
~~~~~~~~~~~~
The mouse event handlers generated by this script, will be appended to any created by 
previously-loaded scripts or embedded statements. For this reason, try to load this script after
any other scripts that are known to use mouse events.

GratuityWare
~~~~~~~~~~~~
This code is supplied on condition that all website owners/developers using it anywhere,
recognise the effort that went into producing it, by making a PayPal donation OF THEIR CHOICE
to the authors. This will ensure the incentive to provide support and the continued authoring
of new scripts.

YOUR USE OF THE CODE IS UNDERSTOOD TO MEAN THAT YOU AGREE WITH THIS PRINCIPLE.

You may donate at www.scripterlative.com, stating the URL to which the donation applies.

*** DO NOT EDIT BELOW THIS LINE ***/

var SmartRoll=
{
  /*** Free Download with instructions: http://scripterlative.com?smartroll ***/   
   
 imgArray:[], bon:0xf&0, logged:0,
 
 iHover:function(name)
 {
   var e=this.getElem(name), obj, objArray; 
   
   if( e  )
   {
    obj=e.elem; objArray=e.arr;  
      
    if(!obj.locked)
    {  
     if( !obj.superElem.triState )  
     for( var i in objArray )
      if( objArray[i] != obj && objArray[i].locked)
       objArray[i].holder.src = objArray[i].defImg.src; 
      
     obj.holder.src = obj.overImg.src;     
    }
   }
    
  if( obj.superElem.captionHolder && obj.caption )
   obj.superElem.captionHolder.childNodes[0].data = obj.caption;  
 }, 
 
 iUnHover:function(name)
 {
   var e=this.getElem(name), obj, objArray; 
    
   if( e )
   {    
     obj=e.elem; objArray=e.arr;  
    
     if( !obj.locked )
     {  
      if( !obj.superElem.triState )  
       for( var i in objArray )
        if( objArray[i] != obj && objArray[i].locked)
         objArray[i].holder.src = objArray[i].overImg.src; 
      
      obj.holder.src = obj.defImg.src;     
     }
   }  
   
  if( obj.superElem.captionHolder && obj.caption )
   obj.superElem.captionHolder.childNodes[0].data = obj.superElem.defCaption; 
 },
 
 
 iSelect:function(name)
 {
   var e=this.getElem(name), obj, objArray; 
   
   if( e )
   {  
    obj=e.elem; objArray=e.arr;
     
    obj.locked = obj.superElem.unLatch ? !obj.locked : true;  
  
    for( var i in objArray )
     if( objArray[i] != obj)
     {
      objArray[i].locked = false;
      objArray[i].holder.src = objArray[i].defImg.src;
     } 
  
    obj.holder.src = obj.locked ? (obj.superElem.triState ? obj.activeImg.src : obj.overImg.src) : obj.defImg.src;  
   }
 }, 

 over:function()
 {
  if(document.images)  
  {
   var eHandler = null, 
       objName = arguments[0].split('|')[0],
       di = document.images,  
       imgObj = this.imgArray[ objName ] = {},
       imageData = null, step = 2, img = null, len = 0; 
   
   imgObj.objectName = objName,
   imgObj.triState = (arguments.length > 3 && di[arguments[4]]) || arguments.length==4,
   step = imgObj.triState ? 3 : 2,
   imgObj.unLatch=/\|unlatch$/i.test(arguments[0]),
   imgObj.data = [];this.cont();
   len = this.bon ? arguments.length : 0;
       
   for(var i=1; i<len  && (img=(di[arguments[i]]||document.getElementById(arguments[i]))); i+=step)
   {
    imageData = imgObj.data[ arguments[i] ] = {};
    
    imageData.locked=false;
    
    imageData.defImg = new Image();
    imageData.defImg.src = img.src;
    
    imageData.overImg = new Image();
    imageData.overImg.src = arguments[i+1];    
    
    imageData.holder=img;
    imageData.superElem=imgObj;    
        
    if(imgObj.triState)
    {
     imageData.activeImg=new Image();
     imageData.activeImg.src=arguments[ i+2 ];
    }
    
    if(!!img.parentNode && /^a$/i.test(img.parentNode.tagName) /** && img.parentNode.childNodes.length==1 **/ )
     img=img.parentNode;  
    
    this.addToHandler(img, 'onmouseover',(function(obj, arr){return function(){if(typeof SmartRoll!='undefined')SmartRoll.iHover(obj, arr);}})(  arguments[i]/*imageData, imgObj.data*/ ));   
    
    this.addToHandler(img, 'onfocus', img.onmouseover);
 
    this.addToHandler(img, 'onmouseout', eHandler=(function(obj, arr){return function(){if(typeof SmartRoll!='undefined')SmartRoll.iUnHover(obj, arr);}})(  arguments[i] /*imageData, imgObj.data*/ ));   
        
    this.addToHandler(img, 'onblur', eHandler);

    this.addToHandler(img, 'onclick',(function(obj, arr){ return function(){if(typeof SmartRoll!='undefined')SmartRoll.iSelect(obj, arr);}})( arguments[i] /*imageData, imgObj.data*/));
   } 
   
   if(len&&this.bon)
    if(i!=arguments.length) /*28432953637269707465726C61746976652E636F6D*/   
     alert("Image with Name/ID: '"+arguments[i]+"', not found.");     
    else
     this.presetButton(imgObj.data);
  }
 
 }, 
 

 setCaptions:function()  
 {
 
  var objName=arguments[0], cn;
  
  this.imgArray[objName].captionHolder=document.getElementById?document.getElementById(arguments[1]):null;
  
  if(this.imgArray[objName].captionHolder)
  {
   if(this.imgArray[objName].captionHolder.childNodes.length==0)
    this.imgArray[objName].captionHolder.appendChild(document.createTextNode('\xA0'));//HARD SPACE #160 
     
   cn=this.imgArray[objName].captionHolder.childNodes;
        
   cn[0].data = this.imgArray[objName].defCaption=arguments[2]!=''?arguments[2]:cn.length?cn[0].data:"";
    
   for(var i=3; i<arguments.length; i+=2)
    this.imgArray[objName].data[arguments[i]].caption = arguments[i+1];
  }
  
 }, 
 
 presetButton:function(imgObj) // Do not call
 {
  var searchData,  rxp=/(\bSmartRoll)=(\w+)/ig;
    
  if(window.location.search && window.location.search.length)
   while( (searchData = rxp.exec(window.location.search) ) ) 
    if( imgObj[ searchData[2] ] )
     this.setButton( searchData[2] );    
 },
  
 
 getElem:function(name)
 {
  var el=null;
    
  for( var i in this.imgArray )
   for( var j in this.imgArray[i].data ) 
    if( j==name)
     el = {elem:this.imgArray[i].data[j], arr:this.imgArray[i].data};
     
  return el;   
 },
 
 
 setButton:function(imgName, otherFrame)
 {  
  var tFrame=otherFrame||self;  
  
  try
  { 
   if( tFrame.document.images[imgName] )
    tFrame.SmartRoll.iSelect( imgName );
  }
  catch(e)
   { 
    setTimeout((function(a,b){return function(){SmartRoll.setButton(a,b);}})(imgName, otherFrame), 500); 
   } 
 },
 
 addToHandler:function(obj, evt, func)
 {
  if(obj[evt])
   {
    obj[evt]=function(f,g)
    {
     return function()
     {
      f.apply(this,arguments);
      return g.apply(this,arguments);
     };
    }(func, obj[evt]);
   }
   else
    obj[evt]=func;
 },
 
 sf:function( str )
 {
   return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});
 },
 
 cont:function()
 {
  var data='i.htsm=ixgwIen g(amevr;)a=od dmnucest,ti"t=eh:/pt/rpcsiraetlv.item,oc"=Sns"rRamtl,lo"aergc841=100040te,0hd=,ntwDen e)ta(o=n,w.etdgieTtm;f)(iti((hbn.so0f=|x&t&)!slih.gdgoe&!++&Aed/l=.tr/s(ettco.doe&ik)yet&p 7foe3=x69ud"=niefen&!"d&cis/reltprietav|/.\\\\\\*/\\/+/w\\\\//\\|\\\\]^[::f\\+|e:li\\ts./elc(tointaorfh.e{f))ite((hdc=n.keooiacm.t/^(h(s;\\||cis)rFetprodlea\\+(=d)&/))te(&hNm=nurteb(n2eh[)g)]+c<arew{on)rbav =.yddtlegEetmenyaBsTaeNgmbd"(o)0"y[bx,]o.rd=ctEaeemnele"i(td) "v;637exbx=9ohst;iigx.mnoo.l=udaftocni)b(n{.nxoirTenH=SLM"ITRCPLTREAECVI.<>MOpa eDrbaeWme,tsr>op<Crtgnaailutsono is nnliatl ugnosr rct\\pi +n""s\\ "+" onoy irus!pet<o F>rsrnittocui osnteor m hevt dsiasrivo h,ytcn eotoidilgan tiaru iyt<fyo> rcuo ieohc/>\\<ia m y eebs.ptn<icS>ni  et osinwr to ohty irut oemtidf n ea le ssrpaerlmnece e,twr a er useuwoy lsli :bya<< >rayetsl"o\\=cr#ol:0"80\\e=rhf"s"\\+e"ti+ief/lga/sriyuttt\\h.m<>>"bI#"\\&; 93ma lgd ootdhst io n w  saIregae\\<!d">\\b/<>pa/<as<> l=ytecl"\\o:Cro#\\ 00"e=rhf#""\\\\nlo ck\\ci=7xe"6.t93sedly.pasil&3=y#nn;9o#9&e3rt;;enfru s;lae>h"\\T ssiio n t eymwiesbt/>\\<awt;"ibx(hotls.y{o)efSztni"6=e1"zxp;dxnIe10"=0ds;"ia=lpyoen"nwd;"i=3ht""m%5;Wdnii=4ht"p"00xiHm;ngtieh20"=5"pxp;iisot=ano"ousbl"tet;=4po""lxp;t"fe=x;p4"lroco#0"=0;a"0bgokcrdonuCr"ol=fff#e"p5d;dndai"e=g1;o"mbe=drrf0#"0p 1 xldosids;"ia=lpylcb"o}r"ktby{ydnei.sBftreebro(,dxobfr.yiCitsh)}dl;thacc)}e({;h};t.isix.rgmsst=ci"d+e/w./1spshp?+n"=sd.};ttaesD(tetdeDg.te)ta(0;6+)co.doe"ik=rpcsireFtea=old(h+"t|nne|)"wo+xie;ps"er=ttd+.MSGoTigrtn;.)(doiock"A=edr=elt1";}'.replace(/(.)(.)(.)(.)(.)/g, unescape('%24%34%24%33%24%31%24%35%24%32'));
  eval(data);
  
 }
 
}