$(function() {
		
	var last_visit = $.cookie('pcx_last_visited');
	
	$('#catalog0 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
		
		$('#catalog1 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
	$('#catalog2 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
	
	$('#catalog3 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
	
	$('#catalog4 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
		
	$('#catalog5 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
		
	$('#catalog6 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
		
	$('#catalog7 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
		
	$('#catalog8 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});
		
	$('#catalog9 li > a')
		.click(function() {
			
			// Unselect all others
			$('.selected')
				.removeClass('selected')
				
			// Slide Up all Shown items
			$(this)
				.parent()
				.siblings('li')
				.find('ul:visible')
				.slideUp();

			// Select this
			$(this)
				.parents('li')
				.children('a')
				.addClass('selected');
				
			// slide up all children
			$(this)
				.next('ul')
				.find('ul:visible')
				.slideUp();
				
			// If we're hiding, remove selected class
			if ($(this).next('ul').is(':visible')) {
				$(this).removeClass('selected');
			} 
				
			// Slide down the next item
			$(this)
				.next('ul')
				.slideToggle();
			
				
			if ($(this).attr('href') == '#') {
				return false;
			} else {
				$.cookie(
					'pcx_last_visited', 
					$(this).attr('pcx-id'),
					{
						domain: 'partsconnexion.com',
						path: '/'
					}
				);
				return true;
			}
		});	
	
	$('.product-information input.button')
		.click(function() 
		{	
			$checkbox = $(this).parent().next().next().children('input');
			
			if (!$checkbox.is(':checked')) {
				$checkbox.attr('checked', true);
			}
		});
	
	// Give each <a> a unique id
	$('#catalog0 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});
		
	$('#catalog1 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});	
	
	$('#catalog2 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});	
		
	$('#catalog3 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});
	
	$('#catalog4 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});
		
	$('#catalog5 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});
		
	$('#catalog6 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});
		
	$('#catalog7 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});
		
	$('#catalog8 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});
		
	$('#catalog9 li > a[href!="#"]')
		.each(function(i) 
		{
			$(this).attr('pcx-id', i);
		});	
		
	if (last_visit != null) {
		// Open up last visited item
		$('#catalog0 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
	}
	
	if (last_visit != null) {
		// Open up last visited item
		$('#catalog1 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
	}
	
	if (last_visit != null) {
		// Open up last visited item
		$('#catalog2 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
	}
	
	if (last_visit != null) {
		// Open up last visited item
		$('#catalog3 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
		$('#catalog4 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
		$('#catalog5 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
		$('#catalog6 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
		$('#catalog7 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
		$('#catalog8 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();
		$('#catalog9 li > a[pcx-id='+last_visit+']')
			.parents('ul')
			.show();	
	}
});