

// Tweak #TopMenu
jQuery(document).ready(function($){
	$('#TopMenu li:first').addClass('firstitem');
});

// Top Search Box: Focus/Blur Events
jQuery(document).ready(function($){
	if ($('#top_search_term').size() < 1) { return; }
	var news_DefaultText = 'search keywords...';
	var address_input = $('#top_search_term');
	if ($(address_input).val() == '') { $(address_input).val(news_DefaultText); }
	$(address_input).focus(function() {
		if ($(address_input).val() == news_DefaultText) { $(address_input).val(''); }
		$(address_input).addClass('focus');
	});
	$(address_input).blur(function() {
		if ($(address_input).val() == '') { $(address_input).val(news_DefaultText); }
		$(address_input).removeClass('focus');
	});
});

// Centre Locator (scrolling bar)
jQuery(document).ready(function($){
	if ($('ul#ListAllCenters').size() < 1) { return; }	
	// Figure out the width of our containing UL
	totalWidth = 0;
	$('ul#ListAllCenters li').each(function(i) {
		liWidth = $(this).outerWidth(true);
		totalWidth = totalWidth + liWidth;
	});
	$('ul#ListAllCenters').width(totalWidth);
	// Prev & Next Listeners
	$('a#ListAllCenters_Next').click(function(e) {
		e.preventDefault();
		$('ul#ListAllCenters li:first-child').appendTo('ul#ListAllCenters');
	});
	$('a#ListAllCenters_Prev').click(function(e) {
		e.preventDefault();
		$('ul#ListAllCenters li:last-child').prependTo('ul#ListAllCenters');
	});
});

// Product Browser
jQuery(document).ready(function($) {
	if ($('#abc_shop_menu').size() < 1) { return; }
	$('#abc_shop_menu ul.products').hide();
	// Open on click event
	$('#abc_shop_menu>li.cat').click(function(e) {
		if ($(e.target).is('a')) { return; } // don't close menu on link click event
		$(this).children('ul.products').slideToggle();
		$(this).toggleClass('active');
	});
	// Start open if it contains a Current page
	$('#abc_shop_menu li.cat ul.products:has(li.current_page)').each(function(e) {
		$(this).slideDown();
		$(this).parent('li.cat').toggleClass('active');
	});
	// Open if it IS a Current Page
	$('#abc_shop_menu li.cat.current_page:has(ul.products)').each(function(e) {
		$(this).find('ul.products').slideDown();
		$(this).toggleClass('active');
	});
});
