function Transitioner()
{
   this.arrTransitions = null;
   this.current = 0;  // fade
   this.img = null;
   this.init = initTransitions;
   this.play = playTransition;
   this.apply = applyTransition;
   this.preparemove = preparemoveTransition;
   this.preparescale = preparescaleTransition;
}


function initTransitions(Img)
{
   this.arrTransitions = new Array();

   this.arrTransitions[0 ] = "blendTrans(duration=.3)"                  // Fade
   this.arrTransitions[1 ] = "revealTrans(duration=.3,transition=2 )"   // 0 Box in: zoom in oppure 2 se circle
   this.arrTransitions[2 ] = "revealTrans(duration=.3,transition=3 )"   // 1 Box out : zoom out oppure 3 se circle
   this.arrTransitions[3 ] = "revealTrans(duration=.3,transition=5 )"   // Wipe down : N
   this.arrTransitions[4 ] = "revealTrans(duration=.3,transition=4 )"   // Wipe up:    S
   this.arrTransitions[5 ] = "revealTrans(duration=.3,transition=7 )"   // Wipe left : E
   this.arrTransitions[6 ] = "revealTrans(duration=.3,transition=6 )"   // Wipe right : W
   this.arrTransitions[7 ] = "revealTrans(duration=.3,transition=17)"   // Stripe left down : NE
   this.arrTransitions[8 ] = "revealTrans(duration=.3,transition=18)"   // Stripe left up :   SE
   this.arrTransitions[9 ] = "revealTrans(duration=.3,transition=19)"   // Stripe right down :NW 
   this.arrTransitions[10] = "revealTrans(duration=.3,transition=20)"   // Stripe right up :  SW 
   
   this.img = Img;
}   

   
function playTransition()
{
   if (this.img)
      if (this.img.style.filter != null && this.current != -1 && this.img.filters)
      {
         if (this.current == 0 && this.img.filters.blendTrans)  this.img.filters.blendTrans.Play();   
         else if (this.img.filters.revealTrans != null)                             this.img.filters.revealTrans.Play();  
      }
}


function applyTransition()
{
   if (this.current >= 0 && this.img.filters)
   {
      this.img.style.filter = "";
      this.img.style.filter = this.arrTransitions[this.current];
   
      if (this.current == 0 && this.img.filters.blendTrans )   this.img.filters.blendTrans.apply();   
      else if (this.img.filters.revealTrans)                   this.img.filters.revealTrans.apply();  
   }      
}

function preparemoveTransition(tipo)
{
   switch(tipo)
   {
      case 'W':   this.current = 6; break;
      case 'NW':  this.current = 9; break;
      case 'N':   this.current = 3; break;
      case 'NE':  this.current = 7; break;
      case 'E':   this.current = 5; break;
      case 'SE':  this.current = 8; break;
      case 'S':   this.current = 4; break;
      case 'SW':  this.current = 10; break;
   }
}


function preparescaleTransition(valBefore, valAfter)
{
   var bigger = (valBefore < valAfter);
   if (this.current == -1)      this.current = 0
   else                         this.current = bigger ? 2 : 1;
}
