$(document).ready(function(){
	base();
	$(".b-link-item1, .b-link-item2, .b-link-item3, .b-link-item4, .b-link-item5, .b-link-item6").hover(function(){
		$(this).css({
			"background-image" : "url(img/bg-button.png)", 
			"background-repeat" : "no-repeat"
		});
	},
	function(){$(this).css({"background-image" : "none"});})
	$("table.tb-top-menu td").hover(
		function(){$(this).addClass("over");},
		function(){$(this).removeClass("over");}
	);
	$(document).click (function(e) {
		var offset = $("#private-enter").offset();
		var x = offset.left;
		var y = offset.top;
		var h = $(".b-auth").height();
		var $clicked=$(e.target);
		if ($clicked.is('.b-auth-link')) showenter();
		else if (!($clicked.is('#enter > h4, input, #enterm')||$clicked.is('#enter'))||$clicked.is('#undefined')) {$("#enter").animate({"top":+(0-(y+h+40))+"px"});}
    });
	$("#glosoptlst").change(function(){
		$selId = $("#glosoptlst option:selected").attr("id").split("pos");
		$selNum = Number($selId[1]);
		$("#glosopttxt"+$selNum).slideDown().siblings("div:visible").slideUp();		
	});
});
$(window).resize(function(){
	base();	
});

function showenter() {
	var offset = $(".b-auth-link").offset();
	var x = offset.left;
	var y = offset.top;
	var h = $("#enter").height();
	var $id = $(this).attr("id");
	if ($id!="loggedin"){
		$("#enter").css({"left":+x-30+"px", "top":+(0-(y+h))+"px", "display":"block"}).animate({"top":+y-20+"px"});$("#enter > input:text").focus();
	}	
}

var $headId = "head";
var $bodyId = "body";
var $baseId = "base";

function getWindowHeight(){
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') windowHeight = window.innerHeight;
	else {
		if (document.documentElement && document.documentElement.clientHeight) windowHeight = document.documentElement.clientHeight;
		else if (document.body && document.body.clientHeight) windowHeight = document.body.clientHeight;
	}
	return windowHeight;
}

function base(){
	$winHeight = getWindowHeight();
	if ($("#"+$headId)) $headHeight = $("#"+$headId).height();
	else $headHeight = 0;
	$bodyHeight = $("#"+$bodyId).height();
	$baseHeight = $("#"+$baseId).height();
	$difHeight = $winHeight - ($headHeight + $bodyHeight + $baseHeight);	
	if ($difHeight > 0) $("#"+$baseId).css({"position":"absolute", "bottom":"0px", "width":"100%"});
	else $("#"+$baseId).css({"position":"static"});
}