var Search = {
	control: null,
	el: null,
	completeCallback: function(){
		var c = El.getElementsByClassName("searchtarget","div")[0], q=" '"+$("q").value+"'", h;
		Search.el = El.createNode("div");
		Search.control.results.each(Search.showResult);
		if (Search.el.childNodes.length == 0)
			Search.el = El.createNode("p","Geen resultaten gevonden voor"+q);
		El.empty(c);
		c.appendChild(El.createNode("h1","Zoekresultaten voor"+q,"searchresult-header"));
		h = El.getElementsByClassName("searchresult-header", "h1");

		/* replace sifr */
		var museo = { src: '/flash/museo.swf' };
		sIFR.activate(museo);
		sIFR.replace(museo, {
		  selector: 'div#contents h1, div#container h2',
		  css: '.sIFR-root { color: #010154;}',
		  wmode: 'transparent'
		});
		jQuery('.searchtarget').removeClass('loading');

		c.appendChild(Search.el);
	},
	execute: function(){
		b = jQuery('body');
		if($('q').value == '' || $('q').value == 'Vul hier je zoekterm in ...') return false;
		if(b.hasClass('home')){
			b.removeClass('home').find('#center-column').remove().end().find('#contents').css('width','550px');
		}
		b.addClass('class', 'search').find('.searchtarget').html('').addClass('loading');
		setTimeout(function(){
			Search.control.execute($("q").value);
			}, 300);
		return false;
	},
	register: function(){
		var s = $("search");
		if (!s) return;
		s.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("h4",null,null,Search.el), a = El.createNode("a",r.titleNoFormatting,null,dt), dd = El.createNode("p",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);