
//------------- TopDestinationContentRenderer -------------------------------------

function TopDestinationContentRenderer(aName)
{
  this.name = aName;
  this.applicationModel=null;
  this.id = '__'+aName;
  this.width=600;
  this.height=450;
  this.imgwidth=185;
  this.imgheight=110;
  this.maxColCount=3;
  this.topOffset=0;
 
  this.xmlReader=new ReaderFactory().createXmlReader(null);

  this.toString = toFlightContent;
  this.setVisible = setFlightContentVisible;
  this.show = initTopDiv;
  this.flightContentContainer= null;

  this.flightRequestor = null;
  
  this.url;



  this.selectionListener = new Array();
  this.defaultImages=['img/top/top_lon.jpg','img/top/top_mai.jpg',
  'img/top/top_madrid.jpg','img/top/top_nyc.jpg','img/top/top_par.jpg',
  'img/top/top_rom.jpg','img/top/top_zur.jpg'];
  window.topDestinationContentRenderer= this;
  this.book=null;
  this.currentNo=0;  
  this.moveElementObj;
  this.moveOutElementObj = null;
  this.moveTimer;
  this.moveOutOffset=190;
  this.moveSteps=20;
  this.inMovement=false;
  this.waitingPeriod=15;//waiting time between 2 steps in img movement
  this.model=null;
  this.FORTH='forth';
  this.BACK='back';
  this.rollDirection=this.FORTH;
  
  this.siteChanger=null;
  
  this.defaultMessage=new TopLoadingListener(this).message;

  return this;
}

TopDestinationContentRenderer.prototype.moveOut= function(anElement, anOutElement)
{
  this.roll(this.BACK, anElement, anOutElement);
}

TopDestinationContentRenderer.prototype.moveIn= function(anElement, anOutElement)
{
  this.roll(this.FORTH, anElement, anOutElement);
}

TopDestinationContentRenderer.prototype.roll= function(aDir, anElement, anOutElement)
{
  this.rollDirection = aDir;
  if(this.inMovement)
  {
    return;
  }
  if(!anElement)
  {
    return;
  }
  var theMax = this.moveOutOffset;

  if (aDir==this.FORTH)
  {
    anElement.style.left= theMax+'px';
  }
  else
  {
    anElement.style.left= '-'+theMax+'px';
  }
  anElement.style.zIndex='1';


  this.inMovement=true;
  this.moveElementObj = anElement;
  this.moveOutElementObj = anOutElement;
  if(anOutElement != null)
  {
    anOutElement.style.zIndex='0';
  }
  this.moveElementObj.style.visibility='';//visible';
  this.moveTimer = setInterval("window.topDestinationContentRenderer.moveElement()",this.waitingPeriod);
}

TopDestinationContentRenderer.prototype.moveElement = function()
{
  var theStep = this.moveSteps;

 
  if (!this.moveElementObj)
  {
    clearInterval(this.moveTimer);
    this.inMovement=false;
    return;
  }
  var theOutPos=0;
  if (this.moveOutElementObj != null)
  {
    var theOutPosString = this.moveOutElementObj.style.left;
    theOutPos = theOutPosString.replace('px', '');
    theOutPos = Math.round(theOutPos);

  }

  var thePosString = this.moveElementObj.style.left;
  var thePos = thePosString.replace('px', '');
  thePos = Math.round(thePos);
  
  if (this.rollDirection==this.FORTH)
  {
    
    if (thePos > 0)
    {
      thePos = thePos-theStep;
      theOutPos = theOutPos-theStep;
      this.moveElementObj.style.left= thePos+'px';
  
      if (this.moveOutElementObj != null)
      {
       this.moveOutElementObj.style.left= theOutPos+'px';
      }
    }
    else
    {
      clearInterval(this.moveTimer);
      this.inMovement=false;
      if (this.moveElementObj)
      {
        this.moveElementObj.style.left= '0px';
        this.moveElementObj=null;
      }
      if(this.moveOutElementObj != null)
      {
        this.moveOutElementObj.style.visibility='hidden';
        this.moveOutElementObj.style.left='0px';
        this.moveOutElementObj=null;
      }
     }
  }
  else if (this.rollDirection==this.BACK)
  {
    if (thePos < 0)
    {
      thePos = thePos+theStep;
      theOutPos = theOutPos+theStep;
      this.moveElementObj.style.left= thePos+'px';
  
      if (this.moveOutElementObj != null)
       this.moveOutElementObj.style.left= theOutPos+'px';
    }
    else
    {
      clearInterval(this.moveTimer);
      this.inMovement=false;
      if (this.moveElementObj)
      {
        this.moveElementObj.style.left= '0px';
        this.moveElementObj=null;
      }
      if(this.moveOutElementObj != null)
      {
        this.moveOutElementObj.style.visibility='hidden';
        this.moveOutElementObj.style.left='0px';
        this.moveOutElementObj=null;
      } 
    }
  }
}


