/**
 Mootools More:
 Fx.Accordion
 */
 
Shadowbox.init();

window.addEvent('domready', function() {
  /**
  var divRightTop = $('headerfoto').getElement('div.righttop');
  if(divRightTop) {
    var myShow = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'];
    divRightTop.setStyle('background-image','url(/_images/aav/rt/' + myShow.getRandom() + '.jpg)')
  }
  */

  if ($$('.divMoreInfo a').length > 0) {
    $$('.divMoreInfo a')[0].addEvent('click', function() {
        _gaq.push(['_trackEvent', 'Offerte', 'Button', document.location.pathname]);
        //if (window.console) console.log('Offerte - Button');
    })
  }

  if ($('offertelink')) {
    $('offertelink').addEvent('click', function() {
        _gaq.push(['_trackEvent', 'Offerte', 'Tekst', document.location.pathname]);
        //if (window.console) console.log('Offerte - Tekst');       
    })
  }

  var suggestionContainer = $(document.body).getElement('.suggestionContainer');
  
  var myTotalValueCalculator = new mooTotalValueCalculator($(document.body).getElement('.totalValueCalculator'),$(document.body).getElement('.totalValueContainer'),{totalString:'Totaal',unitSign:' m<sup>3</sup>',unitBeforeTotal:false});
  
  var myHTMLRequest = new Request.HTML({
    url:'/_scripts/BoxSelector.ashx',
    update:suggestionContainer,
    onRequest:function() {
      suggestionContainer.set('html','Bezig met ophalen meest geschikte Boxtype en prijs...');
    }
  });
  
  var makeRequest = function() {this.send('total=' + $('mooTotalValue').get('html') + '&rnd='+ $random(1,1000)); };
  $$('.amount').addEvent('keyup',function() {
    myTotalValueCalculator.CalcTotal(this);
    // Send XmlHttpRequest
    makeRequest.delay(600,myHTMLRequest); // Added delay, so when a user type very fast, the latest value is submitted, not the first
  });
  
  
  if($('mp_divMoreInfo')) {
    $('mp_divMoreInfo').addEvent('click',function() {
      _gaq.push(['_trackEvent', 'Offerte aanvraag', 'click', 'Banner rechterkolom']);
    });
  }
  if($$('blockquote a')) {
    $$('blockquote a').addEvent('click',function() {
      _gaq.push(['_trackEvent', 'Offerte aanvraag', 'click', 'Link in grijze balk']);
    });
  }
  
  if($('reacties')) {
    var myAccordion = new Fx.Accordion($$('#reacties li h2'), $$('#reacties li div'), {
      display:-1
    });
    $$('blockquote').inject($('moving'),'before');
    
    var cats = $$('.lbCategory');
    for(i = 1; i < cats.length; i++) {
      if(cats[i].get('html') == cats[i-1].get('html')) {
        cats[i].setStyle('display','none');
      }
    }
    
  }
  
});

