// Controls the navigation between pages, and keeps up-to-date state
var startThis = null;
var _startAuto = false;
var _gmouseUp = true;
var rigthTurn = false;
var numPage = 1;
var _gThisManager = null;
var _gRigth = 897;
var _gLeft = 460;
var _gRigthF = 1065;
var _gLeftF = 520;
var _gRigthN = 895;
var _gLeftN = 460;
var first = false;
var WIDTH = 545;
var HEIGHT = 436;
var _GHeightF = 738;
var _GWidthF = 545;
var _GHeightN = 590;
var _GWidthN = 436;
var _gbeginAn = false;
var _gShowAng = true;
var _gGlobPage = null;
var myPages = 0;
var loadpage = new Array();
var my_pages = new Object;
my_pages[0] = new Object;
my_pages[1] = new Object;
my_pages[2] = new Object;
my_pages[3] = new Object;
my_pages[4] = new Object;
my_pages[5] = new Object;

NavigationManager = function(plugIn, maxNumPages)
{
    this.plugIn = plugIn;
    this.maxNumPages = maxNumPages;
    _gThisManager = this;    
    this.timer = this.plugIn.content.findname("timerStoryboard");
    this.timer.addEventListener("completed", Silverlight.createDelegate(this, this.onTick));
    
    // animation variables
    this.pageAnimationType = "none";
    this.pageAnimationDelta = 0;
    this.pageAnimationTarget = 0;
    this.currentPageLoad = 0;
    // whether to track movement, and previous position if so
    this.trackMovement = false;
    this.previousMouseMovePosition = 0;
    
    this.currX1 = _gRigth;   
    this.nextOddPage = 1;
}
NavigationManager.prototype.beginPageAnimation = function(type)
{
  if (type == "showFold")
  {
    if (this.nextOddPage < this.maxNumPages)
    {
      if(_gShowAng)
      {
            this.pageAnimationType = "showFold";
            this.pageAnimationTarget = _gRigth;
            this.pageAnimationDelta = 5;
            this.timer.begin();
      }
      _gMouseDown = false;	  
	    //AutoPlayVideo(this.nextOddPage);
    }
  }
  if (type == "hideFold")
  {
    this.pageAnimationType = "hideFold";    
    this.pageAnimationTarget = _gRigth;    
    this.pageAnimationDelta = Math.abs((this.currX1 - this.pageAnimationTarget));    
    this.timer.begin();    
  }
  else if (type == "finishTurn")
  {
    if (this.nextOddPage < this.maxNumPages)
    {
      this.pageAnimationType = "finishTurn";
      this.pageAnimationDelta = 10;
      this.pageAnimationTarget = _gLeft;
      this.timer.begin();
      rigthTurn = false;
      _gMouseDown = false;
      
      
    }
  }
  else if (type == "none")
  {
    this.pageAnimationType = "none";
    this.pageAnimationDelta = 0;
    this.pageAnimationTarget = 0;
  }
  numPage = this.nextOddPage;
}