TopDestinationContentRenderer.prototype.changeSite = function(aDir)
{
  if(this.book.pageCount() <= 1)
  { 
    return;
  }
  if (aDir == this.FORTH)
  {
    if (this.currentNo < (this.book.pageCount() - 1))
    {
      var theOldElement = document.getElementById('top_dest_page_'+this.currentNo);
  
      this.currentNo++;
      var theElement = document.getElementById('top_dest_page_'+this.currentNo);
      if (theElement==null)
      {
        alert("no element found for id top_dest_page_"+this.currentNo);
      }
      this.roll(aDir,theElement, theOldElement);
    }
    else
    {
      return;  
    }    
  }
  else
  {
  
    if (this.currentNo > 0)
    {
      var theOldElement = document.getElementById('top_dest_page_'+this.currentNo);
  
      this.currentNo--;
      var theElement = document.getElementById('top_dest_page_'+this.currentNo);
      if (theElement==null)
      {
        alert("no element found for id top_dest_page_"+this.currentNo);
      }
      this.roll(aDir,theElement, theOldElement);
    }    
  }
}

TopDestinationContentRenderer.prototype.addSelectionListener = function (aSelectionListener)
{
  this.selectionListener[this.selectionListener.length]=aSelectionListener;
}

TopDestinationContentRenderer.prototype.selectTopDestination=function(aOfferId, aTopOfferId)
{
  var theOffer = this.applicationModel.getFlightOffer(aOfferId);
  if (!theOffer)
  {
    alert("NO OFFER FOR "+aOfferId);
    return;
  }
  var theEvent = new TopSelectionEvent(aOfferId,aTopOfferId,theOffer);
  var i;
  for (i=0;i<this.selectionListener.length;i++)
  {
    this.selectionListener[i].selectionEventReceived(theEvent);
  }
}

TopDestinationContentRenderer.prototype.init=function(aUrl)
{
	this.url = aUrl;
	if(this.flightRequestor != null)
	{
		this.flightRequestor.callUrl(aUrl);
	}
	else
	{
		alert("flight requestor  not set");
	}
}

TopDestinationContentRenderer.prototype.setFlightRequestor=function(aFlightRequestor)
{
	this.flightRequestor = aFlightRequestor;
	this.flightRequestor.addListener(new TopLoadingListener(this));
}

TopDestinationContentRenderer.prototype.createSiteChanger=function()
{

  if (this.siteChanger == null)
  {
    this.siteChanger = new BookPageChanger(this.name+'_1',this);
  }
  
  return this.siteChanger.createElement();
}

function initTopDiv()
{
  var theParent=new DIVElement();
  theParent.addAttribute('id', 'border_'+this.id);
  theParent.addAttribute('class', 'topdest_border');
  theParent.addElement(this.createSiteChanger());

  var theElement = new DIVElement();
  theElement.addAttribute('id', this.id);
  theElement.addAttribute('class', 'topdestination_container');
  theElement.addStyleElement('width', '600px');
  theElement.addStyleElement('height', this.height+'px');
  theElement.addStyleElement('left', '0'+'px');
  theElement.addStyleElement('top', '-10'+'px');
  theParent.addElement(theElement);
  theElement.addContent(this.defaultMessage);
  return theParent.write();
}

