// initialize the toggle.
// check on user's search pref.
// if set, respect it.  if not set, default it to site-wide google search

function initSearch() {
	var toggle_a = document.getElementById("toggle_a");
	var toggle_g = document.getElementById("toggle_g");

	toggle_a.onclick = function() { swapSearch(this.id); };
	toggle_g.onclick = function() { swapSearch(this.id); };
	
	var test = readCookie('searchpref');
	if (test == null) {
		createCookie('searchpref', 'google');
	} else if (test == 'archive') {
		swapSearch('toggle_a');
	} else {
		swapSearch('toggle_g');
	}
}


function swapSearch(t) {
	var toggle_a = document.getElementById("toggle_a");
	var toggle_g = document.getElementById("toggle_g");
	
	if (t == 'toggle_a') {
		toggle_a.setAttribute((document.all ? 'className' : 'class'),'toggledon');
		toggle_g.setAttribute((document.all ? 'className' : 'class'),'');
		document.getElementById("search").action = 'http://www.pbs.org/cgi-registry/wgbh/roadshow/archive_search.cgi';
		createCookie('searchpref', 'archive');
	}
	if (t == 'toggle_g') {
		toggle_a.setAttribute((document.all ? 'className' : 'class'),'');
		toggle_g.setAttribute((document.all ? 'className' : 'class'),'toggledon');
		document.getElementById("search").action = 'http://www.pbs.org/wgbh/roadshow/search_results.html';
		createCookie('searchpref', 'google');
	}
}