// javascript by posttoast, 2009 (http://www.posttoast.nl)

function initFormdescription(){
  $$('.formdescription').each(function(el){
    var originalValue = el.value;

    el.addEvent('focus', function(){
      if (this.value == originalValue){
        this.value = '';
      }
    });

    el.addEvent('blur', function(){
      if (this.value == ''){
        this.value = originalValue;
      }
    });
  });
}

function initNewsletterSubscription(){

  if ($('newslettersubscribe-form')){
    $('newslettersubscribe-form').set('send', {onComplete: function(response) {
      if (response == 'OK'){
        $('newslettersubscribe-form').set('html', 'Bedankt voor je aanmelding!');
      }
    }});

    $('newslettersubscribe-form').addEvent('submit', function(el) {
      $('newslettersubscribe-form').send('index.php?ajax=1');
      el.stop();
    });
  }
  
}

function initActs(){
  if ($(document.body).hasClass('page-acts')){

    function openAct(actListItem, id){
      $$('.acts-list a').removeClass('active');
      actListItem.addClass('active');
      $$('.act').addClass('inactive-act');
      $(id).toggleClass('inactive-act');
    }

    // Hide all acts
    $$('.act').addClass('inactive-act');

    // Open act onclick
    $$('.acts-list a').addEvent('click', function(el) {
      arrayHref = this.getProperty('href').split('#');
      if (arrayHref[1] && $(arrayHref[1])){
        openAct(this, arrayHref[1]);
      }
      el.stop();
    });

    // Check if anchor is set and show corresponding act
    if (window.location.hash.substring(1) != ''){
      actId = window.location.hash.substring(1);
      actListItem = $('actlist-'+actId).getFirst('a');
      if (actListItem){
        openAct(actListItem, actId);
      }
    }
  }
}

function initFestivalreports(){
  if ($(document.body).hasClass('page-festivalreports')){

    function openFestivalreport(id){
      $(id).toggleClass('inactive-report');
    }

    // Hide all acts
    $$('.report').addClass('inactive-report');

    // Open act onclick
    $$('.report a.readfull').addEvent('click', function(el) {
      arrayHref = this.getProperty('href').split('#');
      if (arrayHref[1] && $(arrayHref[1])){
        openFestivalreport(arrayHref[1]);
      }
      this.destroy();
      el.stop();
    });

    // Check if anchor is set and show corresponding act
    if (window.location.hash.substring(1) != ''){
      actId = window.location.hash.substring(1);
      actListItem = $('actlist-'+actId).getFirst('a');
      if (actListItem){
        openFestivalreport(festivalreportId);
      }
    }
  }
}

function killBill(){
  if (Browser.Engine.trident && Browser.Engine.version <= 4){
    var warningMessage  = new Element('div', {id: 'browserupdate'});
    warningMessage.set('html', '<div id="browserupdate">U gebruikt een sterk verouderde versie van Microsoft Internet Explorer. Hierdoor loopt u mogelijk veiligheidsrisico\'s en worden webpagina\'s niet correct getoond.<br /><a href="http://www.microsoft.com/netherlands/windows/internet-explorer" target="_blank">Klik hier om de nieuwste versie te downloaden</a>.</div>');
    warningMessage.inject($(document.body), 'top');
  }
}

Shadowbox.init({
  language: "nl",
  players: ["img", "iframe"]
});



window.addEvent('domready', function(){
  initFormdescription();
  initNewsletterSubscription();
  initActs();
  initFestivalreports();
  killBill();
});