var searchFocus = false;
var searchOver = false;
function hideSearchOptions() {
	$('#searchExtras').removeClass('searchExtrasBg');
	$('#searchOptions').hide();
}
function doSearch() {
	if( $('#searchInput').val() != '' ) {
		// what type of search is it?
		if( $('#search_products').attr( 'checked' ) ) {
			// products
			document.location = '/products/%20search::' + $('#searchInput').val();
			return false;
		} else {
			// site search
			$('#searchForm').attr( 'action' , '/site_search' );
			$('#searchInput').attr( 'name', 'cmsContentSearch[text]' );
			return true;
		}
	} else {
		// no search term
		alert( 'Please enter a search term' );
		return false;
	}
}
$(document).ready(function(){
	$('.lhsNavTitle').click(function(){
		// if the next div is hidden, show it, otherwise, hide it
		if($(this).next('div').css('display') == 'none' ) {
			// show it
			$(this).next('div').css('display','block');
			// hide the "+"
			$(this).children('span').css('display','none');
		} else {
			// hide it
			$(this).next('div').css('display','none');
			// show the "+"
			$(this).children('span').css('display','inline');
		}
	});
	
	// add the fancy tool tips for all .infoIcon class elements
	$('.infoIcon').each(function() {
		// Create image content using websnapr thumbnail service
		var content = '<div class="productInfoBg">';
		content += '<div class="image"><img src="' + $(this).attr('image') + '" alt="" /></div>';
		content += '<div class="description"><div class="title">';
		content += $(this).attr('title');
		content += '</div><div class="details">';
		content += $(this).attr('content');
		content += '</div></div>';
		// Setup the tooltip with the content
		$(this).qtip({
			content: content,
			position: {
				corner: {
					tooltip: 'rightMiddle',
					target: 'leftMiddle'
				},
				adjust : {
					x: -10,
					y: 0,
					screen: true
				}
			},
			style: {
				width: 368,
				height: 193,
				padding: 0,
				background: 'transparent',
				textAlign: 'left',
				border: {
					width: 0,
					radius: 0
				}
			}
		});
	});
	$('.searchInput').mouseenter(function() {
		searchOver = true;
		$('#searchExtras').addClass('searchExtrasBg');
		$('#searchOptions').show();
	});
	$('#searchExtras').mouseleave(function() {
		searchOver = false;
		// only if focus isnt on the search
		if( !searchFocus ) {
			hideSearchOptions();
		}		
	});
	$('.searchInput').focus(function() {
		searchFocus = true;
	});
	$('.searchInput').blur(function() {
		searchFocus = false;
		if( !searchOver ) {
			hideSearchOptions();
		}
	});
});