/***************************************************************
*  FADER
***************************************************************/
 
function JAVASCRIPT_SFX_FADE(objectName) {
  
  this.sfx                     = new JAVASCRIPT_SFX(); //uses JAVASCRIPT_SFX
  this.sfx.objectName          = objectName;
  this.oid                     = element_buildUniqueObjectID(this);
  
  // register Functions 
  this.doEffect                = JAVASCRIPT_SFX_FADE_doEffect;   
  this.addItem                 = JAVASCRIPT_SFX_FADE_addItem;   
  this.setSpeedParameters      = JAVASCRIPT_SFX_FADE_setSpeedParameters;
  this.start                   = this.sfx.start;
  this.stop                    = this.sfx.stop;
  
  return true;
}

//Wrapper Function
JAVASCRIPT_SFX_FADE_addItem = function(object, destinationX, destinationY){
  object = element_isObject(object);
  
  var x = null;
  var y = null;
  
  x = element_recalcValue2px(destinationX, 100);
  
  this.sfx.addObject(object, x, y);  

}

JAVASCRIPT_SFX_FADE_setSpeedParameters = function(intervalSpeed, a, b, c){
  
  this.sfx.calc.setParameters(intervalSpeed, a, b, c);  

}



JAVASCRIPT_SFX_FADE_doEffect = function(oid){
 
  var objects = this.sfx.objectPool;  
  for(var id in objects){  
    var object = objects[id];  //Momentan wird nur 1 Objekt/Effekt unterstützt
    
    //positions
    var currentOpacity = element_getOpacity(object); 

    //direction
    var direction = (currentOpacity<object.destination.x)?1:-1;  
    
    //parameters
    var y = 0;
    
    //calculation      
    y = this.sfx.calc.getValue(direction);
      
    currentOpacity+= y;

    if(direction > 0){    
      currentOpacity = (currentOpacity<object.destination.x)?currentOpacity:object.destination.x;    
    } else if(direction < 0){
      currentOpacity = (currentOpacity>object.destination.x)?currentOpacity:object.destination.x;
    }    
    
    //movement
    element_setOpacity(object, currentOpacity);
    
    if(currentOpacity == object.destination.x) {
      delete this.sfx.objectPool[id];
      continue;
    }
  } 
  
  if(object_count(this.sfx.objectPool) == 0) {
    this.stop();
  }
      
  return true;

}



