$(document).ready(function() {
  $("#searchinput").autocomplete({
      serviceUrl: "index.php",
      onSelect: function(value, data) {
	  	location.href = data;
  	  },
      params : {
  		  ajax:'1',
  		  action:'autocomplete',
      	  limit: 30
       },
    onSelect: function(value, data) {
		location.href = data;
	  }
  });
  $('#searchinput').keyup(function(e) {
		if(e.keyCode == 13) {
			if($(".autocomplete div.selected").length==0) {
				$(".autocomplete div:first").click();	
			}
		}
  });
  $('input[name=searchbutton]').click(function() {
	  if($(".autocomplete div.selected").length==0) {
		  $(".autocomplete div:first").click();
	  }
	  else {
		  $(".autocomplete div.selected").click();
	  }
	  
  });
  
  $('a.readmore').click( function(event) {
	  event.preventDefault();
	  $('a.readmore').after('<hr />');
	  $('a.readmore').remove();
	  $('#producttable table').css('display','block');
//	  $('#producttable table').slideDown(1000);
  });
  
	/* Apply fancybox to multiple items */
	
	$("a.grouped_elements").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'speedIn'			: 600, 
		'speedOut'			: 400, 
		'overlayShow'		: true,
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.75,
		'easingIn'      	: 'easeOutBack',
		'easingOut'     	: 'easeInBack',
		'titlePosition' 	: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Foto ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});

});
