﻿ 
 /*
  UI help klasse om plattegronden 'slideshow' te besturen.
  Jquery-1.3.2 moet al included zijn voordat deze klasse word geinclude.
 */
 function FloorPlanManager(){

    this._floorplans = new Array();
    this._screenSize = 5;
    this._cumulativeSize=0;
    
    this._steps = new Array();
    this._stepIndex = 0;
    this._stepSize = 157;
    this._animationBusy = false;
    
    this._listScrollTimer = null; // up/down timer voor het scrollen van de lijst van woningtypes (links)
    
 }
 
 /*
    Voeg een plattegrond toe
    
    id = unieke string waarmee plattegrond kolom bepaald kan worden
    size = aantal kolommen die de plattegrond in beslag neemt
 */
 FloorPlanManager.prototype.AddFloorplan = function(id, size){
    this._cumulativeSize += size;
    
    //voeg nieuwe plattegrond toe
    var plan = new Object();
    plan.id = id;
    plan.size = size;
    plan.cumulativeSize = this._cumulativeSize;
    
    this._steps.push(size);
    
    //voeg plattegrond toe aan de lijst
    this._floorplans.push(plan);
    
    //pijltjes goedzetten
    this.SetArrows();
    

 }
 
 /*
Beweeg scrollgebied naar links
*/
 FloorPlanManager.prototype.MoveLeft = function(){
    if (!this.CanGoLeft()){
        return;
    } 

    //alleen bewegen als er geen animatie loopt
    if (!this._animationBusy){
        //als naar links kan, beweeg met de stepsize naar links
        var diff = '+=' + (this._steps[this._stepIndex - 1] * this._stepSize).toString();
        this.Move(diff);
        this._stepIndex -= 1;
        
        //toon de zichtbare menu linkjes
        this.ShowVisibleButtons();
        
        //grens controleren
        if (this._stepIndex < 0) this._stepIndex = 0;
        
        //pijltjes goedzetten
        this.SetArrows();
    
    }
 }
 
 
/*
Beweeg scrollgebied naar rechts
*/
 FloorPlanManager.prototype.MoveRight = function(){
    if (!this.CanGoRight()){
        return;
    } 
 
    //alleen bewegen als er geen animatie loopt
    if (!this._animationBusy){
        //als naar rechts kan, beweeg met de stepsize naar rechts
        var diff = '-=' + (this._steps[this._stepIndex] * this._stepSize).toString();
        this.Move(diff);  
        this._stepIndex += 1;
        
        //highlight linker menu items
        this.ShowVisibleButtons();
        
        //check grens
        if (this._stepIndex > this._steps.length) this._stepIndex = this._steps.length;
      
        //pijltjes goedzetten
        this.SetArrows();  
    
    }
 }
 
 
 /* beweeg naar floorplan met opgegeven id */
 FloorPlanManager.prototype.MoveToFp = function(nodeId){
    var me = this;
    
    //alleen doen als er nog geen animatie loopt
    if (!me._animationBusy){
    
        //zoek node
        for (var i=0; i < this._floorplans.length; i++){
          //indien node gevonden
          if (this._floorplans[i].id == nodeId){
          
            //bereken nieuwe left property
           var moveTo = this._stepSize;
           if (i>0){
                moveTo = this._floorplans[i - 1].cumulativeSize * this._stepSize * -1 + this._stepSize;
           }
           if (!me._animationBusy){
                me._animationBusy = true;
                //animeer naar positie van gekozen plattegrond
               $("#mapScroller").stop().animate({
                           left: moveTo + 'px'
                      }, 800, function() {
                      // animate klaar
                      me._animationBusy = false;
               });
           }
              
           //zet zichtbaarheid van de knoppen
            var startColumn = 0;
            if (i > 0){
                startColumn = this._floorplans[i - 1].cumulativeSize;
            }
            this.ShowVisibleButtons(startColumn);
            this._stepIndex = i;

            this.SetArrows();
            break;
          }//if nodeId gevonden
      
      }
      
      
    }//for each floorplan
    
 
 } //MoveToFp
 
 /*
 Markeer de 'menu' linkjes die op dit moment in beeld zijn
 */
 FloorPlanManager.prototype.ShowVisibleButtons = function(startColumn){

    var startCol = 0;  
    if (startColumn == null){
        //bepaal startkolom obv step index
        for(var i=0; i < this._stepIndex; i++){
            startCol += this._steps[i];
        }
    }
    else{
        //anders obv parameter
        startCol = startColumn
    }
    var endCol = 5;
    //einde is altijd  begin + 5
    endCol = startCol + this._screenSize;
    
    //check voor iedere link of deze daarbinnen valt
    for(var i=0; i < this._floorplans.length; i++){
        //maak linkje bold indien binnen de grenzen
        if (this._floorplans[i].cumulativeSize <= endCol && this._floorplans[i].cumulativeSize > startCol){
            $(".fpLink" + this._floorplans[i].id.toString()).css("color","white");
        }
        else{
            $(".fpLink" + this._floorplans[i].id.toString()).css("color","#A5A5A5"); 
        }
    }//voor elk linkje
    
 }//show visible buttons
 
 /*
  Maak pijltjes (in)actief voor links en rechts scrollen
 */
 FloorPlanManager.prototype.SetArrows = function(){
    if (this.CanGoRight()){
        $("#mapsRight").css("backgroundImage", "url('/images/arrow_right_active.gif')").css("cursor","pointer");
    }
    else{
        $("#mapsRight").css("backgroundImage", "url('/images/arrow_right_inactive.gif')").css("cursor","default");
    }
    if (this.CanGoLeft()){
        $("#mapsLeft").css("backgroundImage", "url('/images/arrow_left_active.gif')").css("cursor","pointer");
    }
    else{
        $("#mapsLeft").css("backgroundImage", "url('/images/arrow_left_inactive.gif')").css("cursor","default");
    }
        
 } //SetArrows
 
 /*
  Kan naar rechts scrollen?
 */
 FloorPlanManager.prototype.CanGoRight = function(){
    return (this._stepIndex < this._steps.length - 1);
 }
 
 /*
  Kan naar links scrollen?
 */
 FloorPlanManager.prototype.CanGoLeft = function(){
    return (this._stepIndex > 0);
 }
 
 /*
  Verplaats scroll container naar opgegeven naar diff (het verschil met huidige positie).
 */
 FloorPlanManager.prototype.Move = function(diff){
    var me = this;
    
    if (!me._animationBusy){
        me._animationBusy = true;
        $("#mapScroller").stop().animate({
            left: diff
          }, 800, function() {
                // animate klaar
                me._animationBusy = false;
        });
    } //if busy
} //Move
 
 
/*
 Start de timer die de scrollfunctie aanroept.
 direction = 1 voor omhoog, -1 voor omlaag
*/
 FloorPlanManager.prototype.ScrollList = function(direction)
 {
    
    this._listScrollTimer = setInterval("fpMan.ScrollListGo(" + direction + ")", 20);
 }

