$(function() {
	$('#catalog li.current-page ul, #catalog li.current-page-ancestor').addClass('expanded');
	$('#catalog a').click(function(e) {
		$ul = $('ul', $(this).parent());
		if($ul.length)
		{
			$('ul.expanded').slideUp('fast', function() { $(this).removeClass('expanded'); });
			$ul.filter(':not(.expanded)').slideDown('fast').addClass('expanded');
			e.stopPropagation();
			return false;
		}
		else return true;
	});
	$('#center_display a').hover(function() {
		$a = $(this);
		$('#pic_words .black_box').html($a.attr('title'));
		$('.category_pic img').each(function() {
			$t = $(this);
			if ($t.parent().attr('id') != $a.attr('id'))
			{
				$t.stop().fadeTo('fast', 0.5);
			}
		});
	}, function() {
		$('#pic_words .black_box').html('');
		$('.category_pic img').each(function() {
			$t = $(this);
			$t.stop().fadeTo('fast', 1);
		});
	});
	$('#home_columns a').hover(function() {
		$(this).siblings().stop().fadeTo('fast', .5);
	}, function() {
		$(this).siblings().stop().fadeTo('fast', 1);
	});
	$('tr.list-item').hover(function() {
		$(this).addClass('list-item-hover');
	}, function() {
		$(this).removeClass('list-item-hover');
	});
});

function intergift_init_search()
{
	var search_timer = null;
	var q = '';
	var prev_q = '';
	var $s = $('#s').focus(function() {
		$t = $(this);
		if ($t.hasClass('default'))
		{
			$t.val('').removeClass('default');
		}
		$('#search ul').fadeIn('fast');
	}).blur(function() {
		if ($t.val().trim() == '')
		{
			$t.val('Start typing to search...').addClass('default');
		}
		setTimeout(function() {
			$('#search ul').fadeOut('fast');
		}, 500);
	}).keyup(function() {
		var q = this.value;
		if (q != prev_q)
		{
			clearTimeout(search_timer);
			search_timer = setTimeout(function() {
				$('#search ul').fadeOut('fast', function() { $(this).remove(); });
				$.get('./search/', {q:q, plugin:'store-product'}, function(data) {
					$(data).hide().appendTo($('#search')).fadeIn('fast');
				});
			}, 250);
			prev_q = q;
		}
	});
	//console.log('$s.val() is "Search..."');
}
