/**************************************************************************************************************************************************/

/* */

// acc is number between -1 and 1 ( -1 full decelerated, 1 full accelerated, 0 linear, i.e. no acceleration)
dyngObj.prototype.slideTo = function (destX,destY,slideDur,acc,endFn) {
  if (!document.getElementById) return;
  this.slideDur = slideDur || .0001; var acc = -acc || 0;
  if (endFn) this.onSlideEnd = endFn;
    // hold destination values (check for movement on 1 axis only)
  if (destX == null) this.destX = this.x;	else this.destX = destX;
  if (destY == null) this.destY = this.y; else this.destY = destY;
  this.startX = this.x; this.startY = this.y;
  this.st = new Date().getTime();
    // control points for bezier-controlled slide (see www.youngpup.net accelimation)
  this.xc1 = this.x + ( (1+acc) * (this.destX-this.x)/3 );
  this.xc2 = this.x + ( (2+acc) * (this.destX-this.x)/3 );
  this.yc1 = this.y + ( (1+acc) * (this.destY-this.y)/3 );
  this.yc2 = this.y + ( (2+acc) * (this.destY-this.y)/3 );
  this.sliding = true;
  this.onSlideStart();
  dw_Animation.add(this.animString + ".doSlide()");
}

dyngObj.prototype.doSlide = function() {
  
  if (!this.sliding) return;	
  var elapsed = new Date().getTime() - this.st;
  if (elapsed < this.slideDur) {
    var x = dw_Bezier.getValue(elapsed/this.slideDur, this.startX, this.destX, this.xc1, this.xc2);
    var y = dw_Bezier.getValue(elapsed/this.slideDur, this.startY, this.destY, this.yc1, this.yc2);
    this.shiftTo( Math.round(x) ,Math.round(y) );
    this.onSlide();} 
  else {	// if time's up
    dw_Animation.remove(this.animString + ".doSlide()");
    this.shiftTo(this.destX,this.destY);
    this.onSlide();
    this.sliding = false;
    this.onSlideEnd();}
}

dyngObj.prototype.slideBy = function(dx,dy,slideDur,acc,endFn) {
	var destX=this.x+dx; var destY=this.y+dy;
	this.slideTo(destX,destY,slideDur,acc,endFn);
}
dyngObj.prototype.onSlideStart = function () {}
dyngObj.prototype.onSlide = function () {}
dyngObj.prototype.onSlideEnd = function () { 
 if (this.el) this.el = null; 
}


var CardOn = 0;
var InvAddOn = 0;
var InvAddOpen = 0;
var Mobile_MenuOpen = 0;

function  ShowInfo() {
 if (CardOn == 0){
  glideLyrInfo = new dyngObj("glideInfo",-260,40);
  var oldLyr = dyngObj.getInstance('glideInfo');  
  oldLyr.show(); 
  oldLyr.onSlideEnd = function() { oldLyr.slideTo((getWinWidth()-255)/2 + 344,(getWinHeight()-180)/2 - 132, 3000 , -0.5 );
                                   this.onSlideEnd = function() { if (this.el) this.el = null }  }
  oldLyr.slideTo(18 + (getWinWidth() - 900)/2, 236 + (getWinHeight() - 500)/2, 2000 , -0.8 );
  CardOn = 1;
  }
}  

function  HideMyGlider(_myglider_) {  var old_Lyr = dyngObj.getInstance(_myglider_); old_Lyr.hide(); CardOn = 0; InvAddOn = 0; InvAddOpen = 0;}

function  ShowInvQuiz() {
  
 if (InvAddOn == 0){
  glideLyrInfo = new dyngObj("glideInvAdd",-260,40);
  var oldLyr = dyngObj.getInstance('glideInvAdd');  
  oldLyr.show(); 
  oldLyr.onSlideEnd = function() { oldLyr.slideTo((getWinWidth()-255)/2 + 344,330, 3000 , -0.5 );
                                   this.onSlideEnd = function() { if (this.el) this.el = null }  }
  oldLyr.slideTo(18 + (getWinWidth() - 900)/2, 236 + (getWinHeight() - 500)/2, 2000 , -0.8 );
  InvAddOn = 1;
  }
}  