/*
 Stopt de timer die de scrollfunctie aanroept
*/
 FloorPlanManager.prototype.ScrollListStop = function()
 {
    clearTimeout(this._listScrollTimer);
    this._listScrollTimer = null;
 }

/*
 Scrollt de container div nara nieuwe positie
*/
 FloorPlanManager.prototype.ScrollListGo = function(direction)
 {
    var scrollDiv = $("#mapListScrollContainer");
    scrollDiv.scrollTop(scrollDiv.scrollTop() + direction * -15);
 } 
 
 /*
  Initialisatie functie om uit te voeren on document.ready()
 */
 FloorPlanManager.prototype.Init = function () {
     //linkjes highlighten
     this.ShowVisibleButtons(0);
     //scroll pijltjes goedzetten
     this.SetArrows();

     //totale breedte aanpassen van scroll div
     $(".MapScroller").css("width", this._cumulativeSize * this._stepSize);

     //controleer of verticale scrollbuttons zichtbaar moeten zijn (indien te veel items in lijst)
     var scrollContainer = $("#mapListScrollContainer")[0];
     if (scrollContainer.clientHeight < scrollContainer.scrollHeight) {
         $(".MapsUpButton").show();
         $(".MapsDownButton").show();
     }

 }

 //wordt aangeroepen vanuit parent venster met parent.ShowFloorplan(x);
 //toont de lightwindow met plattegrond en zoom functie
 function ShowFloorplan(id) {

    //controleer of de lightwindows al aanwezig zijn in dit document. Zo niet dan is de pagina waarschijnlijk in een iframe geladen
     if ($(".FloorplanLightWindow").length == 0) {
         try {
             //kopieer (kopie van!) de lightwindows naar parent window. Zonder de clone methode gaat het mis in sommige browsers
             $("#floorplans").append($(".FloorplanLightWindow", $("#projectsiteFrame").contents()).clone());
         }
         catch (ex) {
            //alert(ex);
         }
     }
    
         $(".lightWin" + id).dialog({ modal: true, autoOpen: false, width: 1000, height: 550, dialogClass: 'FloorplanLightwindow' }).dialog('open');
         $('.jqZoomWindow').show(); 
         $(".fp_zoom" + id).jqzoom(zoomOptions, $(".lightWin" + id));
         PositionZoomContainer(id);
 }

 //verberg de plattegronden popup
 function HideFloorplan(id) {
      $('.jqZoomPup').remove();
     $('.zoom_ieframe').hide();
     $('.jqZoomWindow').hide().remove();
     $('.lightWin' + id).dialog('close');
 }

