//SFX
var sfxObjects = new Object();
function JAVASCRIPT_SFX(){

  this.oid                     = element_buildUniqueObjectID(this);
  this.objectPool              = new Object();
  this.objectName              = null;
  
  this.calc                    = new JAVASCRIPT_SFX_OBJECT_POSITION_CALC();

  //FollowUp
  this.followingObjects        = new Array(); 
  this.followOptions           = new Object();
    
  this.current_intervalID      = null;
  
  this.addObject               = JAVASCRIPT_SFX_addObject;
  this.registerFollowingObject = JAVASCRIPT_SFX_registerFollowingObject;
  this.setFollowingOptions     = JAVASCRIPT_SFX_setFollowingOptions;
  this.callFollowingObjects    = JAVASCRIPT_SFX_callFollowingObjects;
  this.start                   = JAVASCRIPT_SFX_start;
  this.stop                    = JAVASCRIPT_SFX_stop;  
  
}

JAVASCRIPT_SFX_addObject = function(object, destinationX, destinationY){
  object = element_isObject(object);

  this.objectPool[object.id]                     = new Object();
  this.objectPool[object.id]                     = object;
  this.objectPool[object.id]['destination']      = new Object();
  this.objectPool[object.id]['destination']['x'] = (typeof destinationX == 'number')?destinationX:null;  
  this.objectPool[object.id]['destination']['y'] = (typeof destinationY == 'number')?destinationY:null;
  this.objectPool[object.id]['initPosition']     = element_getPosition(object.id);
  
  return true;
}


JAVASCRIPT_SFX_registerFollowingObject = function(object){
  object = element_isObject(object);
  
  //registers following Objects (with method 'start')
  if(typeof object.start == 'undefined') return true;

  this.followingObjects.push(object);

  return true;
}

JAVASCRIPT_SFX_setFollowingOptions = function(key, value){
  
  this.sfx.followingOptions[key] = value;
  
  return true;
}


JAVASCRIPT_SFX_callFollowingObjects = function(){
  //calls following Objects (with method 'start')

  for(var i in this.followingObjects){
    if(typeof this.followingObjects[i].start == 'undefined') continue;

    this.followingObjects[i].start();
  }
  return true;
}

JAVASCRIPT_SFX_start = function(){
  //starts the Effect

  this.sfx.callString = this.sfx.objectName + ".doEffect()";

  //set timer  
  this.sfx.current_intervalID = setInterval(this.sfx.callString, this.sfx.calc.intervalSpeed);

  return true;
}

JAVASCRIPT_SFX_stop = function(){

  clearInterval(this.sfx.current_intervalID);  //timeout zurücksetzen
  
  if(this.sfx.followingObjects.length==0) return true;

  this.sfx.callFollowingObjects();
  
  return true;
}






var app_registeredItems = new Object();

function JAVASCRIPT_SFX_OBJECT_POSITION_CALC(){
  
  //initial Values can be changed by Method "setParameters"
  this.intervalSpeed = 50;  
  this.a             = 0.000000001;
  this.b             = 0.0001;
  this.c             = 1;  
  
  this.startTime     = null;  
  
  this.getValue      = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_getValue;
  this.setParameters = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_setParameters;  
  this.reset         = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_reset;

}

JAVASCRIPT_SFX_OBJECT_POSITION_CALC_getValue = function(direction, calcLinear){
  direction = (typeof direction == 'undefined')?1:direction;  //deprecated
  
  if(this.startTime == null) this.startTime = time_getMilliTimestamp();  
  
  //time  
  var currentTime = time_getMilliTimestamp();      
  var xt = (currentTime - this.startTime);  

  var a = this.a;
  var b = this.b;
  var c = this.c;  
  
  if(calcLinear==true){
    y = Math.ceil(a);
  } else{    
    y = a * Math.pow(xt, 2) + (b * xt) + c; //y = ax² + bx + c      
    y = Math.floor(y);
  }
  

  return y;
  
}


JAVASCRIPT_SFX_OBJECT_POSITION_CALC_setParameters = function(intervalSpeed, a, b, c){

  this.intervalSpeed = (typeof intervalSpeed != 'undefined' && intervalSpeed != null)?intervalSpeed:this.intervalSpeed;  
  this.a = (typeof a != 'undefined' && a != null)?a:this.a;
  this.b = (typeof b != 'undefined' && b != null)?b:this.b;
  this.c = (typeof c != 'undefined' && c != null)?c:this.c;

}

JAVASCRIPT_SFX_OBJECT_POSITION_CALC_reset = function(){
  
  this.startTime = null;
  
}

function sfx_openPopUp(fileurl,width, height) {
  
  ScreenWidth = screen.width; 
  ScreenHeight = screen.height; 
  xpos = (ScreenWidth/2)-(width/2); 
  ypos = (ScreenHeight/2)-(height/2); 
  option = "left="+xpos+",top="+ypos+",width="+width+",height="+height+",status=false,toolbar=false";
  neupop = open(fileurl,"Detail",option);

}