TopDestinationContentRenderer.prototype.setFlightContent=function(aContentModel)
{
  if (this.flightContentContainer == null)
  {
    this.flightContentContainer = document.getElementById(this.id);
  }
  this.applicationModel=aContentModel;
  this.currentNo = 0;
  var theContent = this.generateContent(aContentModel);
  if(theContent != null)
  {
    
  	this.flightContentContainer.innerHTML=theContent;
  	var theElement = document.getElementById('top_dest_page_'+this.currentNo);
  	if (theElement==null)
    {
      return;
    }
  }
}

TopDestinationContentRenderer.prototype.generateContent=function(aModel)
{
	if(aModel.getTopListLength()==0)
	{
		return '';
	}
	var i = 0;
	var realIterator = 0;
	var theNode;
	var theLength = aModel.getTopListLength();
	var theSite = 0;
	var theCount = 0;
	var theCurrentSite = -1;
	this.book = new Book();
	var thePage = null;
	var theContent = null;
	
	for (i = 0; i<theLength; i++)
	{
		theSite = realIterator%12;
		realIterator++;
		if (theSite==0)
		{
			theCurrentSite++;
			thePage = new BookPage('top_dest_page_',theCurrentSite)
			this.book.add(thePage);
			theCount = 0;			
			i = (i - 8) > 0 ? i - 8 : i;			
		} else {
			theCount++;
		}
		var theTopOffer=aModel.getTopOffer(i);
		var theDivElement = new DIVElement();
		thePage.add(theDivElement);
		theDivElement.addAttribute('id','TopDest_'+i);
		this.setTopImgStyle(theDivElement, theCount);
		var theUrl = theTopOffer.getImgUrl();
		if (theUrl == null || theUrl == '')
		{
			theUrl = this.defaultImages[i%7];//'img/top/top_lon.jpg';
		}
		var theImgElement = new ElementTag('img'); 
		theImgElement.addAttribute('src',theUrl);
		theImgElement.addAttribute('alt','TopOfferImage');
		
		theDivElement.addElement(theImgElement);
		var theCityElement = new DIVElement();
		this.setCityStyle(theCityElement);
		
		var theCity = new PElement();
		theCity.addContent(this.getCityName(theTopOffer));
		theCityElement.addElement(theCity);
		
		theDivElement.addElement(theCityElement);
		var theTextIntro = new DIVElement();
		this.setIntroStyle(theTextIntro);
		
		theDivElement.addElement(theTextIntro);
		
		for(var theIdCount=0;theIdCount<this.maxColCount;theIdCount++)
		{
			var theOffer = theTopOffer.getOffer(theIdCount);
			if (theOffer !=null)
			{
				this.addOfferData(theDivElement, theTopOffer, theOffer,theCount, theIdCount)
			}
		}
	 }
	 this.siteChanger.checkButtons();
	 return this.book.write();
}


TopDestinationContentRenderer.prototype.addOfferData=function(aDivElement, aTopOffer, aOffer, aCount, aIdCount)
{
  	var theParameters='\''+aOffer.getOfferId()+'\',\''+aTopOffer.getId()+'\'';    		
        var theTextDiv = new DIVElement();    	
      	var theTextElement= new PElement();
    	this.setTopText(theTextElement, aIdCount, aOffer);    	
      	theTextDiv.addElement(theTextElement);
    	this.setTopTextStyle(theTextDiv, aCount, aIdCount);    	
        var thePElement = new PElement();
    	thePElement.addAttribute('onclick','javascript:window.topDestinationContentRenderer.selectTopDestination('+theParameters+');');
    	thePElement.addAttribute('onmouseover','document.body.style.cursor=\'pointer\';');
        thePElement.addAttribute('onmouseout','document.body.style.cursor=\'default\';');
  		thePElement.addContent(aOffer.getPrice() + '&#8364; p.P.');
        var theSubDiv = new DIVElement();
        theSubDiv.addElement(thePElement);
        this.setTopPriceStyle(theSubDiv, aCount, aIdCount);        
        aDivElement.addElement(theTextDiv);
        aDivElement.addElement(theSubDiv);
}


TopDestinationContentRenderer.prototype.getCityName=function(aTopOffer)
{
   var theOffer = null;
   for (var i = 0; i<3 && theOffer==null; i++)
   {
      if(aTopOffer.getOffer(i))
      {
        theOffer = aTopOffer.getOffer(i);
      }
   }
   if (theOffer)
   {
      return theOffer.getTo();
   }
   return ' - ';
}

