
/**
 * Global functions for InGoedeHanden.nl
 */

// jQuery; Document load
$(document).ready(function()
{
	// innerfade
	$("ul#HeaderImages").innerfade({
		animationtype: 'fade',
		speed: 750,
		timeout: 5000,
		type: 'random_start'
	});

	// superfish menu
	$("#nav-one li").hover(
		function(){
			if ( $("ul li", this).size() > 0 )
			{
				var sWidth = $("ul li:eq(0)", this).css("width");
				$("ul", this).width(sWidth).show();
			}
		},
		function() { }
	);
	$("#nav-one li").hoverClass ("sfHover");

	// lightbox
	initLightbox();

	// open all links with a relation 'external' in a new window
	$("a[@rel='external']").click(function(){
		window.open( $(this).attr("href") );
		return false;
	});
});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover(
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

// Google zoekfuncties
function GoogleOnLoad()
{
	// create searchobjects
	searchControl	= new GSearchControl();
	siteSearch		= new GwebSearch();
	drawOptions		= new GdrawOptions();
	searchOptions	= new GsearcherOptions();

	// Configure site searcher
	siteSearch.setUserDefinedLabel("Zoekresultaten");
	siteSearch.setSiteRestriction("ingoedehanden.nl");

	// Configure Drawmode
	drawOptions.setInput("SearchInput");

	// Configure search options
	searchOptions.setExpandMode(searchControl.EXPAND_MODE_OPEN);
	searchOptions.setNoResultsString( "Geen resultaten" );

	// configure sitesearcher an tie it to searchcontrol
	searchControl.setLinkTarget( siteSearch.LINK_TARGET_SELF );
	searchControl.setSearchCompleteCallback( document, processResult );
	searchControl.addSearcher(siteSearch, searchOptions);

	// add event to submit button
	var submitBtn		= document.getElementById( "DoSearch" );
	submitBtn.onclick	= doSearch;
}

function doSearch()
{
	// get user data
	var inputField	= document.getElementById( "SearchInput" );
	var query		= inputField.value;

	// check if the query is not empty
	if( query != "" )
	{
		// Tell the searcher to draw itself and tell it where to attach
		searchControl.draw(document.getElementById("LeftBlock"), drawOptions);

		// perform the search
		searchControl.execute(query);
	}
}

function processResult()
{
	// remove some useless html
	$("div.gsc-ad-box").remove();
	$("div.gsc-results-selector").remove();
	$("div.gsc-expansionArea").remove();
	$("div.gs-visibleUrl").remove();

	// make title spiffy
	sIFR.replaceElement("div.gsc-title", named({sFlashSrc: "../media/swf/candara.swf", sColor: "#ED171F", sCase: "upper", sWmode: "transparent"}));

	// add branding
	var branding = google.search.Search.getBranding( $("td.gsc-configLabelCell").get() );
	$("td.gsc-configLabelCell").append( branding );
}

// load google search
google.load("search", "1");
google.setOnLoadCallback( GoogleOnLoad );
