var Search = {
	control: null,
	el: null,
	completeCallback: function(){
		var c = El.getElementsByClassName("searchtarget","div")[0], q=" '"+$("q").value+"'", h;
		Search.el = El.createNode("dl");
		Search.control.results.each(Search.showResult);
		if (Search.el.childNodes.length == 0){
			var content = "Geen resultaten gevonden voor"+q+". ";
			if (location.href.indexOf("powered-by-publer") !== -1 || location.href.indexOf("loves-publer") !== -1){
				content = "\Zodra de website live staat kunnen de zoekresultaten pas getoond worden.";
			}
			Search.el = El.createNode("p",content);
		}
		El.empty(c);
		c.appendChild(El.createNode("h1","Zoekresultaten voor"+q,"searchresult-header"));
		h = El.getElementsByClassName("searchresult-header", "h2");
		if (typeof sIFR !="undefined"){ // sIFR exists
			// sIFR.redraw(); somehow replace the h1 with new sifr, but styling is uknown
		}
		c.appendChild(Search.el);
		Cufon.replace("h1.searchresult-header");

	},
	execute: function(){
		Search.control.execute($("q").value);
		return false;
	},
	register: function(){
		$("search").onsubmit = Search.execute;
		Search.control = new google.search.WebSearch();
		Search.control.setSiteRestriction(searchPath);
		Search.control.setSearchCompleteCallback(Search, Search.completeCallback);
		Search.control.setResultSetSize(7);
		Search.control.setLinkTarget(GSearch.LINK_TARGET_SELF);
		Search.control.setNoHtmlGeneration();
	},
	showResult: function(r){
		var dt = El.createNode("dt",null,null,Search.el), a = El.createNode("a",r.titleNoFormatting,null,dt), dd = El.createNode("dd",null,null,Search.el);
		a.href = r.unescapedUrl;
		dd.innerHTML = r.content;
	}
}
var searchPath = searchPath?searchPath:document.domain;
google.load("search", "1");
Event.add(window, "load", Search.register);
