function ovr(obj, t) {
  obj.title = t;	
  $(obj).remove();
  $("#screenshot").remove();
}


this.screenshotPreview = function(){	
		
		xOffset = -10;
		yOffset = 50;
	$("a.screenshot").hover(function(e){
		$("#screenshot").remove();
		this.t = this.title;
		this.title = "";
		var o = this;
		$(this).addClass("Ovr");
		var c = (this.t != "") ? "<br/>" + this.t : "";
		var url = encodeURI(this.href);
		var tmp = url.split('\/');
		var hu = '';
		var soubor = '';

		hu = tmp[tmp.length-1];
		if (hu == '') hu = tmp[tmp.length-2];
		$.ajax({
		   type: "GET",
		   url: "include/ajax_getimg.php",
		   data: "r="+(Math.random())+"&url="+hu,
		   success: function(msg){
		   	soubor = msg;
			$("#screenshot").remove();
			if (soubor) {
				if ($(o).hasClass("Ovr")) {
				$("body").append('<p id="screenshot"><img src="'+soubor+'" alt="Načítání ..." />'+ c +'</p>');								 
				$("#screenshot")
					.css("top",(e.pageY - xOffset) + "px")
					.css("left",(e.pageX + yOffset) + "px")
					.fadeIn("fast");
				}
				
			}
				//setTimeout('ovr(this, this.t)', 2000);
				//.mouseover(ovr(this, this.t));
		    }
		});
					
	},
	function(){
		this.title = this.t;
		$(this).removeClass("Ovr");
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

	function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	
	function formatItem(row) {
		return row[0];
	}
	function formatResult(row) {
		return row[1].replace(/(<.+?>)/gi, '');
	}


$(document).ready(function(){
	screenshotPreview();


	$("#search_select").autocomplete('include/ajax_autocompleter.php', {
		minChars: 3,
		max:20,
		width: 170,
		matchContains: true,
		autoFill: false,
				formatItem: formatItem,
		formatResult: formatResult
	});
});