$(document).ready(function () {

  $('#product-filter input:checkbox').live('click', function(e) {

    $('input.ajax-vars').removeAttr('disabled');
    var form = $(this).parents('form');

    $.ajax({
      url: '/include/produktsuche-form.php',
      data: form.serialize(),
      beforeSend: function(jqXHR, settings) {
      },
      success: function(data, textStatus, jqXHR) {
        $('#product-search-form').html(data);
      }
    });

  });

  $("#main-navigation > ul > li, .lang-select").hover(function () {
    $("ul", this).show();
  }, function() {
    $("ul", this).hide();
  });

  if($('#select-all-cultivations').length)
  {
    $('#select-all-cultivations, #select-all-dehydrations, #select-all-product-groups').click(function(event) {
      event.preventDefault();
      $(this).parent().prev('ul').find('input:not(:disabled)').attr('checked', 'checked');
    });

    $('#deselect-all-cultivations, #deselect-all-dehydrations, #deselect-all-product-groups').click(function(event) {
      event.preventDefault();
      $(this).parent().prev('ul').find('input:not(:disabled)').removeAttr('checked');
    });

    $('#result-order').change(function() {
      this.form.submit();
    })
  }

  $('#quick-search, #query').keyup( function() {
    var query = $(this).val();
    $(this).autocomplete({
      source: function( request, response ) {
        $.ajax({
          type: 'POST',
          url: '/include/ajax/schnellsuche.ajax.php',
          data: {q: query, language: $('#q_language').val()},
//          data: 'q=' + query + '&language=' + $('#q_language').val(),
          success: function( data )
          {
            response($.map($.parseJSON(data), function(item) {
              return item;
            }));
          }
        });
      },
      minLength: 2,
      select: function( event, ui ) {
        //self.location.href = '/naturprodukte/'+$('#q_language').val()+'/produkt/'+ui.item.value;
        self.location.href = $('#q_pfad').val() + ui.item.value;
      }
    });
  });

  $('.product-choose').ready( function() {
    h_max = parseInt(0);
    $('.product-choose').find('ul').each( function() {
      h = parseInt($(this).height());
      if(h > h_max) {
        h_max = h;
      }
    });

    $('.product-choose').find('ul').css({'height': h_max + 'px'});
  });

$(function() {
  $('div.flowplayer_button[rel]').overlay({
    effect: 'apple',
    expose: '#789',
    onLoad: function(content) {
      // find the player contained inside this overlay and load it
      this.getOverlay().find("a.flowplayer_content").flowplayer(0).load();
    },
    onClose: function(content) {
      $f().unload();
    }
  });

  $("a.flowplayer_content").flowplayer("/include/flowplayer/flowplayer-3.2.7.swf");
}); // function()

}); // document.ready()