function  ShowInvAdd() {
  
 if (InvAddOn == 0){
  glideLyrInfo = new dyngObj("glideInvAdd",-260,40);
  var oldLyr = dyngObj.getInstance('glideInvAdd');  
  oldLyr.show(); 
  oldLyr.onSlideEnd = function() { oldLyr.slideTo((getWinWidth()-255)/2 + 344,130, 3000 , -0.5 );
                                   this.onSlideEnd = function() { if (this.el) this.el = null }  }
  oldLyr.slideTo(18 + (getWinWidth() - 900)/2, 236 + (getWinHeight() - 500)/2, 2000 , -0.8 );
  InvAddOn = 1;
  }
}  

var setoff_m_x = 25;
var setoff_m_y = 10;
var m_speed = 1000;
var m_acc = -0.8;
var pos_m_x = new Array();
var pos_m_y = new Array();

var oldLyr1, oldLyr2, oldLyr3, oldLyr4, oldLyr6, oldLyr7, oldLyr8, oldLyr9;
    pos_m_x[0]= 0 ;
    pos_m_y[0]= 175 ;

    pos_m_x[5]= 685 ;
    pos_m_y[5]= 440 ;

function LoadSocial_Bar(){

var temp;
     var glideLyrInfo;
     var tempH = 0;
     var tempY = 0;

     temp = document.getElementById("glideMobilemenu6"); 
     tempY = temp.clientHeight;
     pos_m_y[6] = - tempY - setoff_m_y;
     pos_m_x[6] = setoff_m_x + tempH + pos_m_x[5];
     tempH = temp.clientWidth;
     glideLyrInfo = new dyngObj("glideMobilemenu6",pos_m_x[6],pos_m_y[6]);
     pos_m_y[6] = pos_m_y[6] - setoff_m_y - pos_m_y[5];
     oldLyr6 = dyngObj.getInstance('glideMobilemenu6');  

     temp = document.getElementById("glideMobilemenu7"); 
     tempY = temp.clientHeight;
     pos_m_y[7] = - tempY - setoff_m_y;
     pos_m_x[7] = setoff_m_x/2 + tempH + pos_m_x[6];
     tempH = temp.clientWidth;
     glideLyrInfo = new dyngObj("glideMobilemenu7",pos_m_x[7],pos_m_y[7]);
     pos_m_y[7] = pos_m_y[7] - setoff_m_y  - pos_m_y[5];
     oldLyr7 = dyngObj.getInstance('glideMobilemenu7'); 
     oldLyr6.onSlideEnd = function() { oldLyr7.show(); oldLyr7.slideBy(0, -pos_m_y[7], m_speed , m_acc ); this.onSlideEnd = function() { if (this.el) this.el = null }  }; 

     temp = document.getElementById("glideMobilemenu8"); 
     tempY = temp.clientHeight;
     pos_m_y[8] = - tempY - setoff_m_y;
     pos_m_x[8] = setoff_m_x/2 + tempH + pos_m_x[7];
     tempH = temp.clientWidth;
     glideLyrInfo = new dyngObj("glideMobilemenu8",pos_m_x[8],pos_m_y[8]);
     pos_m_y[8] = pos_m_y[8] - setoff_m_y - pos_m_y[5];
     oldLyr8 = dyngObj.getInstance('glideMobilemenu8');  
     oldLyr7.onSlideEnd = function() { oldLyr8.show(); oldLyr8.slideBy(0, -pos_m_y[8], m_speed , m_acc ); this.onSlideEnd = function() { if (this.el) this.el = null }  }; 

     temp = document.getElementById("glideMobilemenu9"); 
     tempY = temp.clientHeight;
     pos_m_y[9] = - tempY - setoff_m_y;
     pos_m_x[9] = setoff_m_x/2 + tempH + pos_m_x[8];
     tempH = temp.clientWidth;
     glideLyrInfo = new dyngObj("glideMobilemenu9",pos_m_x[9],pos_m_y[9]);
     pos_m_y[9] = pos_m_y[9] - setoff_m_y - pos_m_y[5];
     oldLyr9 = dyngObj.getInstance('glideMobilemenu9');  
     oldLyr8.onSlideEnd = function() { oldLyr9.show(); oldLyr9.slideBy(0, -pos_m_y[9], m_speed , m_acc ); this.onSlideEnd = function() { if (this.el) this.el = null }  }; 


     oldLyr6.show(); 
     oldLyr6.slideBy(0,-pos_m_y[6], m_speed , m_acc );

}

