jQuery(document).ready(function(){
	$('#topzoek').autocomplete(http_base+'/autocompletesearch/', {
		width: 400,
		scrollHeight: 200,
		cellSeparator: '|',
		formatItem: formatItem,
		formatResult: formatResult,
		matchSubset: false,
		mustMatch: false,
		max: 30										
	});
});
// Wanneer de pagina van grootte veranderd
$(window).resize(function(){
	placeIcon();
});

// Wanneer er wordt gescrolled
$(window).scroll(function(){
	placeIcon();
});

$(function() {
	$("#menu ul li").bind("mouseenter", 
		function() {
			$("#ul_"+this.id).animate({height:"show",opacity:"show"},"slow"); 
			return false;
		}).bind("mouseleave", 
		function() {
			$("#ul_"+this.id).animate({height:"hide",opacity:"hide"},"slow"); 
			return false;
		});;
});

$(function() {
	$("#item_66").bind("mouseenter", 
		function() {
			$("#website_items_search").animate({height:"show",opacity:"show"},"slow");
			$("#topzoek").focus(); 
			return false;
		});
	$("#topzoek").bind("blur", 
		function() {
			setTimeout('$("#website_items_search").animate({height:"hide",opacity:"hide"},"slow")',10000); 
			return false;
		});
});


function placeIcon(){
	var offset = $("#footer").offset();
	var new_left = offset.left-110;
	var max_top = offset.top-150;
	var min_top = $("#content").offset().top;
	var new_top = $(window).height()+$(window).scrollTop()-193; // Op de rand van je browser
	if(new_top > max_top){
		new_top = max_top;
	}
	if(new_top < min_top){
		new_top = min_top;
	}
	$("#d-media-icon").css("position","absolute");
	$("#d-media-icon").css("left",new_left);
	$("#d-media-icon").css("top",new_top);
}


function formatItem(row){ 
	if (row[1]){return '<strong>' +row[0]+ '</strong><br />' + row[1]; }else{return '<strong>' +row[0]+ '</strong>' };
}
function formatResult(row){	return row[0].replace(/(<.+?>)/gi, '');	}
