﻿$j(function () {
	userinfo.init();
});

var userTooltipTimer;

var config = {
	over: function () { userinfo.showtooltip(); clearTimeout(userTooltipTimer); },
	timeout: 5000,
	out: function () { userinfo.hidetooltip() }
};

var userinfo = {
	init: function () {

		$j("#chkremember").click(function () {
			$.ajax({
				type: "POST",
				data: JSON.stringify({ enable: $j("#chkremember").is(':checked') }),
				url: "/Tools/Webservices/KasiaAddress.asmx/RememberMe",
                contentType: "application/json",
                dataType: "json"
			});
		});

        if ($j('#usertooltip').length) {
            // due to IE7 z-index problems the userinfo is moved to mainarea instead
            $j('#usertooltip').appendTo('#mainarea').css('left', $j('#header .wrapper').position().left + 690); 
        }
		//userinfo.showtooltip(); //use this to show the tooltip programmatic

		$j('#username.shortened').livequery(function () {
			$j(this).hover(function () {
				$j(this).data('shortvalue', $j(this).html()).html($j(this).attr('title')).prev('.dots').hide(); //on hover: save the shortened text in data, show the long text from the title attribute and hide the dots
			}, function () {
				$j(this).html($j(this).data('shortvalue')).prev('.dots').show(); //on out: show the shortened text saved in data, show the dots
			});
		}, function () {
			$j(this).unbind('mouseover').unbind('mouseout');
		});
		$j('#username').live('click', function () { userinfo.showtooltip(); }) //on click: show the tooltip
	},
	showtooltip: function () {
		$j('#usertooltip').show().animate({ opacity: 1, top: '60px' }, 100);
		userTooltipTimer = setTimeout('userinfo.hidetooltip()', 5000);
		$j("#usertooltip").hoverIntent(config).mouseover(function () { clearTimeout(userTooltipTimer); });
	},
	hidetooltip: function () {
		$j('#usertooltip').hide().css('top', '40px');
	},
	startTooltipTimer: function () {
		userTooltipTimer = setTimeout("$j('#usertooltip').stop().hide().css('top', '40px')", 5000); //start the timer, hide tooltip after 5 sec
	}
}