TopDestinationContentRenderer.prototype.setCityStyle=function(aElement)
{
   aElement.addAttribute('class','top_city_name');
   aElement.addStyleElement('position','absolute'); 
   aElement.addStyleElement('top',(3)+'px');
   aElement.addStyleElement('left',(1)+'px');// width:'+(this.imgwidth-2)+'px;
   aElement.addStyleElement('width','178px'); 
   aElement.addStyleElement('z-index','17');
   aElement.addStyleElement('height','20px'); 
   aElement.addStyleElement('overflow','visible'); 
   aElement.addStyleElement('text-align','center');
}


TopDestinationContentRenderer.prototype.setTopImgStyle=function(aElement, aNumber)
{
   var thePosIndicator = parseInt(aNumber/4);
   var theHeightIndicator = aNumber%4;
   aElement.addAttribute('class','tabheader'); 
   aElement.addStyleElement('position','absolute');
   aElement.addStyleElement('z-index','2');
   aElement.addStyleElement('top',((this.imgheight*theHeightIndicator)+10)+'px');
   aElement.addStyleElement('left',((thePosIndicator*this.imgwidth)+20)+'px');
}


TopDestinationContentRenderer.prototype.setTopText=function(aElement, aTextIndicator, aOffer)
{
   var theCode = aOffer.getFromIataCode();
   if (aTextIndicator ==0)
   {
    aElement.addContent("7 Tage "+theCode);
   }
   else if (aTextIndicator==1)
   {
    aElement.addContent("30 Tage "+theCode);
   }
   else if (aTextIndicator==2)
   {
    aElement.addContent("90 Tage "+theCode);
   }
}

TopDestinationContentRenderer.prototype.setIntroStyle=function(aElement)
{
   aElement.addAttribute('class','top_offer_intro'); 
   aElement.addStyleElement('z-index','18');
   var theText = new PElement();
   theText.addContent('in den n&#228;chsten ...');
   aElement.addElement(theText);
}

TopDestinationContentRenderer.prototype.setTopPriceStyle=function(aElement, aNumber, aTextIndicator)
{
   aElement.addAttribute('class','top_offer_price_'+aTextIndicator );
   aElement.addStyleElement('z-index','18');
}

TopDestinationContentRenderer.prototype.setTopTextStyle=function(aElement, aNumber, aTextIndicator)
{
   aElement.addAttribute('class','top_offer_text_'+aTextIndicator );
   aElement.addStyleElement('z-index','18');
}

function PageContent()
{
	this.string='';
  	this.write=writePageContent;
  	this.add=addPageContent;
}

function addPageContent(aString)
{
  this.string+=aString;
}

function writePageContent()
{
  return this.string;
}

function BookPage (anIdPrefix, aCounter)
{
  this.id=''+anIdPrefix+aCounter;
  this.counter=aCounter;
  
  this.beginWrapper1=new DIVElement();
  this.beginWrapper1.addAttribute('id',this.id);
  if (aCounter > 0)
  this.beginWrapper1.addStyleElement('visibility', 'hidden');  
  this.beginWrapper1.addStyleElement('position', 'absolute');
  this.beginWrapper1.addStyleElement('left', '0px');
  this.beginWrapper1.addStyleElement('top', '0px');  
}

BookPage.prototype.setVisible=function(aBoolean)
{
    var theElement = document.getElementById(this.id);
    if (!aBoolean)
      theElement.style.visibility='hidden';
    else
      theElement.style.visibility='';
}

BookPage.prototype.add=function(aPageContent)
{
  this.beginWrapper1.addElement(aPageContent);
}

BookPage.prototype.write=function()
{
  return this.beginWrapper1.write();
}

BookPage.prototype.getElement=function()
{
  return this.beginWrapper1;
}

function Book()
{
  this.add=addBookPage;
  this.pages=new Array();
  this.write=writeBook;

  this.setVisible=setPagesVisible;
  this.currentPage=0;
  this.nextPage=nextBookPage;
  this.changeToBeginPage=changeToBeginPage;
  this.changeToNextPage=changeToNextPage;
}

function nextBookPage()
{
  if (this.currentPage < (this.pages.length-1))
  {
    this.changeToNextPage();
  }
  else
  {
    this.changeToBeginPage();
  }
}

