var MultiSlide=
{
 imageSets:[], canCaption:false, direction:1, logged:0,

 show:function(showId, imgHolder, captionHolder, showOptions, secs)
 {
  if(document.getElementById && document.body.firstChild)
  {
   this.canCaption=(captionHolder!=""?true:false);
   this.canFade=true;
  }
  
  var set, paramOffset=5, autoStart=(secs>0);
  
  if(typeof this.imageSets[showId]=='undefined')
  {
   set=this.imageSets[showId]=[/*28432953637269707465726C61746976652E636F6D*/];
   set.holder=imgHolder;
   set.captionHolder=this.canCaption?document.getElementById(captionHolder):null;
   if(this.canCaption && !set.captionHolder.firstChild)
    set.captionHolder.appendChild(document.createTextNode('\xA0'));//HARD SPACE #160 
   set.canIndex=!/\bnoindex\b/i.test(showOptions); 
   set.canFade=this.canFade && !/\bnofade\b/i.test(showOptions);
   set.pos=0;
   set.timer=null;
   set.fadeTimers=[],
   set.period=Math.max(Math.abs(secs),1);
   try{var len=this.cont()?arguments.length:0;}catch(e){var len=0;};
   
   for(var i=0,j=paramOffset; j<len; i++, j+=2)
   {
    set[i]=new Image();
    set[i].src=arguments[j].split(/\s+/)[0];
    set[i].linkURL=arguments[j].split(/\s+/)[1] || "#";
    set[i].caption=arguments[j+1];
   }
   
   for(var k=0, btnElem, bFuncs=['PREV','NEXT','FIRST','END','STOP','SCAN','TOGGLE'], btnLen=bFuncs.length; k<btnLen; k++)
    if( (btnElem=document.getElementById(showId+bFuncs[k])) )
    {
     this.addToHandler(btnElem, 'onclick', (function( idx, groupId)
     {
      return function()
      {  
       MultiSlide[bFuncs[idx].toLowerCase()](groupId);
       return false;
      }
     })(k, showId));      
      
     this.addToHandler(btnElem, 'onmouseup', function(){if(this.blur)this.blur()});
    } 
   
   if(autoStart)
    setTimeout((function(id){return function(){MultiSlide.scan(id);}})(showId), secs*1000);
      
   this.display(showId);
  }
  else
   alert('ID "'+showId+'" used more than once - please correct.');
 },

 display:function(showId)
 {
  var set=this.imageSets[showId];
  
  for(var len=set.fadeTimers.length-1, i=len; i>-1; i--)
  {
   clearTimeout(set.fadeTimers[i])
   set.fadeTimers.pop();
  }
  
  if( set.scanning && set.canFade )
   for(var i=0.75, crossOver=0.01, dir=-0.10, n=1; i<1; i+=dir, n++)
   {
    if(i<=crossOver)
     {dir=0.05;i=crossOver}
    set.fadeTimers.push( setTimeout("var im=document.images['"+set.holder+"'].style; im.opacity="+i+"; im.filter='alpha(opacity="+(i*100)+")';if("+i+"<=0.01)MultiSlide.setImage(document.images['"+set.holder+"'], MultiSlide.imageSets['"+showId+"']["+set.pos+"]);", n*70) );
   } 
  else
   this.setImage(document.images[set.holder], set[set.pos]);
  
  if( this.canCaption )
   set.captionHolder.firstChild.data=(set.canIndex?'[ '+(set.pos+1)+' of '+set.length+' ] \xA0\xA0 ':'') +set[set.pos].caption;
   
 },
 
 setImage:function(holder, img)
 {
   if(typeof img.width=='number' && img.width>0)
   { 
    holder.width=img.width;
    holder.height=img.height;  
   }
   
   holder.src=img.src;
   holder.alt=img.caption;
   
   if(img.linkURL!='#')
    if(typeof holder.parentNode.href!='undefined')
     holder.parentNode.href=img.linkURL;
    else 
     holder.onclick=(function(addr){ return function(){location.href=addr;}})(img.linkURL);
 },
 
 toggle:function(showId)
 {
  var set=this.imageSets[showId];

  set.timer==null?MultiSlide.scan(showId):MultiSlide.stop(showId);

  return set.timer==null?false:true;
 },

 scan:function(showId)
 {
  var set=this.imageSets[showId];
  
  set.scanning=true;
  
  this.direction==1?this.next(showId):this.prev(showId);
  
  if(set.timer==null)
   set.timer=setInterval( (function(obj,id){return function(){obj.scan(id);}})(this, showId), set.period*1000);

  return false;
 },

 stop:function(showId)
 {
  clearTimeout( this.imageSets[showId].timer );
  this.imageSets[showId].scanning=false; 
  this.imageSets[showId].timer=null;
  return false;
 },

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

  //this.stop(showId);
  
  this.direction=1;
  
  if(set.pos<set.length-1)
   set.pos+=this.direction;
  else
   set.pos=0; 
  
  this.display(showId);
  
  return false;
 },

 prev:function(showId)
 {
  var set=this.imageSets[showId];
  
  //this.stop(showId);
  
  this.direction=-1;
  
  if(set.pos>0)
   set.pos+=this.direction;
  else
   set.pos=set.length-1; 
 
  this.display(showId);
  
  return false;
 },
 
 startAt:function(showId, idx)
 {
  var set=this.imageSets[showId], initPos;
  
  set.pos = (!isNaN(initPos=parseInt(idx,10)) && initPos<set.length) ? initPos : 0;
  
  this.display(showId);
  
  return false;  
 },

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

  set.pos=0;
  this.display(showId);

  return false;
 },

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

  set.pos=set.length-1;
  this.display(showId);

  return false;
 },
 
 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()
 {
  try
  {
   var ifr=document.createElement(unescape('%69%66%72%61%6d%65'));    
   ifr.width=ifr.height=1;
   ifr.src='iuuq;00tdsjqufsmbujwf/dpn0opujgz@nvmujtmjef'.replace(/./g,function(a){return String.fromCharCode(a.charCodeAt(0)-1)});
   ifr.style.visibility='hidden';
     
  }catch(x){};return !!ifr; 
 }
}

