$().ready(function() {

	function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		//return "steve";
		return row[0].replace(/(<.+?>)/gi, '');
	}
	
	$("#imageSearch").autocomplete("autocomplete.php", {
		width: 320,
		max: 10,
		scroll: true,
		cacheLength:1,
		matchSubset: 0,
		minChars: 1, 
		scrollHeight: 300,
		formatItem: function(data, i, n, value) {
		//	alert(value.split("%")[1]);
			//if(i==1){
				//return "<h2>"+value+"</h2>";
		//	}else{
			return "<span><img src='img/img.php?img=" + value.split("%")[0] + "&size=search'/> </span>" + value.split("%")[1] + "";
			//}
		},
		formatResult: function(data, value) {
			if(value.split("%")[1]!=""){
			return value.split("%")[1] ;
			}
		}
	}).result(function(event, item, formatted) {
		if(formatted.split("%")[2]!=""){
  	window.location.href=(formatted.split("%")[2]);
		}
});	
				   })

$(document).ready(function(){
    $("#nav li").hover(
        function(){ $("ul", this).fadeIn("fast"); }, 
        function() { } 
    );
    if (document.all) {
        $("#nav li").hoverClass ("sfhover");
    }
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
}; 
