/**
 * autor: Ciro Feitosa - http://cirofeitosa.com
 * ago/2009
 */

/**
 * barra global - bsgworld
 */

function bsgRemoveFundo()
{
	$("#bsg_overlay").fadeOut("fast",function(){$('#bsg_overlay').trigger("unload").unbind().remove();});
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	return false;
}

function bsgDetectMacXFF()
{
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1)
	{
		return true;
	}
}

document.onkeyup = function(e){ 	
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	if(keycode == 27){ // close
		if ($('#bsgworld-log:visible')[0])
			$('#bsgworld-login').click();
	}	
};

$(document).ready(function()
{
	$('#bsgworld-login').click(function()
	{
		$('#bsgworld_login_id').focus();

		if (!$('#bsgworld-log:visible')[0])
		{
			$('#bsgworld-login').addClass('atual');
			if(!$('#bsg_overlay')[0])
			{
				$("body").prepend("<div id='bsg_overlay'></div>");
				$("#bsg_overlay").click(function()
				{
					$('#bsgworld-login').click();
				});
			}
			
			if(bsgDetectMacXFF()) {	$("#bsg_overlay").addClass("bsg_overlayMacFFBGHack"); } else { $("#bsg_overlay").addClass("bsg_overlayBG"); }
		}
		else
		{
			$('#bsgworld-login').removeClass('atual');
			bsgRemoveFundo();
		}

		$('#bsgworld-log').slideToggle('fast', function()
		{
			$('#bsgworld_login_id').focus();
		});
		return false;
	});

	$('#bsgworld-conta').click(function() {
		$('#bsgworld-conta span').toggleClass("conta_seta_up");
		$('#tools_user').toggle();
		return false;
	});
	
	 $('#bsgworld_login_id, #bsgworld_senha_id').keydown(function(e){
        if (e.keyCode == 13) {
            $(this).parents('form').submit();
            return false;
        }
    });

});