function LoadMenu_Bar(){

     var temp;
     var glideLyrInfo;
     var tempH = 0;
     var tempY = 0;



     temp = document.getElementById("glideMobilemenu1"); 
     tempH = temp.clientWidth;
     pos_m_x[1] = - tempH - setoff_m_x;
     pos_m_y[1] = setoff_m_y + tempY + pos_m_y[0];
     tempY = temp.clientHeight;
     glideLyrInfo = new dyngObj("glideMobilemenu1",pos_m_x[1],pos_m_y[1]);
     pos_m_x[1] = pos_m_x[1] - setoff_m_x;
     oldLyr1 = dyngObj.getInstance('glideMobilemenu1');  
 
     temp = document.getElementById("glideMobilemenu2"); 
     tempH = temp.clientWidth;
     pos_m_x[2] = - tempH - setoff_m_x;
     pos_m_y[2] = setoff_m_y + tempY + pos_m_y[1];
     tempY = temp.clientHeight;
     glideLyrInfo = new dyngObj("glideMobilemenu2",pos_m_x[2],pos_m_y[2]);
     pos_m_x[2] = pos_m_x[2] - setoff_m_x;
     oldLyr2 = dyngObj.getInstance('glideMobilemenu2');  
     oldLyr1.onSlideEnd = function() { oldLyr2.show(); oldLyr2.slideBy(-pos_m_x[2], 0, m_speed , m_acc ); this.onSlideEnd = function() { if (this.el) this.el = null }  };
 
     temp = document.getElementById("glideMobilemenu3"); 
     tempH = temp.clientWidth;
     pos_m_x[3] = - tempH - setoff_m_x;
     pos_m_y[3] = setoff_m_y + tempY + pos_m_y[2];
     tempY = temp.clientHeight;
     glideLyrInfo = new dyngObj("glideMobilemenu3",pos_m_x[3],pos_m_y[3]);
     pos_m_x[3] = pos_m_x[3] - setoff_m_x;
     oldLyr3 = dyngObj.getInstance('glideMobilemenu3');  
     oldLyr2.onSlideEnd = function() { oldLyr3.show(); oldLyr3.slideBy(-pos_m_x[3], 0, m_speed , m_acc ); this.onSlideEnd = function() { if (this.el) this.el = null }  };

     temp = document.getElementById("glideMobilemenu4"); 
     tempH = temp.clientWidth;
     pos_m_x[4] = - tempH - setoff_m_x;
     pos_m_y[4] = setoff_m_y + tempY + pos_m_y[3];
     tempY = temp.clientHeight;
     glideLyrInfo = new dyngObj("glideMobilemenu4",pos_m_x[4],pos_m_y[4]);
     pos_m_x[4] = pos_m_x[4] - setoff_m_x;
     oldLyr4 = dyngObj.getInstance('glideMobilemenu4');  
     oldLyr3.onSlideEnd = function() { oldLyr4.show(); oldLyr4.slideBy(-pos_m_x[4], 0, m_speed , m_acc ); this.onSlideEnd = function() { if (this.el) this.el = null }  };
     oldLyr4.onSlideEnd = function() { LoadSocial_Bar(); this.onSlideEnd = function() { if (this.el) this.el = null }  };


     oldLyr1.show(); 
     oldLyr1.slideBy(-pos_m_x[1], 0, m_speed , m_acc );

}



function ReloadCard(){ 
  if (CardOn == 1 ) { HideMyGlider('gliderInfo'); ShowInfo();}
  if (InvAddOn == 1) {HideMyGlider('gliderInvAdd'); ShowInvAdd();}
}


