jQuery(document).ready(function($) {
	$('.jCarousel').jcarousel({
		scroll: 1
	});
	$('.expertiseItem').each(function() {
		var relArray = $(this).attr('rel').split(' :: ');
		var content = '<div class="tooltip">';
		if (relArray.length > 1) {
			content += '<h3>' + relArray[0] + '</h3><p>' + relArray[1] + '</p>';
		} else {
			content += '<p>' + relArray[0] + '</p>';
		}
		content += '</div>';
		$(this).append(content);
		$(this).hover(
			function() {
				$(this).children('.tooltip').fadeIn(200);
			},
			function() {
				$(this).children('.tooltip').fadeOut(200);
			}
		);
	});
	if (!$.browser.msie) {
		Cufon.refresh();
	}
	var lvl1 = $('#mainnav').children('.level_1').children('.first');
	var lvl2 = $('#mainnav').find('.level_2');
	var lvl3;
	var lvl2active = false;
	var lvl3active = false;
	lvl2.hide();
	$('#mainnav').find('.level_3').hide();
	lvl1.hover(
		function() {
			lvl2active = true;
			lvl2.fadeIn(200);
		},
		function() {
			lvl2.fadeOut(200);
			if (lvl3) {
				lvl3.fadeOut(200);
			}
		}
	);
	lvl2.hover(
		function() {
			lvl2active = true;
			$(this).fadeIn(200);
			$(this).children('li').hover(
				function() {
					if ($(this).find('.level_3').length) {
						lvl3 = $(this).find('.level_3');
						lvl3.fadeIn(200);
					}
				},
				function() {
					if (lvl3) {
						lvl3.fadeOut(200);
					}
				}
			);
			
		},
		function() {
			if (!lvl2active) {
				$(this).fadeOut(200);
			}
			lvl2active = false;
			if (lvl3) {
				lvl3.fadeOut(200);
			}
		}
	);
});
