function showSearch() {
	$('#nav-search').removeClass('hide');
	
	$('#nav-search').animate({
		width: 200
	}, 200, null);
	$('#searchbox').animate({
		width: 150
	}, 200, function() {
		$('#searchbox').focus();
	});
}
function hideSearch() {
	$('#nav-search').animate({
		width: 55
	}, 50, null);
	$('#searchbox').animate({
		width: 2
	}, 50, function() {
		$('#nav-search').addClass('hide');
	});
}
// called by onsubmit of search form
function siteSearch() {
	terms = document.forms[0].searchbox.value;
	if (terms == '') return false;
	terms = terms.replace('+', '%2B');
	terms = terms.replace('*', '%2A');
	terms = terms.replace('/', '%2F');
	terms = terms.replace('@', '%40');
	terms = terms.replace(' ', '+');
	window.location.href = 'http://www.google.com/search?q=site%3Acradlesolution.com%20' + terms;
	return true;
}

// bind events
window.onload = function() {
	hideSearch();
	$('#search-btn').click(function() {
		showSearch();
	});
	$('#searchbox').keypress(function(e) {
		if (e.which == 13) {
			siteSearch();
		}
	});
	initMenus();
	$('#herographic').nivoSlider({
		controlNav: false,
		directionNav: false,
		pauseTime: 6000
	});
}

// init dropdown menus
function initMenus() {
	$('ul.toplevel li a').mouseenter(function() {
		// show submenu
		$(this).parent().find("ul.level1").slideDown(150).show();
		
		// when it leaves the hover state, hide submenu
		$(this).parent().hover(null, function() {
			$(this).parent().find('ul.level1').slideUp(250);
		});
	});
}
