//Domready
var level1tm = null;
var level2tm = null;
var level3tm = null;

$(document).ready(function(){

	$('.home_box_body ul').each(function () { $(this).find("li:last").addClass('last') } );

	$('#edit-submit-1').val('');
	$('#contact-mail-page .form-submit').val('');
	$('#search-form #edit-submit').val('');

	$('#nav > ul > li > a').addClass('a_level1');
	$('#nav > ul > li > ul > li > a').addClass('a_level2').each(
		function () { 
			$(this).attr('href', $(this).closest('li').find("ul > li:first > a").attr('href'));
		});
	$('#nav > ul > li > ul > li > ul > li > a').addClass('a_level3');

	Cufon.replace('#nav a.a_level1', { hover: true }, { fontFamily: 'Swiss' }) ('.home_box_top h2', { hover: true }, { fontFamily: 'Swiss' }) ('.primary_top h2', { hover: true }, { fontFamily: 'Swiss' }) ('.certif_listing h4', { hover: true }, { fontFamily: 'Swiss' }) ('.timeline_wrapper', { hover: true }, { fontFamily: 'Swiss' });
	$("#management_listing a[rel]").overlay({expose: '#000'});
	
	$('dt > a.active').each(function () { 
	  if($('dd', $(this).closest('dl')[0]).size()) {
	    alert('test');
	    $(this).removeClass("plus").addClass("minus").closest('dt').siblings('dd').show(); 
	  }
	} );
	
	$('dd > a.active').closest('dd').siblings('dt').find("a").addClass('minus').removeClass("plus").closest('dl').addClass('dl_active').end().end().siblings('dd').show();
	
	$('ul.sidebar_nav > li:last').addClass('last');
	
	$('ul.sidebar_nav > li > dl > dt > a').click( function () {
		$('ul.sidebar_nav > li > dl > dd').slideUp('normal').closest('dl:has(dd)').removeClass('dl_active').find("dt > a").removeClass('minus').removeClass('plus').addClass('plus');
		if($('dd', $(this).closest('dl')[0]).size())
          $(this).removeClass('plus').removeClass('minus').addClass('minus');
		$(this).closest('dt').siblings('dd').slideDown('normal').closest('dl').addClass('dl_active');
	});
	
	// top menu animations 
	
	$('div#nav > ul').addClass('ul_level1').children("li").addClass('li_level1');
	$('div#nav > ul > li > ul').addClass('ul_level2').children('li').addClass('li_level2');
	$('div#nav > ul > li > ul > li > ul').addClass('ul_level3').children('li').addClass('li_level3');
	
	//$('div#nav ul.ul_level2').each(function () { $(this).width($(this).width() + 20 + 'px'); });

	$('div#nav a.a_level1').hover(function () {
		clearTimeout(level2tm);
		clearTimeout(level3tm);
		$('div#nav ul.ul_level2').hide(); 
		$('div#nav ul.ul_level3').hide(); 
		$(this).siblings('ul').show(); 
	});
	
	$('div#nav a.a_level2').hover(function (event) { 
		event.stopPropagation();
		$('div#nav ul.ul_level3').hide();
		
		$('div#nav ul.ul_level3').closest('li').removeClass('selected');
		
		$(this).siblings('ul').show();
	});	
	
	$('div#nav ul.ul_level1').hover(function () { }, function () {
		clearTimeout(level2tm);
		clearTimeout(level3tm);
		level2tm = setTimeout(function () { $('div#nav ul.ul_level2').hide(); }, 1000);
		level3tm = setTimeout(function () { $('div#nav ul.ul_level3').hide(); }, 1000);
	});
	$('div#nav ul.ul_level2').hover(function (event) { 
										event.stopPropagation(); 
										clearTimeout(level2tm); 
										$('li', this).removeClass('selected');  
									},
									function (event) { 
										event.stopPropagation(); 
										var t = this; 
										clearTimeout(level2tm); 
										level2tm = setTimeout(function () { $(t).hide(); }, 1000);
									});
	$('div#nav ul.ul_level3').hover(function (event) { 
			event.stopPropagation();
			clearTimeout(level3tm); 
			clearTimeout(level2tm);
			
			$(this).closest('li').addClass('selected');
		}, function (event) { 
			event.stopPropagation();
			var t = this; 
			clearTimeout(level3tm);
			clearTimeout(level2tm);
			level3tm = setTimeout(function () { $(t).hide(); }, 1000); 
			level2tm = setTimeout(function () { $('div#nav ul.ul_level2').hide(); }, 1000); 
		});		
	
	// end top menu animations
	
}); //Domready end