jQuery.noConflict();

(function($) {
		$.fn.extend({
			sameHeight : function(adder) {
				if (adder == null) var adder = 0;
				sameHeightDivs = $(this);
				var maxHeight = 0;
				sameHeightDivs.each(function() {
				    maxHeight = Math.max(maxHeight, jQuery(this).outerHeight());
				});
				sameHeightDivs.css({ height: maxHeight + adder + 'px' });
				return;
			},
			maxHeight :  function(_opts) {
				divs = $(this);
				var maxHeight = 0;
				divs.each(function() {
				    maxHeight = Math.max(maxHeight, jQuery(this).outerHeight());
				});
				return maxHeight;
			}
		});
})(jQuery);


jQuery(document).ready(function(){
	
	// adjust the margin-top of the content to the height of the navigation level 2
	var contentMarginTop = jQuery("#content").css("marginTop").replace('px', '');
	var navl2height = jQuery('#navbar ul.level2').maxHeight();
	if (navl2height > contentMarginTop)
	{
		jQuery("#content").css({"marginTop": navl2height+"px"});
	}
	
	
	var litop = jQuery(".navSF li.litoplevel");
	var litopactive = jQuery(".navSF li.litoplevel.active");
	var activesub = jQuery(".navSF li.litoplevel.active .level2");
	
	(function() {
		var navCode = jQuery(".navSF").html();
		
		addHoverFX();
		
		function addHoverFX()
		{
			litop.bind("mouseenter", function(){
				topHover(this);
			});
			litop.bind("mouseleave", function(){
				topRestore(this);
			});
		}
		
		function topHover(elem)
		{
			//litop.stop();
			if (!jQuery(elem).hasClass("active"))
			{
				//litopactive.find("ul").hide();
				litopactive.removeClass("active");
				
				litop.removeClass("sfhover");
				jQuery(elem).addClass("sfhover").find(".level2").hide().fadeIn(300);
			}
			else
			{
				litop.removeClass("sfhover");
				jQuery(elem).addClass("sfhover");
			}
			
		}
		function topRestore(elem)
		{
			litop.removeClass("sfhover");
			litopactive.addClass("active");
			if (!jQuery(elem) == litopactive)
			{
				litopactive.find(".level2").hide().fadeIn(300);
			}
		}
		
	})();
});