function  changeToNextPage()
{

}

function  changeToBeginPage()
{

}

function addBookPage(aPage)
{
  this.pages[this.pages.length]=aPage;
}

function writeBook()
{
  var theElement=new DIVElement();
  theElement.addStyleElement('position','absolute');
  theElement.addStyleElement('top', 0+'px');
  theElement.addStyleElement('left', 0+'px');
  theElement.addStyleElement('clip', 'rect(0px, 580px, 450px, 0px)');

  for (var i=0;i<this.pages.length;i++)
  {
    theElement.addElement(this.pages[i].getElement());
  }
  return theElement.write();
}

Book.prototype.pageCount=function()
{
  return this.pages.length;
}

function setPagesVisible(aBoolean)
{
  for (var i=0;i<this.pages.length;i++)
  {
    this.pages[i].setVisible(aBoolean);
  }
}

function SitePosIndicator(aNumber, aName)
{
  this.imgNotSelected='img/kontroll_0.gif';
  this.imgSelected='img/kontroll_1.gif';
  this.number = aNumber;
  this.elements=new Array();
  this.id=aName;
  this.ids=new Array();
  this.top=0;
  this.left=0;
  this.selected = 0;
  this.selectedImg=null;
  this.unselectedImg=null;
  this.elementWidth=10;
  this.elementHeight=10;
  this.init();

}

SitePosIndicator.prototype.initPos=function(aTop, aLeft)
{
  this.top=aTop;
  this.left=aLeft;
}

SitePosIndicator.prototype.init=function()
{
  this.selectedImg=new ElementTag('img');
  this.selectedImg.addAttribute('src', this.imgSelected);
  this.selectedImg.addAttribute('alt', 'selected');

  this.unselectedImg=new ElementTag('img');
  this.unselectedImg.addAttribute('src', this.imgNotSelected);
  this.unselectedImg.addAttribute('alt', 'unselected');
  for(var i=0; i<this.number; i++)
  {
    this.ids[i]=this.name+'_'+i;
  }
}

SitePosIndicator.prototype.setNumber=function(aNo)
{
  this.number = aNo;
}

SitePosIndicator.prototype.select=function(aNo)
{
  var theNew = Number(aNo);
  if (theNew == this.selected)
  {
    return;
  }
  if (!this.elements[theNew])
  {
    this.elements[theNew]=document.getElementById(this.ids[theNew]);
  }
  var theOld = this.selected;
  this.selected=theNew;
  if (this.elements[theNew])
  {
    var theElement = this.elements[theNew];
    theElement.innerHTML=this.selectedImg.write();
  }

  if (!this.elements[theOld])
  {
    this.elements[theOld]=document.getElementById(this.ids[theOld]);
  }
  if (this.elements[theOld])
  {
    this.elements[theOld].innerHTML=this.unselectedImg.write();
  }

}

SitePosIndicator.prototype.update=function(aNo)
{
  this.setNumber(aNo);
  this.select(0);
  var theParent = document.getElementById(this.id);
  if (theParent)
  {
   var theInner = '';
   for(var i=0; i<this.number; i++)
   {
    var theNext = this.createPos(i);
    theInner+=theNext.write();
   }
   theParent.innerHTML=theInner;
  }
}


SitePosIndicator.prototype.createElement=function(aNo)
{
  var theParent = new DIVElement();
  theParent.addAttribute('class', 'site_pos_indicator');
  theParent.addAttribute('id', this.id);
  theParent.addStyleElement('position','absolute');
  theParent.addStyleElement('top',this.top+'px');
  theParent.addStyleElement('left',this.left+'px');
  theParent.addStyleElement('width', (this.number*this.elementWidth)+'px');
  theParent.addStyleElement('z-index', '450');

  for(var i=0; i<this.number; i++)
  {
    var theNext = this.createPos(i);
    theParent.addElement(theNext);
  }
  return theParent;
}

SitePosIndicator.prototype.getId=function(aNo)
{
  var theId = this.ids[aNo];
  if (!theId)
  {
    theId = this.id+'_'+aNo;
    this.ids[aNo]=theId;
  }

  return theId;
}

