Page = Class.create();
Page.prototype = {
  initialize: function() {
    // bla bla
  },
  fadeContent: function(el, effect, options) {
    effect(el.down('.c-box'), options);
  },
  toggle_content: function(link) {
    if($(link).innerHTML == 'Hide') {
      $(link).update('Show');
    } else {
      $(link).update('Hide');
    }
    $$('div.content').invoke('toggle');
  },
  addPageEvents: function() {
    $('your-link').onclick = function() {
      p.setTabs(this);
      new Effect.Morph('ours', {
        style: 'height: 27px',
        beforeStart: p.fadeContent.bind(p.ours, p.ours, Effect.Fade, {duration: 0.4}),
        afterFinish: function() {
          p.fadeContent(p.yours, Effect.Appear, {to: 0.95});
          Effect.Appear($('your-link').next());
        }
      });
      return false;
    }
    $('our-link').onclick = function() {
      var endHeight = document.documentElement.clientHeight-30 < 740 ? document.documentElement.clientHeight-30 : 740;
      p.setTabs(this);
      new Effect.Morph('ours', {
        style: 'height: '+endHeight+'px',
        beforeStart: p.fadeContent.bind(p.yours, p.yours, Effect.Fade, {duration: 0.4}),
        afterFinish: function() {
          p.fadeContent(p.ours, Effect.Appear, {to: 0.95})
          if($('home')) Effect.Appear('green', { duration: 7});
          Effect.Appear($('our-link').next());
        }
      });
      return false;
    }
    $$('.toggle').each(function(el) {
      el.onclick = function() {
        cbox = el.up('.c-box');
        if(cbox.hasClassName('full')) cbox.full = true;
        if(cbox.hasClassName('collapsed')) {
          return_style = cbox.full ? "full" : "expanded"
          el.next().style.visibility = "visible";
          new Effect.Morph(cbox, {
            style: return_style, 
            duration: 0.6,
            afterFinish: function() {
              cbox.removeClassName('collapsed');
            }
          });
        } else {
          cbox.removeClassName('expanded');
          el.next().style.visibility = "hidden";
          new Effect.Morph(cbox, {
            style: 'collapsed', 
            duration: 0.6, 
            scaleContent: true,
            afterFinish: function() {
              cbox.removeClassName('full');
            }
          });
        }
        return false; 
      }.bind(el);
    });
  },
  adjustContentHeight: function() {
    this.clientHeight = document.documentElement.clientHeight;
    if(this.ours.clientHeight > this.clientHeight) {
      this.ours.setStyle("height: "+(this.clientHeight-30)+"px");
      cbox = this.ours.down('.c-box');
      if((cbox.clientHeight+cbox.offsetTop) > (this.ours.clientHeight-40)) {
        cbox.addClassName('full');
      }
    }
  },
  toggleLocations: function() {
    new Effect.toggle('locations', 'Appear', {duration: 0.4});
  }
  
}
p = new Page();

FastInit.addOnLoad(function() {
  //p.ours = $('ours');
  //p.yours = $('yours');
  //p.addPageEvents();
  //p.adjustContentHeight();
});
