// 
// Start up Cover Flow
// 
var myCoverFlow = null;

// Event.observe(window, 'load', function() {
//   activateCoverFlow('hyatt.html');
// });

function activateCoverFlow(url) {
  
  new Ajax.Request(url, {
    method: 'get',
    onComplete: function(transport) {
      
      var temp = new Element('div', {id: 'cover-flow-container-temp'});
      
      temp.innerHTML = transport.responseText;
      
      document.body.appendChild(temp);
      
      myCoverFlow = new CoverFlow();
      
      myCoverFlow.activate();
      
      $('cover-flow-close').observe('click', function() { 
        setTimeout("$('cover-flow-container-temp').remove(); myCoverFlow = null;", 500);
      }, true);
    }
  });
  
}

// 
// Extend Accordion for Tab Structure
//
var TabAccordion = Class.create(Accordion, {
  
  counter: 0,
  active: false,
  maxHeight: 0,
  minHeight: 0,
  _finished: true,
  
  initialize: function($super, container, options) {
    $super(container, options);

    this.pairs.each(function(pair){
      
      pair.content.setStyle({
        display: 'none'
      });      
          
      pair.toggle.makePositioned();
      pair.content.makePositioned();

      if (this.counter == this.options.defaultContent) {
        this.onOpen(null, null, pair, false);
        this.active = pair;
      }
      
      this.counter = this.counter + 1;
      
      this.maxHeight = this.maxHeight > pair.content.getHeight() ? this.maxHeight : pair.content.getHeight();
      
    }.bind(this));
		
		this.minHeight = this.container.getHeight();
		
		this.setHeight();
  },

  setHeight: function() {
    $(this.container).setStyle({
      height: this.maxHeight + this.minHeight + 'px'
    });
  },
  
  onOpen: function(event, index, pair, scroll) {

    if (!this._finished || this.active == pair) {
      return false;
    }

    var effects = [];
    
    if (this.active && this.active.toggle && this.active.content) {
      this.active.toggle.removeClassName('tab_on').addClassName('tab_off');  
    
      effects.push(
        new Effect.Fade(this.active.content, {
          sync: true,
          from: 1.0,
          to: 0.0
        })
      );
    }
    
    pair.toggle.removeClassName('tab_off').addClassName('tab_on');
    
    effects.push(
      new Effect.Appear(pair.content, {
        sync: true,
        from: 0.0,
        to: 1.0
      })
    );

    new Effect.Parallel(effects, {
      duration: this.duration,
      beforeStart: function() {
        this._finished = false;
      }.bind(this),
      afterFinish: function() {
        this._finished = true;
      }.bind(this),
      queue: {
        position: 'end',
        scope: 'tab_accordion'
      }
    });    
    
    this.active = pair;
  }
  
});