/*! Scripts for nachtwinkelingent.be */

$(function() {

 // Alle variabelen declareren
 var $uitgebreid = $('#uitgebreid'),
     $uitgebreidLink = $('#uitgebreid_link a'),
     $reageren = $('#reageren'),
     $contactForm = $('#contactForm'),
     $r_naam = $('#review_naam', $reageren),
     $r_email = $('#review_email', $reageren),
     $naam = $('#bericht_naam', $contactForm),
	 $adres = $('#adres', '#met_vertrekpunt_form'),
     $email = $('#bericht_email', $contactForm),
     $url = $('#bericht_url', $contactForm);
     $score = $('#score').show(),
     $scoreLis = $('li', $score),
     $reviewScore = $('#review_score'),
     keys = [],
     konami = '38,38,40,40,37,39,37,39,66,65';

 // a img
 $('#content a:has(img)').addClass('linkedImage');

 // Uitgebreid zoeken
 $uitgebreidLink.click(function() {
  if (!$uitgebreid.height()) {
   $uitgebreid.animate({ height: 256 }, 500);
   $uitgebreidLink.text('Eenvoudig zoeken');
  } else {
   $uitgebreid.animate({ height: 0 }, 500);
   $uitgebreidLink.text('Uitgebreid zoeken');
  };
  return false;
 });

// Gegevens zoekveld in cookie bewaren
 if ($.cookie('adres')) {
  $adres.val($.cookie('adres'));
 }

 $('#submit', '#met_vertrekpunt_form').click(function() {
  // Cookie adres aanmaken
  $.cookie('adres', $adres.val(), { path: '/' });
 });


 // Konami-code
 $(document).keydown(function(e) {
  keys.push(e.keyCode);
  if (keys.toString().indexOf(konami) >= 0) {
   // konami-klasse geven
   $('#nav').addClass('konami');
   // array leegmaken
   keys = [];
  };
 });

 // Validatie reactieformulier
 $('form', $reageren).validate();

 // Gegevens reactie_formulier in cookie bewaren
 if ($.cookie('naam')) {
  $r_naam.val($.cookie('naam'));
 }
 if ($.cookie('email')) {
  $r_email.val($.cookie('email'));
 }

 $('#submit', $reageren).click(function() {
  // Cookie naam aanmaken
  $.cookie('naam', $r_naam.val(), { path: '/' });
  // Cookie e-mailadres aanmaken
  $.cookie('email', $r_email.val(), { path: '/' });
 });


 // Validatie contactformulier
 $('form', $contactForm).validate();

 // Gegevens contactformulier in cookie steken
 if ($.cookie('naam')) {
  $naam.val($.cookie('naam'));
 }
 if ($.cookie('email')) {
  $email.val($.cookie('email'));
 }
 if($.cookie('url')) {
  $url.val($.cookie('url'));
 }

 $('#submit', $contactForm).click(function() {
  // Cookie naam aanmaken
  $.cookie('naam', $naam.val(), { path: '/' });
  // Cookie e-mailadres aanmaken
  $.cookie('email', $email.val(), { path: '/' });
  // Cookie website aanmaken
  $.cookie('url', $url.val(), { path: '/' });
 });


 // Score geven
 $('#score_label').show();
 $('#review_score-element, #review_score-label').hide();
 $scoreLis.hover(function() {
  $(this).prevAll().andSelf().addClass('hover');
 }, function() {
  $(this).prevAll().andSelf().removeClass('hover');
 }).click(function() {
  var $this = $(this);
  $scoreLis.removeClass('selected');
  $this.prevAll().andSelf().addClass('selected');
  $reviewScore.val($this.index() + 1);
  return false;
 });

});
