$(document).ready(function(){

	/*
	 * Tooltip script
	 * powered by jQuery (http://www.jquery.com)
	 * written by Alen Grakalic (http://cssglobe.com)
	 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
	 *
	 */
	/* CONFIG */
	xOffset = 10;
	yOffset = 20;
	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result
	/* END CONFIG */
	$(".ttip").mouseover(function(e){
		this.t = this.title;
		this.title = "";
		if (this.t) {
			$("body").append("<p id='tooltip'>"+ this.t +"</p>");
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
		}
	});

	$(".ttip").mouseout(function(e){
		this.title = this.t;
		$("#tooltip").remove();
	});

	$(".ttip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	/*
	 * Tooltip END
	 */

	/*
	 * Login
	 */

	var formMayVanish=true;

	$('#login-form').hide();

	$('#head-username').focus(function(){
		if ($(this).val() == 'Username') {
			$(this).val('');
			formMayVanish = false;
		}
	});
	$('#head-username').blur(function(){
		if (!$(this).val().length) {
			$(this).val('Username');
		}
		formMayVanish = true;
	});
	$('#head-password').css('display', 'none');
	$('#head-password-hint').focus(function(){
		$(this).css('display', 'none');
		$('#head-password').css('display', 'inline');
		$('#head-password').focus();
		formMayVanish = false;
	});
	$('#head-password').blur(function(){
		if (!$(this).val().length) {
			$('#head-password-hint').css('display', 'inline');
			$(this).css('display', 'none');
		}
		formMayVanish = true;
	});
	$('#head-login-submit').mouseover(function(){
		$(this).addClass('active');
	});
	$('#head-login-submit').mouseout(function(){
		$(this).removeClass('active');
	});
	$('#login-form-close').click(function(){
		$('#login-button').removeClass('active');
		$('#login-form').hide();
	});
	$('#login-button').mouseover(function(){
		if (!$(this).hasClass('active')) {
			$(this).addClass('active');
			$('#login-form').show();
		}
	});
	$('#head').mouseover(function(){
		if ($('#login-button').hasClass('active') && formMayVanish) {
			$('#login-button').removeClass('active');
			$('#login-form').hide();
		}
	});
});

function frmsubmit(frm) {
	$('#overlay').removeClass('hidden');
	$(frm).submit();
}