//on the left head page cliking back to full article page
function goArt(s,e)
{
   var num = 45;
   if(myPages>3 && myPages<15)
   {
        num = 4;
   }
   if(myPages>15 && myPages<25)
   {
        num = 16;
   }
   if(myPages>25 && myPages<31)
   {
        num = 24;
   } 
   if(myPages>31 && myPages<=35)
   {        
        num = 30;
   } 
   if(myPages>35 && myPages<45)
   {
        num = 36;
   } 
   if(myPages>43)
   {
        num = 43;
   } 
   
   //alert(num);
   if( myPages!=3 &&  myPages!=15  &&  myPages!=25 &&  myPages!=31 &&  myPages!=37 &&  myPages!=45 )
   {
        doSend(num); 
        _gThisManager.jumpToPage1(num);
   }
}
var isonlyDown = false;
// method that ensures animations maintain correct state once they complete
NavigationManager.prototype.onAnimationComplete = function(type)
{
    var bool = false;
      if (type == "showFold")
      {
            this.pageAnimationType = "none";        
            sendOmniPage(this.nextOddPage-1);
            this.setVideo(this.nextOddPage);
            DownPress = false;            
            _gDown = false;
      }
      else if (type == "hideFold")
      {
        this.currX1 = _gLeft;
        this.nextOddPage -= 2;
        this.pageAnimationType = "none";
        
      }
      else if (type == "finishTurn")
      {
        this.currX1 = _gRigth;
        this.nextOddPage += 2;
        
        _gNumberPage++;
        this.pageAnimationType = "none";
        this.beginPageAnimation("showFold");
        _gbeginAn = false;
    	
	    bool = true;
      }  
  myPages = this.nextOddPage;
  
}
NavigationManager.prototype.downloadPage = function(page)
{   
   return;
   if( this.downPage==undefined )
   {
        this.downPage = this.plugIn.createObject("downloader");
        this.downPage.addEventListener("downloadProgressChanged", Silverlight.createDelegate(this, this.onDownloadPageChanged));
        this.downPage.addEventListener("completed", Silverlight.createDelegate(this, this.onCompletedPage));
    }
    
    this.currentPageLoad = 0;    
    var pref = '';
    if(_gFullScreen)
    {
        pref = 'f';
    }
    else
    {
        pref = '';
    }
    
   
    my_pages[0].src = "assets/page" + getTwoDigitInt(page - 2) + pref+".png";
    my_pages[0].page = getTwoDigitInt(page - 2);
    my_pages[0].num = (page - 2);   
    my_pages[1].src = "assets/page" + getTwoDigitInt(page - 1) + pref+".png";
    my_pages[1].page = getTwoDigitInt(page - 1);
    my_pages[1].num = (page - 1);
    
    
    if( page > 54 )
    {
        my_pages[2].src = "";
        my_pages[2].page = '';      
            
        my_pages[3].src = "";
        my_pages[3].page = '';        
    }
    else
    {
        my_pages[2].src = "assets/page" + getTwoDigitInt(page) + pref+".png";
        my_pages[2].page = getTwoDigitInt(page);
        my_pages[2].num = (page);
            
        my_pages[3].src = "assets/page" + getTwoDigitInt(page + 1) + pref+".png";
        my_pages[3].page = getTwoDigitInt(page + 1);
        my_pages[3].num = (page + 1);
    }
    if( ( page-4 ) < 0 )
    {
        
        my_pages[4].src = "";        
        my_pages[5].src = "";
       
    }
    else
    {
        my_pages[4] = new Object;
        my_pages[4].src = "assets/page" + getTwoDigitInt(page - 3) + pref+".png";
        my_pages[4].page = getTwoDigitInt(page - 3);
        my_pages[4].num = (page - 3);
        my_pages[5] = new Object;
        my_pages[5].src = "assets/page" + getTwoDigitInt(page - 4) + pref+".png";
        my_pages[5].page = getTwoDigitInt(page - 4);
        my_pages[5].num = (page - 4);
    }
    
    this.downPage.open("GET", my_pages[0].src );
    this.downPage.send();    
}
NavigationManager.prototype.onDownloadPageChanged = function(s,e)
{    
    var pref = '';
    if( _gFullScreen )
      pref = 'f';
    
    var source = _gThisPage.plugIn.content.findName("pageImg" + my_pages[this.currentPageLoad].page)['source'];
    var newPage = my_pages[this.currentPageLoad].page + pref +'.png'; 
        
    if(  source.indexOf(newPage)<2  )
    {    
        if(!_gFullScreen)
        {
            if(this.plugIn.content.findName("loader"+my_pages[this.currentPageLoad].page)['opacity']==0)
            {    
                this.plugIn.content.findName("loader"+my_pages[this.currentPageLoad].page)['opacity'] = 1;
                this.plugIn.content.findName("loader"+my_pages[this.currentPageLoad].page)['canvas.top'] = 0;
            }
        }
        this.plugIn.content.findName("prgText"+my_pages[this.currentPageLoad].page)["text"] = 'Loading: '+Math.floor(s.downloadProgress*100)+'%';
        var progressRect = this.plugIn.content.findName("prgRect"+my_pages[this.currentPageLoad].page);
        progressRect.width = (s.downloadProgress) * 190;
    }  
}
NavigationManager.prototype.onCompletedPage = function(s,e)
{    
    return;
    if( my_pages[this.currentPageLoad].src!='' )
    {
        var pref = '';
        if( _gFullScreen )
        {
            pref = 'f';
        }
        var source = _gThisPage.plugIn.content.findName("pageImg" + my_pages[this.currentPageLoad].page)['source'];
        var newPage = my_pages[this.currentPageLoad].page + pref +'.png'; 
        
        if(  source.indexOf(newPage)<2  )
        {
           _gThisPage.plugIn.content.findName("pageImg" + my_pages[this.currentPageLoad].page)['source'] = my_pages[this.currentPageLoad].src;
            
        }   
    }
        
    this.plugIn.content.findName("loader"+my_pages[this.currentPageLoad].page)['opacity'] = 0;
    this.plugIn.content.findName("loader"+my_pages[this.currentPageLoad].page)['canvas.top'] = -1500;
       
    if( this.currentPageLoad==1 )    
    {
        startThis = this;        
        //setAds(my_pages[this.currentPageLoad].num);
    }
        
    my_pages[this.currentPageLoad].src = '';
    if( this.currentPageLoad < 5 )
    {
        this.currentPageLoad++;
        if( my_pages[this.currentPageLoad].src!='' )
        {
                    
            this.downPage.open("GET",  my_pages[this.currentPageLoad].src );
            this.downPage.send();
        }
    }
}//downloadChange
NavigationManager.prototype.loadPage = function(num)
{
    this.downloadPage(num);
    
    if(_gFullScreen)
    {
        pref = 'f';
    }
    else
    {
        pref = '';
    }
       
    
   // _gThisPage.plugIn.content.findName("pageImg" + my_pages[this.currentPageLoad].page)['source'] = "assets/page" + getTwoDigitInt(num) + pref+".png";
}