SitePosIndicator.prototype.createPos=function(aNo)
{
  var theParent = new DIVElement();
  theParent.addAttribute('class', 'site_pos_indicator_n');
  theParent.addAttribute('id', this.getId(aNo));
  theParent.addStyleElement('position','absolute');
  theParent.addStyleElement('top',0+'px');
  theParent.addStyleElement('left',(aNo*this.elementWidth)+'px');
  theParent.addStyleElement('width', (this.elementWidth)+'px');
  theParent.addStyleElement('height', (this.elementHeight)+'px');
  theParent.addStyleElement('z-index', 10);
  if (aNo==0)
  {
    theParent.addElement(this.selectedImg);
    this.selected=0;
  }
  else
  {
    theParent.addElement(this.unselectedImg);
  }
  return theParent;
}


function TopLoadingListener(aTopRenderer)
{
  this.diagram=aTopRenderer;
  this.message = '<div style="'+this.getStyle()+'"><H1></H1></div>';
  this.message += '<div style="position:absolute; top:150px; left: 230px; width: 160px"><img src="img/wait_ajax.gif" alt=""/></div> ';
}

TopLoadingListener.prototype.getStyle=function()
{
  var theStyle='';
      theStyle+='position:absolute; top:0px; left: 5px; width: 60px; color:gray; vertical-align: middle;';
      theStyle+=' text-align: left; font-family:Arial, Helvetica, sans-serif; font-size:11px; height:13px;';
  return theStyle;
}

TopLoadingListener.prototype.requestPerformed=function(anEvent)
{
  if (anEvent.action=='STARTED')
  {
    if (this.diagram.flightContentContainer == null)
    {
       this.diagram.flightContentContainer = document.getElementById(this.diagram.id);
    }
    if (this.diagram.flightContentContainer != null)
    {
      this.diagram.flightContentContainer.innerHTML=this.message;
    }
  }
}
// JavaScript Document




function TopSelectionEvent(aDestinationId, aTopOfferId, aOffer)
{
  this.destination = aDestinationId;
  this.topOfferId=aTopOfferId;
  this.offer=aOffer;
}

TopSelectionEvent.prototype.getOffer=function()
{
  return this.offer;
}


function TopDestinationSelectionListener(aDepRequestor, aDestRequestor, aTabPane, aTabNo, aDiagram)
{
  this.destRequestor=aDestRequestor;
  this.depRequestor=aDepRequestor;
  this.tabPane=aTabPane;
  this.tabNo=aTabNo;
  this.cal = new GregorianCalendar();
  this.diagram=aDiagram;

}
TopDestinationSelectionListener.prototype.selectionEventReceived=function(aSelectionEvent)
{
  var theOffer = aSelectionEvent.getOffer();
  this.depRequestor.setDestinationLocation(theOffer.getTo());
  this.depRequestor.setDepartureLocation(theOffer.getFrom());
  this.depRequestor.setStartDate(this.cal.print(theOffer.getDate()));
  this.depRequestor.setEndDate(null);
  this.depRequestor.set('offerId', theOffer.getOfferId());
  this.depRequestor.setFromIataCode(theOffer.getFromIataCode());
  this.depRequestor.setToIataCode(theOffer.getToIataCode());
  
  this.destRequestor.setDestinationLocation(theOffer.getFrom());
  this.destRequestor.setDepartureLocation(theOffer.getTo());
  this.destRequestor.setStartDate(this.cal.print(theOffer.getDate()));
  this.destRequestor.setEndDate(null);
  this.destRequestor.setFromIataCode(theOffer.getToIataCode());
  this.destRequestor.setToIataCode(theOffer.getFromIataCode());
  
  this.depRequestor.callFlights();
  this.destRequestor.callFlights();
  // resetting offer Id
  this.depRequestor.set('offerId', '');
  this.diagram.setSelectedOffer(theOffer);
  this.tabPane.selectTab(this.tabNo);
}

// SelectionListener

function DiagramTabNotifier(aTabbedPane, aTabNumber, aDiagramContent)
{
  this.tabPane=aTabbedPane;
  this.tabNo=aTabNumber;
  this.diagram=aDiagramContent;
}

