$(function(){

	var isIE6 = $.browser.msie && $.browser.version.match(/^6/)==6;

	$('.cat').removeClass('open');
	
	$('.cat .toggle').show();
	
	$('.cat .sections .sub a.main img').hide();
	$('.cat .sections .sub .links').hide();
	$('.cat .sections').hide();
	
	$('.cat .sections .sub .links a img').attr('src', 'images/icons/pdf_bw.png');
	
	$('.cat .sections .sub .links a').mouseover(function(){ $(this).children('img').attr('src', 'images/icons/pdf.png'); });
	$('.cat .sections .sub .links a').mouseout(function(){ $(this).children('img').attr('src', 'images/icons/pdf_bw.png'); });
	
	$('.cat').mouseover(function(){ $(this).children('h3').addClass('hover'); });
	$('.cat').mouseout(function(){ $(this).children('h3').removeClass('hover'); });
	
	$('.cat').click(function(){ openCat($(this)); });
					
	function openCat(cat){
		if($(cat).attr('class').match(/open/)){
			return;
		}
		$(cat).addClass('open');
		$(cat).find('.toggle img').attr('src', 'images/close.jpg');
		$(cat).children('.toggle').show();
		$(cat).find('.sections .sub .links').hide();
		$(cat).find('.sections .sub:first-child .links').show();
		$(cat).find('.sections .sub:first-child a.main').attr('rel', 'open');
		$(cat).find('.sections .sub a.main').removeClass('selected');
		$(cat).find('.sections .sub:first-child a.main').addClass('selected');
		if(!isIE6){
			$(cat).find('.sections .sub:first-child a.main img').show();
		}
		$(cat).children('.sections').slideDown();
	}
					
	$('.cat .toggle').click(function(){
									$(this).blur();
									if(!$(this).parent().attr('class').match(/open/)){
										openCat($(this).parent());
										return false;
									}
									$(this).children('img').attr('src', 'images/expand.jpg');
									var subLinks = $(this).parent().find('.sections .sub a.main');
									subLinks.each(function(){
															$(this).attr('rel', '');
															$(this).children('img').hide();
													});
									$(this).parent().children('.sections').slideUp("slow", function(){
																								$(this).parent().removeClass('open');
																							});
									return false;
								});
								
	$('.cat .sub a.main').click(function(){
										$(this).blur();
										if($(this).attr('rel')=="open"){
											return false;
										}
										$(this).parent().parent().find('.sub a.main').attr('rel', '');
										$(this).parent().parent().find('.sub a.main').removeClass('selected');
										$(this).attr('rel', 'open');
										$(this).addClass('selected');
										$(this).parent().parent().children('.sub').children('.links').slideUp();
										$(this).parent().parent().children('.sub').children('a.main').children('img').hide();
										$(this).parent().children('.links').slideDown();
										if(!isIE6){
											$(this).children('img').show();
										}
										return false;
									});

});