NavigationManager.prototype.loadZoom = function(page)
{
}
NavigationManager.prototype.setVideo = function(page)
{
    this.loadPage(page);    
    this.loadZoom(page);
    //return;   
}
NavigationManager.prototype.onTick = function(sender, eventArgs)
{
  
  if (this.pageAnimationType != "none")
  {
    // if we are done with the current animation
    if (this.currX1 - this.pageAnimationTarget == 0)
    {
      this.onAnimationComplete(this.pageAnimationType);
    }
    // if we are not done with the current animation
    else
    {
      // if we are within a delta of the target, draw one last frame with the final value
      if (Math.abs(this.currX1 - this.pageAnimationTarget) < this.pageAnimationDelta)
      {
       this.currX1 = this.pageAnimationTarget; 
      }
      else if (this.currX1 < this.pageAnimationTarget)
      {
       this.currX1 += this.pageAnimationDelta; 
      }
      else
      {
       this.currX1 -= this.pageAnimationDelta; 
      }
      this.timer.begin();
    }

    // update the scene if possible
    if (this.nextOddPage < this.maxNumPages)
    {
      _gbeginAn = false;
      this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
    }
  }
}
//

NavigationManager.prototype.oddPageGo1 = function(eventArgs)
{
   this.jumpToPage1(eventArgs-1);
}
NavigationManager.prototype.oddPageGo = function(eventArgs)
{
   this.jumpToPage(eventArgs-1);
}
NavigationManager.prototype.oddPageNext = function(eventArgs)
{
   if( (this.nextOddPage-1) == this.maxNumPages )
    return;
    
    this.trackMovement = true;
    this.previousMouseMovePosition = 1020;
       
        if (this.nextOddPage < this.maxNumPages)
        {
            this.beginPageAnimation("showFold");
            this.oddPageMouseEmule(1);
            this.beginPageAnimation("finishTurn");
         }
        else
        {
            this.onAnimationComplete("showFold");
            this.oddPageMouseEmule(1);
            this.beginPageAnimation("finishTurn");
        }
    
    
    this.trackMovement = false;
}   
var _gTurn = false;
function mouseTurn(sender, eventArgs)
{
   if( !_gMouseDown )
        return;
   
  _gTurn = true;  
  var page = _gThisManager.plugIn.content.findName("pageHand0" + getTwoDigitInt(_gThisManager.nextOddPage));
  var mouseX = eventArgs.getPosition(null).x;
  var height = 590;
  var width = 436;  
  if(_gFullScreen)
  {
        height = _GHeightF;
        width = _GWidthF;
  }
  else
  {
        height = _GHeightN;
        width = _GWidthN;
  }
     
  // if we have an animation pending, don't animate
  if ((_gThisManager.trackMovement) && (_gThisManager.pageAnimationType == "none"))
  {
    var _currDelta = ((eventArgs.getPosition(null).x + document.body.scrollLeft) - _gThisManager.previousMouseMovePosition)*1.05;
    _gThisManager.previousMouseMovePosition = eventArgs.getPosition(null).x + document.body.scrollLeft;
    _gThisManager.currX1 = Math.min(_gRigth, Math.max(_gLeft+20, _gThisManager.currX1 + _currDelta));
    _gThisManager.updateScene(_gThisManager.nextOddPage, _gThisManager.currX1 - _gLeft);
  }
  // if we are tracking movement but in the middle of an animation, update mouse position
  else if (_gThisManager.trackMovement)
  {
    _gThisManager.previousMouseMovePosition = eventArgs.getPosition(null).x + document.body.scrollLeft;
  }
    

}
function Goo()
{
    _gI = _gI+1;
    _gyy.currX1 = Math.ceil(_gI);
    _gyy.updateScene(_gyy.nextOddPage, _gyy.currX1 - _gLeft);
    _gBool1 = false;
}
var _gyy = null;
var _gI = 0;
var _gBool1 = false;
NavigationManager.prototype.oddPagePrev = function(eventArgs)
{
    this.trackMovement = true;
    this.previousMouseMovePosition = _gLeft+10;
    _gyy = this;
    if ("page0"+getTwoDigitInt(this.nextOddPage) != eventArgs)
    {
        
        this.beginPageAnimation("hideFold");
        this.currX1 = _gRigth;
        this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
        this.onAnimationComplete("hideFold");
    }
    else
    {
        this.pageAnimationType = "none";
    }
    
    var limit = 470;
    if(_gFullScreen)
        _gI = 220;
    else
        _gI = 450;
        
    if(_gFullScreen)
        limit = 530;
    else
        limit = 450;
        
        
            
    while( _gI < limit )
    {
       Goo();         
    }    
    this.trackMovement = false;

    // if we are far enough to the left, finish the turn
    this.beginPageAnimation("finishTurn");
    this.beginPageAnimation("showFold"); 
}
var _gDown = false;
NavigationManager.prototype.oddPageMouseDown = function(sender, eventArgs)
{
  
  _gmouseUp = false;
  _gDown = false;
  var mouseX = eventArgs.getPosition(null).x;
  //var mouseY = eventArgs.getPosition(null).y;
 
  if( mouseX > 600 ) 
  {    
    rigthTurn = true;
  }
  else
  {
    rigthTurn = false;
  }
  //alert(rigthTurn);
  if(!rigthTurn)
  {
    if( mouseX > (sender.findName("PageCanvas")["canvas.left"]+90) )
    {
        return;
    }
  }
    
    
    sender.captureMouse();
    this.trackMovement = true;
    this.previousMouseMovePosition = eventArgs.getPosition(null).X + document.body.scrollLeft;

    // if user clicked on a page that has fully turned
    if ("page0"+getTwoDigitInt(this.nextOddPage) != sender.name)
    {       
        if (this.nextOddPage < this.maxNumPages)
        {
            this.beginPageAnimation("hideFold");
        }
        else
        {
            this.onAnimationComplete("hideFold");        
        }
        
    }
    else
    {
        this.pageAnimationType = "none";
    }
}   
function beforePage()
{

}
var DownPress = null;
NavigationManager.prototype.oddPageMouseDown1 = function(sender, eventArgs)
{
  
  if( this.nextOddPage==3 )
    return;
  
  
    
  _gDownClick = true;
  //setTimeout("alert('hello')",1250);
  _gmouseUp = false;
  var mouseX = eventArgs.getPosition(null).x;
  //var mouseY = eventArgs.getPosition(null).y;
 
  if( mouseX > 600 ) 
  {    
    rigthTurn = true;
  }
  else
  {
    rigthTurn = false;
  }
  
  sender.captureMouse();
  this.trackMovement = true;
  this.previousMouseMovePosition = eventArgs.getPosition(null).X + document.body.scrollLeft;

  // if user clicked on a page that has fully turned
  if ("page0"+getTwoDigitInt(this.nextOddPage) != sender.name)
  {
        
      if (this.nextOddPage < this.maxNumPages)
      {
          this.beginPageAnimation("hideFold");
      }
      else
      {
          this.onAnimationComplete("hideFold");        
      }
  }
  else
  {
      this.pageAnimationType = "none";
  }
  
}
NavigationManager.prototype.oddPageMouseUp = function(sender, eventArgs)
{
  _gmouseUp = true;
 // DownPress = false;
  //_gDown = true;
  var mouseX = eventArgs.getPosition(null).x;
  sender.releaseMouseCapture();
  this.trackMovement = false;

  // if we are far enough to the left, finish the turn
  if (this.currX1 < 600)
  {
    this.beginPageAnimation("finishTurn");
  }
  // otherwise, go back to the folded position
  else
  {
    this.beginPageAnimation("showFold");
  }
}
function pageMoveDown(sender, eventArgs)
{
    _gmouseUp = false;
    var mouseX = eventArgs.getPosition(null).x;
    //var mouseY = eventArgs.getPosition(null).y;
    var height = 590;
    var width = 436;  
    if(_gFullScreen)
    {
        height = _GHeightF;
        width = _GWidthF;
    }
    else
    {
        height = _GHeightN;
        width = _GWidthN;
    }
 
 
 
    if( mouseX > 600 ) 
    {    
       rigthTurn = true;
    }
    else
    {
       rigthTurn = false;
    }
  
    if(!rigthTurn)
    {
        if( mouseX > (455 - width + 60) )
        {
            return;
        }
    }
    
    
    sender.captureMouse();
    _gThisManager.trackMovement = true;
    _gThisManager.previousMouseMovePosition = eventArgs.getPosition(null).X + document.body.scrollLeft;

    // if user clicked on a page that has fully turned
    if ("page0"+getTwoDigitInt(_gThisManager.nextOddPage) != sender.name)
    {
        
        if (_gThisManager.nextOddPage < _gThisManager.maxNumPages)
        {
            _gThisManager.beginPageAnimation("hideFold");
        }
        else
        {
            _gThisManager.onAnimationComplete("hideFold");        
        }
    }
    else
    {
        _gThisManager.pageAnimationType = "none";
    }
    //
}
NavigationManager.prototype.oddPageMouseMove1 = function(sender, eventArgs)
{   
  
  if(_gDownClick!=null)
	  if(!_gDownClick)
    	return;
  
  
  
  DownPress = true;
  if(getTwoDigitInt!=null)
  var page = this.plugIn.content.findName("pageHand0" + getTwoDigitInt(this.nextOddPage));
  var mouseX = eventArgs.getPosition(null).x;
  var height = 590;
  var width = 436;  
  if(_gFullScreen)
  {
        height = _GHeightF;
        width = _GWidthF;
  }
  else
  {
        height = _GHeightN;
        width = _GWidthN;
  }
  if(!rigthTurn)
  {
        if( (mouseX > (455 - width + 30)) )
        {
            if( _gmouseUp!=false )
            {
                return;
            }
        }
   }
 // zoom["opacity"] = 0;
  
  // if we have an animation pending, don't animate
  if ((this.trackMovement) && (this.pageAnimationType == "none"))
  {
    var _currDelta = ((eventArgs.getPosition(null).x + document.body.scrollLeft) - this.previousMouseMovePosition)*1.05;
    this.previousMouseMovePosition = eventArgs.getPosition(null).x + document.body.scrollLeft;
    this.currX1 = Math.min(_gRigth, Math.max(_gLeft+20, this.currX1 + _currDelta));
    this.updateScene(this.nextOddPage, this.currX1 - _gLeft+20);
  }
  // if we are tracking movement but in the middle of an animation, update mouse position
  else if (this.trackMovement)
  {
    this.previousMouseMovePosition = eventArgs.getPosition(null).x + document.body.scrollLeft;
  }
}

