$(document).ready(function() {
	var Is_IE6 = false;
	if ( $.browser.msie && parseInt($.browser.version) == 6 ) {
		Is_IE6 = true;
	}
	
	$("#atriam-menu-one>li,#atriam-menu-two>li").hover(
		function () {
			$("#atriam-menu-one>li>ul,#atriam-menu-two>li>ul").stop(true,true).hide();
			
			var Target = $(this);
				Target.addClass('hover');
				Target.find('ul').each(function(i){
					var Target_UL = $(this);
						
					if( Is_IE6 ) {
						Target_UL.show();
						
						$('select').each(function(){
							if( Hit_Test( $(this), Target_UL ) ) {
								$(this).css('visibility', 'hidden');
								$(this).addClass('menu-hidden');
							}
						});	
					
						Target_UL.hide();
					}
					
					Target_UL.slideDown('fast');
				});
		},
		function () {
			$("#atriam-menu-one>li>ul,#atriam-menu-two>li>ul").stop(true,true).hide();
			
			$('select.menu-hidden').css('visibility', 'visible');
			$('select.menu-hidden').removeClass('menu-hidden');
			
			var Target = $(this);
				Target.removeClass('hover');
				Target.find('ul').hide();
		}
	);
	
	$("li:first-child").addClass('first-child');
	$("li:last-child").addClass('last-child');
	
	$("#atriam-global-search-q").focus(function(){
		if( this.value == this.defaultValue ) {
			this.value = '';
		}
	});
	$("#atriam-global-search-q").blur(function(){
		if( this.value == '' ) {
			this.value = this.defaultValue;
		}
	});
});

function Hit_Test( Element_1, Element_2 ) {
	var One = new Object();
		One.Left = Element_1.offset().left;
		One.Top = Element_1.offset().top;
		One.Right = One.Left + Element_1.outerWidth();
		One.Bottom = One.Top + Element_1.outerHeight();
	
	var Two = new Object();
		Two.Left = Element_2.offset().left;
		Two.Top = Element_2.offset().top;
		Two.Right = Two.Left + Element_2.outerWidth();
		Two.Bottom = Two.Top + Element_2.outerHeight();
	
	// horizontal match
	if( (One.Left >= Two.Left && One.Left <= Two.Right) || (One.Right <= Two.Right && One.Right >= Two.Left) ) {
		// vertical match
		if( (One.Top >= Two.Top && One.Top <= Two.Bottom) || (One.Bottom >= Two.Top && One.Bottom <= Two.Bottom) ) {
			return true;
		}
	}
	return false;
}
