    $(document).ready(function() {
        function megaHoverOver() {
            $(this).find(".sub").stop().fadeTo('fast', 1).show();

            //Calculate width of all ul's
            (function($) {
                jQuery.fn.calcSubWidth = function() {
                    rowWidth = 0;
                    //Calculate row
                    $(this).find("ul").each(function() {
                        rowWidth += $(this).width();
                    });
                };
            })(jQuery);

            if ($(this).find(".row").length > 0) { //If row exists...
                var biggestRow = 0;
                //Calculate each row
                $(this).find(".row").each(function() {
                    $(this).calcSubWidth();
                    //Find biggest row
                    if (rowWidth > biggestRow) {
                        biggestRow = rowWidth;
                    }
                });
                //Set width
                $(this).find(".sub").css({'width' :biggestRow});
                $(this).find(".row:last").css({'margin':'0'});

            } else { //If row does not exist...
                $(this).calcSubWidth();
                //Set Width
                $(this).find(".sub").css({'width' : rowWidth});
            }
        }
        function megaHoverOut() {
            $(this).find(".sub").stop().fadeTo('fast', 0, function() {
                $(this).hide();
            });
        }
        var config = {
            sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)
            interval: 10, // number = milliseconds for onMouseOver polling interval
            over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
            timeout: 255, // number = milliseconds delay before onMouseOut
            out: megaHoverOut // function = onMouseOut callback (REQUIRED)
        };
        $("#mainmenu ul li .sub").css({'opacity':'0'});
        $("#mainmenu ul li").hoverIntent(config);
   


			jQuery.validator.setDefaults({
            debug:false,
            focusCleanup:false,
            focusInvalid: false,
            onclick: false,
            onkeyup: false,
            onfocusout: false,
            showErrors: function(errorMap, errorList) {
                if(this.numberOfInvalids() > 0){
                    var message = '';
                    for (var i in errorList){
                        message += errorList[i].message+'<br />';
                    }
                    jAlert(message,"Medicina Informa");
                }
            }
            ,
            submitHandler: function(form) {
                 form.submit();
            }
        });
			$("#newsletter").validate({
				rules:{
					nome:{
                        required:true,
                    },
                    email:{
						required:true,
                        email:true,
                    }
                },
                messages:{
					nome:{
						required:"Informe o seu nome"
					},
                    email:{
						required:"Informe o seu email",
                        email:'informe um e-mail válido',
                    }
                }
			});
	(function($) {
    $.fn.lavaLamp = function(o) {
        o = $.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

        return this.each(function(index) {
            
            var me = $(this), noop = function(){},
                $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
                $li = $(">li", this), curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];

            $li.not(".back").hover(function() {
                move(this);
            }, noop);

            $(this).hover(noop, function() {
                move(curr);
            });

            $li.click(function(e) {
                setCurr(this);
                return o.click.apply(this, [e, this]);
            });

            setCurr(curr);

            function setCurr(el) {
                $back.css({ "left": el.offsetLeft+"px", "width": el.offsetWidth+"px" });
                curr = el;
            };
            
            function move(el) {
                $back.each(function() {
                    $.dequeue(this, "fx"); }
                ).animate({
                    width: el.offsetWidth,
                    left: el.offsetLeft
                }, o.speed, o.fx);
            };

            if (index == 0){
                $(window).resize(function(){
                    $back.css({
                        width: curr.offsetWidth,
                        left: curr.offsetLeft
                    });
                });
            }
            
        });
    };
})(jQuery);
       
            $("#mainmenu ul").lavaLamp({
                fx: "linear",
                speed: 700,
            });
 
		});