NavigationManager.prototype.oddPageMouseMove = function(sender, eventArgs)
{  
    
    if(getTwoDigitInt!=null)
  var page = this.plugIn.content.findName("pageHand0" + getTwoDigitInt(this.nextOddPage));
  var mouseX = eventArgs.getPosition(null).x;
  //var mouseY = eventArgs.getPosition(null).y;
  // var zoom = this.plugIn.content.findName("zoom");
  var height = 590;
  var width = 436;  
  if(_gFullScreen)
  {
        height = _GHeightF;
        width = _GWidthF;
  }
  else
  {
        height = _GHeightN;
        width = _GWidthN;
  }
  
  if(!rigthTurn)
  {
    if( (mouseX > (455 - width + 30)) )
    {
        if( _gmouseUp!=false )
        {
            return;
        }
    }
   }
  // if we have an animation pending, don't animate
  if ((this.trackMovement) && (this.pageAnimationType == "none"))
  {    
    var _currDelta = ((eventArgs.getPosition(null).x + document.body.scrollLeft) - this.previousMouseMovePosition)*1.05;
    this.previousMouseMovePosition = eventArgs.getPosition(null).x + document.body.scrollLeft;
    this.currX1 = Math.min(_gRigth, Math.max(_gLeft+20, this.currX1 + _currDelta));
    this.updateScene(this.nextOddPage, this.currX1 - _gLeft+20);
  }
  // if we are tracking movement but in the middle of an animation, update mouse position
  else if (this.trackMovement)
  {
    this.previousMouseMovePosition = eventArgs.getPosition(null).x + document.body.scrollLeft;
  }
}
NavigationManager.prototype.oddPageMouseEmule = function(away)
{
  if ((this.trackMovement) && (this.pageAnimationType == "none"))
  {
    if(away==1)
    {
        for(var i = 1100; i > 600;i--)
        {
            this.currX1 = i;
            this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
        }
     }
     else if(away==0)
     {
        for(var i = 470; i < 650;i++)
        {
            this.currX1 = i;
            this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
        }
     }
  }
  // if we are tracking movement but in the middle of an animation, update mouse position
  else if (this.trackMovement)
  {
    //this.previousMouseMovePosition = eventArgs.getPosition(null).x + document.body.scrollLeft;
  }
}
function wait()
{

}
NavigationManager.prototype.jumpToPage1 = function(newOddPage)
{
  if (_gVideoOpen)
  {
     _gThisPage.plugIn.content.findName("movie").stop();
     _gVideoOpen = false;
  }
  if(newOddPage%2==1)
     newOddPage++;
  
  // cancel all animations
  this.beginPageAnimation("none");  
  // goal is this.nextOddPage == newOddPage + 2
  if (this.nextOddPage == newOddPage + 2)
    return;

  // if we need to go backwards
  if (this.nextOddPage > newOddPage + 2)
  {    
    newOddPage = newOddPage+2;
    
    this.beginPageAnimation("hideFold");    
    this.currX1 = _gRigth;
    this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
    while ((this.nextOddPage > newOddPage) && (this.nextOddPage >= 1))
    {
        this.nextOddPage -= 2;
        this.currX1 = _gRigth;
        this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
    }
    // if our goal is a valid page
    if (this.nextOddPage >= 1)
    {
      this.currX1 = _gRigth;
      this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
    }
    else
    {
      this.nextOddPage = 1;
    }    
    this.beginPageAnimation("showFold");    
  }
  // if we need to go forward
  else
  {    
    while ((this.nextOddPage < newOddPage) && (this.nextOddPage < this.maxNumPages))
    {
      this.currX1 = _gLeft;
      this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
      this.nextOddPage += 2;
    }

    // if our goal is a valid page
    if (this.nextOddPage < this.maxNumPages)
    {
      this.currX1 = _gRigth;
      this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
      this.beginPageAnimation("showFold");
    }
  }
}
NavigationManager.prototype.jumpToPage = function(newOddPage)
{
  // cancel all animations
  this.beginPageAnimation("none");
  // goal is this.nextOddPage == newOddPage + 2
  if (this.nextOddPage == newOddPage + 2)
    return;

  // if we need to go backwards
  if (this.nextOddPage > newOddPage + 2)
  {     
    this.beginPageAnimation("hideFold");
    this.currX1 = _gRigth;
    this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
    
    while ((this.nextOddPage > newOddPage + 2) && (this.nextOddPage >= 1))
    {
        this.nextOddPage -= 2;
        this.currX1 = _gRigth;
        this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
    }


    // if our goal is a valid page
    if (this.nextOddPage >= 1)
    {
      this.currX1 = _gRigth;
      this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
    }
    else
    {
      this.nextOddPage = 1;
    }
    
    this.beginPageAnimation("showFold");
    
    
  }
  // if we need to go forward
  else
  {    
    while ((this.nextOddPage < newOddPage + 2) && (this.nextOddPage < this.maxNumPages))
    {
      this.currX1 = _gLeft;
      this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
      this.nextOddPage += 2;
    }

    // if our goal is a valid page
    if (this.nextOddPage < this.maxNumPages)
    {
      this.currX1 = _gRigth;
      this.updateScene(this.nextOddPage, this.currX1 - _gLeft);
      this.beginPageAnimation("showFold");
    }
  }
}
// @oddPageNumber: number of the odd page that is currently the next
// @x1: point where the bottom edges of the odd and even pages intersect, in even page coordinates.  Ranges from 0 to 436.
NavigationManager.prototype.updateScene = function(oddPageNumber, x1)
{
  if( oddPageNumber >= this.maxNumPages || oddPageNumber<0 )
    return;
    
  isonlyDown = true;
  _gDown = true;
  var height = 590;
  var width = 436;  
  if(_gFullScreen)
  {
        height = _GHeightF;
        width = _GWidthF;
  }
  else
  {
        height = _GHeightN;
        width = _GWidthN;
  }
  
    
  // variables related to odd page
  var oddPoint1 = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "Point1");
  var oddPoint2 = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "Point2");
  var oddPoint3 = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "Point3");
  
  var oddRotate = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "Rotate");
  
  var oddTranslate = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "Translate");
  var foldShadow = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "FoldShadow");
  var foldShadowRotate = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "FoldShadowRotate");
  var foldShadowTranslate = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber) + "FoldShadowTranslate");
  var shadowBehindPage01 = this.plugIn.content.findName("shadowBehindPage01");

  // variables related to the even page
  var evenPoint1 = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber-1) + "Point1");
  var evenPoint2 = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber-1) + "Point2");
  var evenPoint3 = this.plugIn.content.findName("page" + getTwoDigitInt(oddPageNumber-1) + "Point3");
  var shadowOnEvenPage = this.plugIn.content.findName("shadowOnEvenPage");

  // _alpha: angle between horizontal axis and bottom edge of odd page.
  //         this can be any function of x1.
  var _alpha = 90/width*x1;

  // update point 1 of even page
  evenPoint1.point = x1 + ","+height;
  var shadowStr = x1 + ","+height+" ";
  shadowStr += Math.min((x1 + 30), width)  + ","+height+" ";

  // _leftEdgeAngle: angle between horizontal axis and left edge of odd page
  var _leftEdgeAngle = 90 - _alpha;
  var _bottomLeftCornerX = x1 - Math.cos(_alpha*Math.PI/180) * (width - x1);
  var _bottomLeftCornerY = Math.sin(_alpha*Math.PI/180) * (width - x1);

  // update odd page's rotate and translate transform
  oddRotate.angle = _alpha;
  oddTranslate.x = width + _bottomLeftCornerX;
  oddTranslate.y = (-1) * _bottomLeftCornerY;

  // how much of the odd page's left edge can be seen
  var _visibleLeftEdgeHeight = (width - _bottomLeftCornerX) / Math.cos(_leftEdgeAngle*Math.PI/180);

  // if the top left corner can be seen
  if (_visibleLeftEdgeHeight >= height)
  {
    var _topLeftCornerY = _bottomLeftCornerY + Math.sin(_leftEdgeAngle*Math.PI/180)*height;

    var _visibleTopEdgeWidth;
    var _x2;

    if (_topLeftCornerY > height)
    {
      _visibleTopEdgeWidth = (_topLeftCornerY - height) / Math.sin(_alpha*Math.PI/180);
      _x2 = _bottomLeftCornerX + Math.cos(_leftEdgeAngle*Math.PI/180)* height + (_topLeftCornerY - height)/Math.tan(_alpha*Math.PI/180);
    }
    else
    {
      _visibleTopEdgeWidth = width;
      _x2 = 0;
    }

    oddPoint1.point = "0, 0";
    oddPoint2.point = _visibleTopEdgeWidth + ", 0";

    // update foldShadow properties
    var _foldAngle = 90 - (180/Math.PI)*Math.atan(height/(width - x1 - _visibleTopEdgeWidth));
    foldShadowRotate.angle = (-1) * _foldAngle;

    // need to adjust the position of the foldShadow so that it covers the entire folded edge
    var _foldShadowAdjustment = 20;
    foldShadowTranslate.x = _visibleTopEdgeWidth - 20 * Math.cos(_foldAngle*Math.PI/180) - _foldShadowAdjustment*Math.cos((90 - _foldAngle)*Math.PI/180);
    foldShadowTranslate.y =  20 * Math.sin(_foldAngle*Math.PI/180) - _foldShadowAdjustment*Math.sin((90 - _foldAngle)*Math.PI/180);;

    evenPoint2.point = _x2 + ",0";
    evenPoint3.point = _x2 + ",0";

    shadowStr += Math.min((_x2+0), width) + ",0 " + _x2 + ",0";

  }
  // if the top left corner cannot be seen
  else
  {
    // update points of the odd page, which are both the same
    oddPoint1.point = "0, " + (height - _visibleLeftEdgeHeight);
    oddPoint2.point = "0, " + (height - _visibleLeftEdgeHeight);
    
    
    // update points of the even page
    var _y2 = height - _bottomLeftCornerY - (width - _bottomLeftCornerX) * Math.tan(_leftEdgeAngle*Math.PI/180);
    evenPoint2.point = width+"," + _y2 ;
    evenPoint3.point = width+",0";

    // update shadow string on top of the even page
    shadowStr += width+"," + _y2 + " "+width+"," + _y2;

    // update foldShadow properties
    var _foldAngle;
    if (x1 != width)
    {
        _foldAngle = 90 - (180/Math.PI)*Math.atan(_visibleLeftEdgeHeight/(width - x1));
    }
    else
    {
        //the arctangent of infinity is 90
        _foldAngle = 0;
    }
    if(foldShadowRotate==null )
        return;
    foldShadowRotate.angle = (-1) * _foldAngle;
    foldShadowTranslate.x = (-1) * 20 * Math.cos(_foldAngle*Math.PI/180) ;
    foldShadowTranslate.y =  (height - _visibleLeftEdgeHeight) +  20 * Math.sin(_foldAngle*Math.PI/180) ;
  }

  oddPoint3.point = (width - x1) + ", "+height;
  shadowOnEvenPage.points = shadowStr;

  if (x1 < 15)
  {
    shadowOnEvenPage.opacity = 0.25*(x1/15);
    //foldShadow.opacity = 0.6*(x1/15);
    if (oddPageNumber > 1) {  shadowBehindPage01.opacity = 0.8; }
    else {  shadowBehindPage01.opacity = 0.8 - 0.8*(x1/15); }
  }
  else
  {
    shadowOnEvenPage.opacity = 0.25;
    //foldShadow.opacity = 0.6;
    if (oddPageNumber > 1) {  shadowBehindPage01.opacity = 0.8; }
    else {  shadowBehindPage01.opacity = 0; }
  }
}
//var array = new Array(26);