function formatItem(row,pos,count) {
	var url = row[1];
    var title = row[2];
    title = title.replace('ÃƒÂ¤','&auml;');
    var description = row[3];
    var image = row[4];
    var rval = "";
    if(!image || image == "null") {
		image = "default";
    }
    rval += "<image style='float:left;' src='http://find.rsk-solutions.com/swk2/seimg/"+image+".jpg' width='32' height='32' alt='' />";
    rval += "<strong>" + title + "</strong>";
    rval += "<span>" + description + "</span>";
    rval += "<div style='clear:both'></div>";
	return rval;
}

function onItemSelect(li) {
	document.location.href = li.extra[0];
}
function addRule(stylesheet, selector, rule) {
	if(stylesheet.addRule) {
		stylesheet.addRule(selector, rule, stylesheet.rules.length);	
		return true;
	} else if(stylesheet.insertRule) {
		stylesheet.insertRule(selector + "{"+rule+"}", stylesheet.cssRules.length);	
		return true;
	} else {
		return false;	
	}
}
$(document).ready(function() {
	var stylesapplied = true;
	var pC = ".ac_results ";
	for(var i=0; i<document.styleSheets.length; i++) {
		var s = document.styleSheets.item(i);
		if( (s.rules && s.rules.length==0) || (s.cssRules && s.cssRules.length==0)) {
			stylesapplied &= addRule(s, pC +"li", 
				"border-bottom:1px solid #444;padding:4px;background:#f5f5f5;margin:0;clear:both;");
			stylesapplied &= addRule(s, pC + "li.ac_over", 
				"background-color: #666;");
			stylesapplied &= addRule(s, pC + "li img", 
				"margin: 5px;");
			stylesapplied &= addRule(s, pC + "li strong", 
				"font-size:11px;background-color:#E30012;display:block;color:white;");
			stylesapplied &= addRule(s, pC + "li span", 
				"font-size: 10px;");
			stylesapplied &= addRule(s, pC + "li.ac_over span", 
				"color:white;font-weight:bold;");

			stylesapplied &= addRule(s, pC + "iframe", "display:none;display/**/:block;/*sorry for IE5*/position:absolute;top:0;left:0;z-index:-1;filter:mask();width:3000px;height:3000px;");
		}
	}
	if(stylesapplied) {
		$("#searchText").autocomplete("http://www.swk.de/swkprodukte/proxy_2.jsp", {
    		cacheLength: 0,
        	matchCase: false,
        	matchContains: false,
        	selectFirst: false,
        	minChars: 2,
        	formatItem: formatItem,
        	onItemSelect: onItemSelect,
        	width: 350
		});
	}
});