/*
* mootools v.1.11 classes
* Core(Core)
* Class(Class)
* Native(Array, String, Function, Number, Element)
* Element(Element.Event)
* Window(Window.DomReady)
*/

window.addEvent('domready', function() {

  $$('a[rel=external]').set('target', '_blank');

  if ($('q')) {
    if ($('q').get('value') == '') {
      $('q').set('value', 'zoeken...');
    }

    $('q').addEvent('focus', function() {
      this.addClass('active');
      if (this.get('value') == 'zoeken...') {
        this.set('value', '');
      }
    });

    $('q').addEvent('blur', function() {
      this.removeClass('active');
      if (this.get('value') == '') {
        this.set('value', 'zoeken...');
      }
    });
  }

  displayTxt();
  displayTxt.periodical(5000);
  displayRef();
  displayRef.periodical(3000);

//-------------------------------------------------------------------------------------
// Get latest Tweets and (if available!) add those to page (where? under news?)
var myHTMLRequest = new Request.HTML({
    url : '/_components/recenttweets.ashx', 
    method : 'get', 
    append : $('tweets'),
    onSuccess : function() {
        var tweets = $('tweets').getElements('.tweet');
        tweets.setStyle('opacity', 0);
        tweets[0].setStyle('opacity', 1);
        nextSlide.periodical(6000, $('recentTweets'));
    }
});
myHTMLRequest.send();

var nextSlide = function() {
	fadeSlide.delay($random(500, 2000), this)
}

var fadeSlide = function() {
	this.getElement('.tweet').fade('out').inject(this);
	this.getElement('.tweet').fade('in');
}

//-------------------------------------------------------------------------------------
  var url = window.location.href;

  if (url.contains('/contact/') && $('formcontact')) {
    var missingField;
    $('formcontact').addEvent('submit', function(e) {
      var e = new Event(e);
      e.stop();
      missingField = false;

      $$('.reqFld').each(function(field) {
        field.removeClass('reqFldEmpty');
        if (field.get('value') == '') {
          field.addClass('reqFldEmpty');
          missingField = true;
        }
      });

      if (missingField == true) {
        alert('De gekleurde velden zijn verplicht');
      } else {
        //window.location = this.getProperty('action');  
        $("formcontact").submit();
      }
    });
  }

});

var txt = ['&ldquo;Sterke organisaties kennen de kwaliteiten van hun medewerkers&rdquo;','&ldquo;Het managen van de lastigste persoon op aarde: jezelf&rdquo;','&ldquo;Je kunt anderen niet motiveren als je er niet bent&rdquo;','&ldquo;Om feedback te krijgen moet je goed kunnen luisteren&rdquo;','&ldquo;Leiders zonder volgelingen bestaan niet&rdquo;','&ldquo;Waarom we vaak iets anders doen dan we eigenlijk willen&rdquo;','&ldquo;Succes is een keuze&rdquo;','&ldquo;Iets kost net zoveel tijd als je ervoor uittrekt&rdquo;','&ldquo;Zoek de mogelijkheden in de problemen en niet de problemen in de mogelijkheden&rdquo;','&ldquo;Twee monologen maken nog geen dialoog&rdquo;','&ldquo;Ik heb in mijn leven meer geleerd door te luisteren dan door te spreken&rdquo;','&ldquo;Wees niet bang om langzaam voorwaarts te gaan, wees alleen bang om stil te staan&rdquo;','&ldquo;Je hoeft geen ander mens te worden, om dingen eens anders aan te pakken&rdquo;'];

function displayTxt() {
  if ($('citaten')) {
	$('citaten').set('html', txt.getRandom());
  }
}

var ref = [
	'<img src="/_images/logo/1.gif" alt=""  />',
	'<img src="/_images/logo/7.gif" alt=""  />',
	'<img src="/_images/logo/23.gif" alt=""  />',
	'<img src="/_images/logo/24.gif" alt=""  />',
	'<img src="/_images/logo/8.gif" alt=""  />',
	'<img src="/_images/logo/19.gif" alt=""  />',
	'<img src="/_images/logo/9.gif" alt=""  />',
	'<img src="/_images/logo/22.gif" alt="" />',
	'<img src="/_images/logo/2.gif" alt="" />',
	'<img src="/_images/logo/3.gif" alt="" />',
	'<img src="/_images/logo/4.gif" alt="" />',
	'<img src="/_images/logo/5.gif" alt="" />',
	'<img src="/_images/logo/10.gif" alt="" />',
	'<img src="/_images/logo/11.gif" alt="" />',
	'<img src="/_images/logo/12.gif" alt="" />',
	'<img src="/_images/logo/13.gif" alt="" />',
	'<img src="/_images/logo/14.gif" alt="" />',
	'<img src="/_images/logo/15.gif" alt="" />',
	'<img src="/_images/logo/16.gif" alt="" />',
	'<img src="/_images/logo/17.gif" alt="" />',
	'<img src="/_images/logo/18.gif" alt="" />',
	'<img src="/_images/logo/20.gif" alt="" />',
	'<img src="/_images/logo/21.gif" alt="" />',
	'<img src="/_images/logo/26.gif" alt="" />',
	'<img src="/_images/logo/27.gif" alt="" />',
	'<img src="/_images/logo/28.gif" alt="" />',
	'<img src="/_images/logo/29.gif" alt="" />',
	'<img src="/_images/logo/30.gif" alt="" />',
	'<img src="/_images/logo/31.gif" alt="" />',
	'<img src="/_images/logo/25.gif" alt="" />',
	'<img src="/_images/logo/32.gif" alt="" />',
	'<img src="/_images/logo/33.gif" alt="" />',
	'<img src="/_images/logo/34.gif" alt="" />'
];

var refCurrent = 0;

function displayRef() {
  $('ref').set('html', ref[refCurrent]);

  if (refCurrent == ref.length - 1) {
	  refCurrent = 0;
  } else {
	  refCurrent++;
  }
}



