
$(document).ready(function() {
	//Stupid IE
	//IE doesn't understand min-height, so we are going to manually set the height of the columns
	if ($.browser.msie) {
		var Main = $('#Main');
		var Left = $('#Left');
		if (Main.height() > Left.height()) {
			Left.height(Main.height());
		} else if (Left.height() < 1000) {
			Left.height(1000);
		}
		//alert(Main.height+" "+Left.height());
	}

	$('#nav div.MenuDiv').each(function() {
		//if (!$.browser.msie) {
			$(this).corner("cc:#381B9B 5px"); 
		//}
	});
	$('.ThirdLevelLink').each(function() {
		//console.log($(this));
		//if (!($(this).hasClass('ThirdTop')) && !($(this).hasClass('ThirdBottom'))) {
			$(this).bind('mouseover',function(){
				$(this).addClass('ThirdLevelLinkHover');
				$(this).removeClass('ThirdLevelLink');
			});
			$(this).bind('mouseout',function(){
				$(this).addClass('ThirdLevelLink');
				$(this).removeClass('ThirdLevelLinkHover');
			});
		//}
	});
	$('.SecondLevelLink').each(function() {
		$(this).bind('mouseover',function(){
			$(this).addClass('SecondLevelLinkHover');
			$(this).removeClass('SecondLevelLink');
		});
		$(this).bind('mouseout',function(){
			$(this).addClass('SecondLevelLink');
			$(this).removeClass('SecondLevelLinkHover');
		});
	}); 
	$('.SecondLevelLinkArrow').each(function() {
		$(this).bind('mouseover',function(){
			$(this).addClass('SecondLevelLinkArrowHover');
			$(this).removeClass('SecondLevelLinkArrow');
		});
		$(this).bind('mouseout',function(){
			$(this).addClass('SecondLevelLinkArrow');
			$(this).removeClass('SecondLevelLinkArrowHover');
		});
	});
	
	$('#nav li').each(function() {
		var Parent = $(this).parent();
		if (Parent.attr('id') == 'nav') { //This means that it's a top level li
			var DivItem = $(this).children('a').children('div.MenuDiv'); // Get the div that is within the link
			var ULItem = $(this).children('ul'); //Get the child UL item if it exists
			var Width = $(this).width();
			var Left = -18;
			$(this).hover(function(){
				DivItem.toggleClass('MenuHoverDiv2');
				if (DivItem.length && ULItem.length) {
					ULItem.css({'left':Left});
				}
			},function(){
				DivItem.toggleClass('MenuHoverDiv2');
				if (DivItem.length && ULItem.length) {
					ULItem.css({'left':'-991111px'});
				}
			});
		}
	});
	if (!$.browser.msie) {
		$('#nav ul.SecondLevel li ul li a').each(function() {
			$(this).hover(function(){
				$(this).parent().parent().parent().children('a').addClass('SecondLevelHoverArrow');
			},function(){
				$(this).parent().parent().parent().children('a').removeClass('SecondLevelHoverArrow');
			});
		});
	}

	$('#nav ul.SecondLevel li').each(function() {
		var ULItem = $(this).children('ul');
		if ($(this).children('a').length) { //This is not one of the top/bottom li's
			if (ULItem.length) {
				if ($(this).parent('ul').hasClass('SecondLevel')) {
					if ($.browser.msie) {
						$(this).hover(function(){
							ULItem.css({'left':'200px'});
						},function(){
							ULItem.css({'left':'-999999999px'});
						});
					}
				}
			} else {
				if ($(this).parent('ul').hasClass('SecondLevel')) {
					$(this).hover(function(){
					});
				}
			}
		}
	});
	
	$('#nav ul.SecondLevel ul').each(function() {
		$(this).prepend('<li class="ThirdTop" style="width: 180px;"><!-- --></li>');
		$(this).append('<li class="ThirdBottom"><!-- --></li>');
		if (!$.browser.msie) {
			//alert('Not IE');
			$(this).corner("cc:transparent 10px tr br"); 
		}
	});
	
	$('#nav ul.SecondLevel').each(function() {
		var MaxWidth = 200;
		$(this).css({'width':MaxWidth}); //Force the width to be correct
		if (!$.browser.msie) {
			$(this).corner("10px br bl"); //Round the bottom corners
		}
		$(this).prepend('<li class="Top" style="width: 200px; padding-left:10px"></li>'); //Add the top LI
		$(this).append('<li class="Bottom" style="width: '+MaxWidth+'"></li>'); //Add the bottom LI
		$(this).children('li').css({'text-indent':'10px'}); //Indent the text on all of the LI objects
		$(this).children('li').children('ul').css({'margin-left':'0'});
		if ($.browser.msie) {
			$(this).children('li').children('ul').css({'margin-top':'-34px'});
		} else {
			$(this).children('li').children('ul').css({'margin-top':'-34px'});
		}
		$(this).children('li').children('ul').children('li').css({'right':'0%'});
		$(this).children('li').children('ul').children('li').css({'text-align':'left'});
		$(this).children('li').children('ul').children('li').css({'text-indent':'0px'});
		if ($.browser.msie && ($.browser.version.substr(0,3)=="6.0" || $.browser.version.substr(0,3)=="7.0")) {
			$(this).css({'margin-top':-2});
			$(this).children().each(function() {
					$(this).css({'left':0});
			});
		} else if ($.browser.msie) {
			//$(this).css({'border':'1px solid red'});
			$(this).children().each(function() {
				if ($(this).hasClass('Top')) {
					$(this).css({'left':0});
					$(this).css({'top':-1});
				} else {
					$(this).css({'left':0});
				}
			});
		} else if ($.browser.safari) {
			$(this).children().each(function() {
				if ($(this).hasClass('Top')) {
					$(this).css({'left':0});
				} else {
					$(this).css({'left':0});
				}
			});
		} else {
			$(this).children().each(function() {
				if ($(this).hasClass('Top')) {
					$(this).css({'left':-6});
				} else {
					$(this).css({'left':0});
				}
			});
		}
	});
	
	
});
