$(document).ready(function(){
  
  $('#lp').change(function(){
    window.location = $(this).val();
  });
  $('#cp').change(function(){
    document.location_search.submit();
  });

  $('#mainmenu > ul > li').mouseover(function(){
    $(this).find('ul').show();
  });

  $('#mainmenu > ul > li').mouseout(function(){
    $(this).find('ul').hide();
  });

  $('p').removeAttr('style');
  $('h1').removeAttr('style');
  
  $('.font-m').click(function(){
    $('body').css('fontSize', '75%');
    $('.location_row').each(function(){
      $(this).find('td').eq(1).css('display', 'block');
      $(this).find('td').eq(0).width(140);
    });
    $.cookie('font-size', '75%');
  });

  $('.font-l').click(function(){
    $('body').css('fontSize', '100%');
    $('.location_row').each(function(){
      $(this).find('td').eq(1).css('display', 'none');
      $(this).find('td').eq(0).width(340);
    });
    $.cookie('font-size', '100%');
  });

  $('.font-xl').click(function(){
    $('body').css('fontSize', '150%');
    $('.location_row').each(function(){
      $(this).find('td').eq(1).css('display', 'none');
      $(this).find('td').eq(0).width(340);
    });
    $.cookie('font-size', '150%');
  });

  /*
   * Google route
   */
  $('#start_address').keyup(function(){
    var start_address = $(this).val() + ' ' + $('#start_city').val();
    $('#start').val(start_address);
  });
  $('#start_city').keyup(function(){
    var start_address = $('#start_address').val() + ' ' + $(this).val();
    $('#start').val(start_address);
  });
  $('#open_route').click(function(){
    var start_address = $('#start').val();
    var destination_address = $('#destination').val();
    var url = 'http://maps.google.com/maps?f=d&source=s_d&saddr=' + encodeURIComponent(start_address) + '&daddr=' + encodeURIComponent(destination_address) + '&hl=nl';
    window.open(url);
  });

  $('.lightbox').lightBox();

  $('.search_button').click(function(){
    document.search.submit();
  });
  $('.search_button_footer').click(function(){
    document.search_footer.submit();
  });

  if (!$.cookie('font-size'))
  {
    $.cookie('font-size', '75%');
  }
  if ($.cookie('font-size') != '75%')
  {
    $('.location_row').each(function(){
      $(this).find('td').eq(1).css('display', 'none');
      $(this).find('td').eq(0).width(340);
    });
  }
  $('body').css('fontSize', $.cookie('font-size'));


  /*
   * PNG Fix
   */
  $('#headerimage_overlay').pngFix();
  $('#column_left').pngFix();
  $('#column_right').pngFix();
  $('.location_overview').pngFix();

  /*
   * Wordwrap fix
   */
//  var sContent = $('#column_center').html();
//  var sContent = sContent.replace(/'s-Hertogenbosch/gi, "<span style='white-space: nowrap'>'s-Hertogenbosch</span>");
//  $('#column_center').html(sContent);

});

/*
 * Downloadtracker
 */
function trackDownload(name)
{
  $.ajax({
    url: 'trackdownload/' + name,
    success: function(data) {
      return true;
    }
  });
}