DiagramTabNotifier.prototype.selectionEventReceived=function(aSelectionEvent)
{
  this.tabPane.setVisible(this.tabNo);  
  this.diagram.selectDiagramBar(aSelectionEvent.destination, aSelectionEvent.topOfferId);
}




function BookPageChanger(aName, aDiagram)
{
  this.FORTH='forth';
  this.BACK='back';
  this.DISABLED=0;
  this.ENABLED=1;
  this.diagram=aDiagram;
  this.parentElement= null;
  
  this.id='b_pg_'+aName;
  this.leftButtonName =this.id+'_l';
  this.rightButtonName =this.id+'_r';
  
  this.buttons=new Array();
  this.buttons[this.leftButtonName]=
    new IconButton(this.leftButtonName, 'img/subnav_pfeil_links_weiss_halb.gif','img/subnav_links_ohne_pfeil_halb.gif','img/subnav_pfeil_links_grau_halb.gif');
    
  this.buttons[this.leftButtonName].mouseOverText='- vorangehende';
  this.buttons[this.leftButtonName].addActionListener(new PrevAction(this));
  this.buttons[this.leftButtonName].setPosition(0,0);
  
  this.buttons[this.rightButtonName]=
  new IconButton(this.rightButtonName, 'img/subnav_pfeil_rechts_weiss_halb.gif','img/subnav_rechts_ohne_pfeil_halb.gif','img/subnav_pfeil_rechts_grau_halb.gif');
  
  this.buttons[this.rightButtonName].mouseOverText='- n&#228;chste';
  this.buttons[this.rightButtonName].addActionListener(new NextAction(this));
  this.buttons[this.rightButtonName].setPosition(0,(this.diagram.width - 16));
  
  window[this.id]=this;
  
  
}




BookPageChanger.prototype.next=function()
{
  nd(20);
  this.changeSite(this.FORTH);
}


BookPageChanger.prototype.prev=function()
{
  nd(20);
  this.changeSite(this.BACK);
}


BookPageChanger.prototype.changeSite=function(aDirection)
{
  this.diagram.changeSite(aDirection);
  this.checkButtons();
}

BookPageChanger.prototype.checkButtons=function()
{
  

  if(this.diagram.currentNo == 0)
  {
    this.buttons[this.leftButtonName].setEnabled(false);
    if (this.diagram.book.pageCount()>1)
    {    
      this.buttons[this.rightButtonName].setEnabled(true);  
    }
  }
  else if (this.diagram.currentNo == (this.diagram.book.pageCount()-1)) 
  {
    this.buttons[this.rightButtonName].setEnabled(false);
    if (this.diagram.currentNo > 0)
    {
     this.buttons[this.leftButtonName].setEnabled(true);
    }
  }
  else
  {
    if (this.diagram.book.pageCount()>1)    
    {
      this.buttons[this.rightButtonName].setEnabled(true);
    }
    if (this.diagram.currentNo > 0)
    {
     this.buttons[this.leftButtonName].setEnabled(true);
    }
  }
}

BookPageChanger.prototype.enableButton=function(anId)
{
 
 if (this.leftButtonElement == null)
  {
    this.leftButtonElement = document.getElementById(this.leftButtonName);
  }
  if (this.rightButtonElement == null)
  {
    this.rightButtonElement = document.getElementById(this.rightButtonName);
  }
}


BookPageChanger.prototype.createElement=function()
{
  if (this.parentElement==null)
  {
    var theParent = new DIVElement();
    theParent.addAttribute('class','top_changer_container');
    theParent.addAttribute('id','top_page_changer_container');
    theParent.addStyle('position:absolute; top:200px; left:0px; z-index:13;');
  
  
    var theInElement = this.buttons[this.leftButtonName].getElement();
    var theElement = this.buttons[this.rightButtonName].getElement();
  
    theParent.addElement(theInElement);
    theParent.addElement(theElement);
    this.parentElement =  theParent;
  }
  return this.parentElement;
}



function NextAction(aDiagram)
{ 
  this.diagram=aDiagram;
}

NextAction.prototype.actionPerformed=function(anAction)
{
  this.diagram.next();
}


function PrevAction(aDiagram)
{ 
  this.diagram=aDiagram;
}

PrevAction.prototype.actionPerformed=function(anAction)
{
  this.diagram.prev();
}
