var Sondaggi = new Class({

  initialize: function(poll){
    this.poll = document.id(poll);
    this.questions = this.poll.getElement('#questions');
    this.results = this.poll.getElement('#risultati');
    if (this.results) this.results.set('opacity', this.questions ? 0 : 1);
    if (this.questions){
      this.results.setStyles({
        'position': 'absolute',
        'top': 0,
        'left': 0,
        'display': 'inline'
      });
      var h = this.results.offsetHeight;
      h = Math.max(h, this.questions.offsetHeight);
      var height = (h - 2) / 12.13333;
      this.questions.setStyle('height', height + 'em');
      this.results.setStyle('height', height + 'em');
      var show = this.show.bindWithEvent(this);
      document.id('pollresfw').addEvent('click', show);
      document.id('pollresrw').addEvent('click', show);
    } else {
      if (this.results) this.results.setStyle('display', 'inline');
    }
  },

  show: function(){
    this.questions.fade();
    this.results.fade();
  }

});

window.addEvent('domready', function(){
  var todayEl = document.id('dataodierna');
  if (todayEl) todayEl.set('text', new Date().format('%d.%m.%Y'));

  var poll = document.id('sondaggio');
  if (poll) new Sondaggi(poll);

  $$('.hp_video').each(function(el){
    new Home2Video(el);
  });

  var popupEl = document.id(document.body).getElement('.autoPopup .home2Popup');
  if (popupEl) new Home2Popup(popupEl).show();

  var nc = document.id('notizie_content');
  var pc = document.id('progetti_content');
  if (nc && pc){
    var ncb = nc.getCoordinates().bottom;
    var pcb = pc.getCoordinates().bottom;
    if (ncb != pcb){
      var div = new Element('div').setStyles({ 'clear': 'left', 'height': Math.abs(ncb - pcb) + 'px' })
      if (ncb < pcb) nc.adopt(div);
      else pc.adopt(div);
    }
  }
});

