$(document).ready(function() {
	$('#navigation ul:has(a#current)').prev().addClass('open');
	
	$('#navigation h3:not(.open)').next().hide();
	
	$('#navigation li:has(h3>a#current)').css('background','url(img/arrow_current.jpg) 10px center no-repeat');
	$('#navigation li:has(>a#current)').css('background','url(img/arrow_current.jpg) 25px center no-repeat');
	$('li#h_nav ul li:has(>a#current)').css('background','url(img/arrow_current-y.jpg) 25px center no-repeat');

	$('li#h_nav').css({'font-color' : '#FFFF96', 'background-color' : '#F8A01B'});
	$('li#h_nav h3').prepend('<img src="img/h_nav.jpg" alt="" />').children('img').css("vertical-align", "middle");

	$('#navigation h3>a').parents('li').each(function() {
		var $bgImage = $(this).css('background-image');
		$(this).hover(function() {
			$(this).css('background', '#084DB1 url(img/arrow_hover.jpg) 10px center no-repeat');
		}, function() {
			if ($bgImage == 'none') {
				$(this).css('background', '#0073BC');
			} else {
				$(this).css('background', '#0073BC url(img/arrow_current.jpg) 10px center no-repeat');
			}
		});
	});

	$('#navigation li:has(ul)').not(':has(h3.open)').hover(function() {
		if ($(this).attr('id') == 'h_nav') {
			$(this).css('background', '#F8781B url(img/arrow_open-y.jpg) 10px 17px no-repeat');
			$(this).find('h3 img').attr("src","img/h_nav_hover.jpg");
		} else {
			$(this).css('background', '#084DB1 url(img/arrow_open.jpg) 10px 10px no-repeat');
		}
	}, function() {
		if ($(this).attr('id') == 'h_nav') {
			$(this).css('background', '#F8A01B');
			$(this).find('h3 img').attr("src","img/h_nav.jpg");
		} else {
			$(this).css('background', '#0073BC');
		}
	});

	$('#navigation li:has(h3.open)').hover(function() {
		if ($(this).attr('id') == 'h_nav') {
			$(this).css('background', '#F8781B url(img/arrow_open-y.jpg) 10px 17px no-repeat');
			$('#navigation ul>li:has(a#current)').css('background', '#F8781B url(img/arrow_hover-y.jpg) 25px center no-repeat');
			$(this).find('h3 img').attr("src","img/h_nav_hover.jpg");
		} else {
			$(this).css('background', '#084DB1 url(img/arrow_open.jpg) 10px 10px no-repeat');
			$('#navigation ul>li:has(a#current)').css('background', '#084DB1 url(img/arrow_hover.jpg) 25px center no-repeat');
		}
	}, function() {
		if ($(this).attr('id') == 'h_nav') {
			$(this).css('background', '#F8A01B');
			$('#navigation ul>li:has(a#current)').css('background', '#F8A01B url(img/arrow_current-y.jpg) 25px center no-repeat');
			$(this).find('h3 img').attr("src","img/h_nav.jpg");
		} else {
			$(this).css('background', '#0073BC');
			$('#navigation ul>li:has(a#current)').css('background', '#0073BC url(img/arrow_current.jpg) 25px center no-repeat');
		}
	});

	$('#navigation ul>li').each(function() {
		$(this).hover(function() {
			if ($(this).parents('li:eq(0)').attr('id') == 'h_nav') {
				$(this).css('background', 'url(img/arrow_hover-y.jpg) 25px center no-repeat');
			} else {			
				$(this).css('background', 'url(img/arrow_hover.jpg) 25px center no-repeat');
			}
		}, function() {
			$(this).css('background', 'none');
		});
	});

/*
	$('#navigation h3').css('cursor','pointer').click(function() {
		$('#navigation h3.open').removeClass('open').next().hide();
		$(this).addClass('open').next().show();
	});
*/
	$('#navigation h3').css('cursor','pointer').click(function() {
		if (!$(this).hasClass('open')) {
			$('#navigation h3.open').removeClass('open').next().hide('slow');		
		}
		$(this).toggleClass('open').next().toggle();
		//$('#navigation li:has(ul>li>a#current)').css('background', '#0073BC url(img/arrow_current.jpg) 10px center no-repeat');
		//$('li#h_nav :has(ul>li>a#current)').css('background', '#F8A01B url(img/arrow_current-y.jpg) 10px center no-repeat');
	});

	$('a[@rel="external"]').click(function() {
		window.open($(this).attr('href'));
		return false;
	});

});

