function sg_menu() {

	$('#mainnav > ul > li').each(function(i) {

		// Set min-width for submenu to size of parent nav item
		$(this).find('ul:eq(0)').css('min-width',$(this).width() + 'px');

		var sgtimer = null;
		$(this).hover(
			function() {
				// Clear the timeout
				clearTimeout(sgtimer);

				// Hide Siblings Immediately
				var siblings = $(this).siblings('li');
				siblings.find('a:eq(0)').removeClass('active');
				siblings.find('ul').stop().css('height','').hide();

				// Reveal Current
				$(this).find('a:eq(0)').addClass('active');
				$('ul',$(this)).slideDown(); //show();

			},
			function() {
				var obj = $('ul',$(this));
				var parent = $(this);
				// Hide after 1/2 second
				sgtimer = setTimeout(function() { parent.find('a:eq(0)').removeClass('active'); obj.hide(); }, 500);
			}
		);


	});

}

function checkLogin(){
    $("#loginMsg").html("&nbsp;");
        
    login       = $("#username").attr("value");
    password    = $("#password").attr("value");
    returnurl   = $("#returnurl").attr("value");

    
    if (!password || !login){
        $("#loginMsg").html("Both fields are required.");
    } else {
        
        $.ajax({
            type: "POST",
            url: "/index.php/checkauth",
            data: "login=" + login + "&" + "password=" + password,
            success: function(msg){
                if (msg == "no"){
                    $("#loginMsg").html("Wrong user name/password. Please Try again.<br /> Click <a href='/index.php?module=roles&amp;func=lostpassword'>here</a> if you forgot your password.");
                }
                if (msg == "yes"){
                    document.location = returnurl;
                }
            }
        });
    }


return false;

}

$(function() {
    sg_menu();
    
    $('.showLogin').click(function() {
        $('#logingFormWrapper').slideToggle('normal', function() {
            $(document).scrollTo('#endLoginArea');
        });
        return false;
    });
    
});
