/* Show and hide */
function loginbox_show() {
	jQuery("#loginbox").fadeIn();
	jQuery("#user_login").focus();
}
function loginbox_hide() {
	jQuery("#loginbox").fadeOut();
}
function loginbox_toggle() {
	if (jQuery("#loginbox").css("display") == "none") {
		loginbox_show();
	}
	else {
		loginbox_hide();
	}
}

/* The close button */
/* This button is added with javascript because without javascript we not need him ;) */
jQuery(function() {
	jQuery("#loginbox").prepend("<p id='loginbox_close'><input type='button' value='close' class='loginbox_button'/></p>");
	jQuery("#loginbox_close input").click(function() {
		loginbox_hide();
	});
});

/* On key press... */
/* Made with a bit of Visual jQuery (http://visualjquery.com) */
jQuery(document).keydown(function(e) {
	var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
	key = "["+key+"]";
	lbkey = "[101][69]";
	lbauxkey = e.altKey || e.ctrlKey;
	lbkey.indexOf(key) != -1 ? keye = true : keye = false;
	if (keye && lbauxkey) {
		loginbox_toggle();
		return false;
	};
});

/* On link[rel=loginbox-toggle] clicked... */
jQuery(function() {
	jQuery("[rel*='loginbox-toggle']").click(function(){
		loginbox_toggle();
		return false;
	});
}); 
jQuery(function() {
	/* works if  Login-box is showed */
	lbboxwidth = 310;
	lbboxheight = 290;
	/* Centralizes the position of the box
	with the respectives width and height (in pixels) */	
	/* Made with a bit of jQuery plugin Dimensions */
	windowwidth = self.innerWidth ||
		jQuery.boxModel && document.documentElement.clientWidth ||
		document.body.clientWidth;
	windowheight = self.innerHeight ||
		jQuery.boxModel && document.documentElement.clientHeight ||
		document.body.clientHeight;
	lbposx = (windowwidth - lbboxwidth) / 2;
	lbposy = (windowheight - lbboxheight) / 2;
	jQuery("#loginbox").css({ left: lbposx + "px", top: lbposy + "px" });
	jQuery("#loginbox").prepend("<a href='http://wordpress.org' title='Powered by WordPress' id='loginbox_wordpresslink'><span>WordPress</span></a>");
	jQuery("#loginbox").hover(function(){
		jQuery("#loginbox_close").fadeIn();
	},function(){
		jQuery("#loginbox_close").fadeOut();
	});
	jQuery("#loginbox_close input").val("");
});