
init.waitForSingleJsFile('component.libsJs_swfObject1x5.js', function(){content['siteBuilding'] = Class.create({

  THREAD_ID: null,
  EXEC_UID: null,
  arrParams:  null,

  initialize: function(arrInstVars, arrParams)
  {
    this.THREAD_ID = arrInstVars.THREAD_ID;
    this.EXEC_UID  = arrInstVars.EXEC_UID;
    this.arrParams = arrParams;
    
    $('floorTab').observe('click', this._showFloorTab.bind(this));
    $('photoTab').observe('click', this._showPhotoTab.bind(this));
    
    $('buildingPlus').observe('click', this._buildingPlus.bind(this));
    $('buildingMinus').observe('click', this._buildingMinus.bind(this));
    
    $('floorPlus').observe('click', this._floorPlus.bind(this));
    $('floorMinus').observe('click', this._floorMinus.bind(this));
    
    $(document).observe('prj:chooseBuilding', this._onChooseBuilding.bind(this));
    
    this.arrImages = $$('div.content a[_name="photos"]');
    this.arrImages.each(function(el)
    {
        el.observe('click', this._showLargePhoto.bind(this))
    }.bind(this));
    
    
    this.elPlan = $('plan');
    if(this.elPlan)
    {
        var strId = init.genUnicId();
        this.objSWF = new SWFObject('/swf/sitePlan2.swf', 
          strId, 
          "873", 
          "299",
          "9",
          "#FFFFFF"
          );
        this.objSWF.addParam('allowScriptAccess', 'always');
        this.objSWF.addVariable('strJSON', this.arrParams._strJSON);
        this.objSWF.addVariable('intDefaultFloor', 1);
        this.objSWF.addVariable('intDefaultBuilding', 1);
        this.objSWF.useExpressInstall('/swf/expressinstall.swf');
        
          
        this.objSWF.write('plan');
        this.elSwf = $(strId);    
    }
    
    $$('a[name="floor"]').invoke('observe', 'click', this._onFloorClick.bind(this));
    
    this._changeFloor.bind(this).defer();
  },
  _onFloorClick: function(evt)
  {
    var el = evt.element();
    if(!el.getAttribute('_floor')) el = el.up('[_floor]');
    
    this._changeFloor(el.getAttribute('_building'), el.getAttribute('_floor'));
  },
  _onChooseBuilding: function(evt)
  {
    this._changeFloor(evt.memo.intBuildingNum);
  },
  _floorPlus: function()
  {
    if($F('activeFloorNumber')==15)
    {
      return;
    }
    
    var intFloor = $F('activeFloorNumber') == 12 ? 14 : parseInt($F('activeFloorNumber'))+1;
    
    this._changeFloor(false, intFloor);
  },
  _floorMinus: function()
  {
    if($F('activeFloorNumber')==1)
    {
      return;
    }    
    var intFloor = $F('activeFloorNumber') ==14 ? 12 : parseInt($F('activeFloorNumber'))-1;
    
    this._changeFloor(false, intFloor);
  },
  _buildingPlus: function()
  {
    this._changeFloor($F('activeBuildingNumber')==3 ? null : parseInt($F('activeBuildingNumber'))+1);
  },
  _buildingMinus: function()
  {
    this._changeFloor($F('activeBuildingNumber')==1 ? null : parseInt($F('activeBuildingNumber'))-1);
  },
  _changeFloor: function(intBuilding, intFloor)
  {
    intBuilding = intBuilding || $F('activeBuildingNumber');
    intFloor = intFloor || $F('activeFloorNumber');
    
    $('floorMinus').removeClassName('inactiveTop');
    $('floorPlus').removeClassName('inactiveTop');
    if(intFloor==15)
    {
      $('floorPlus').addClassName('inactiveTop');
    }
    if(intFloor==1)
    {
      $('floorMinus').addClassName('inactiveTop');
    }
    
    $('textFloorNumber').update(intFloor);
    
    var intOfficeQuan = $$('[name="floor"][_building="'+intBuilding+'"][_floor="'+intFloor+'"]')[0].getAttribute('data-officeQuan');
    if(intOfficeQuan>0)
    {
      $$('#floorTab *[name="text"]')[0].show(); 
      $$('#floorTab *[name="text"]')[1].hide();
      
      $$('#floorTab *[name="text"]')[0].down('span').update(intOfficeQuan);
    }
    else
    {
      $$('#floorTab *[name="text"]')[0].hide(); 
      $$('#floorTab *[name="text"]')[1].show();
    }
    
    $$('h1.cmp_frgPageName')[0].innerHTML = $F('header'+intBuilding);
    
    $('textBuildingNumber').innerHTML = $F('builldingName'+intBuilding);
    
    $('buildingPlus').addClassName('active');
    $('buildingMinus').addClassName('active');
    
    if(intBuilding==1)
    {
      $('buildingMinus').removeClassName('active');
    }
    if(intBuilding==3)
    {
      $('buildingPlus').removeClassName('active');
    }
    
    var n = {_1: 'a',_2: 'b',_3: 'c'}
    $('mainBuilding').removeClassName('a').removeClassName('b').removeClassName('c').addClassName(n['_'+intBuilding]);
    
    $('activeBuildingNumber').value = intBuilding; 
    $('activeFloorNumber').value = intFloor; 
    
    $$('[name="floorNum"]').invoke('removeClassName', 'active');
    $$('[name="floorNum"][data-floor="'+intFloor+'"]').invoke('addClassName', 'active');
    
    $$('[data-column="yes"][_building]').invoke('removeClassName', 'active');
    $$('[data-column="yes"][_building="'+intBuilding+'"]').invoke('addClassName', 'active');
    
    if(!$('floorsList').hasClassName('big'))
    {
      $$('[data-name="results"]').invoke('hide');  
      $$('[data-name="results"][_building="'+intBuilding+'"]').invoke('show');
    }
    else
    {
      $$('[name="columnName"]').invoke('show');
    }
    
    try
    {
      if(intFloor>=13)
      {
        intFloor--;
      }
      this.elSwf.action('showFloor', {intBuildingNum:intBuilding, intFloorNum:intFloor});
    }catch(e){}
  },
  _showFloorTab: function()
  {
    $('floorTab').addClassName('active');
    $('photoTab').removeClassName('active');
    $$('[name="photos"]')[0].hide();
    $$('[name="plan"]')[0].show();
  },
  _showPhotoTab: function()
  {
    $('floorTab').removeClassName('active');
    $('photoTab').addClassName('active');
    $$('[name="photos"]')[0].show();
    $$('[name="plan"]')[0].hide();
  },
  _showLargePhoto: function(evt)
  {
    $(document).fire('slideShow:start', {intStartImgNum: evt.findElement('a[_num]').getAttribute('_num'), arrImagesElements: this.arrImages});
    evt.stop();
  }
});
arrJsLoaded['content.siteBuilding.js']=true;init.jsLoaded("content.siteBuilding.js");}, true);
