/*--- Typing Alert Bar ---*/
var keyCookieTyping = 'typing_alert_bar';
var defaultTyping = 1 ; /*Telex*/
var tAUTO 	= 0;
var tTELEX 	= 1;
var tVI 	= 2;
var tOFF 	= 3;

function cookieTyping(v)
{
	$.getJSON
	(
		HOST_CANDIDATE + '/cookie-typing/?callback=?',
		{
			'v'	: v
		},
		function(data)
		{
			displayTypingAlertBar(data.result);
		}
	);
}

function setTypingAlertBar(v)
{
	cookieTyping(v);
}

function displayTypingAlertBar(vMethod)
{
	var idInput = 'idAuto';
	if (vMethod==tTELEX){ idInput='idTelex';}
	else if(vMethod==tVI){ idInput='idVni';}
	else if(vMethod==tOFF){ idInput='idOff';}
	$('#'+idInput).attr('checked','checked');

	var e = $('#idOnOffTyping');
	e.removeClass('typesOffItem');
	e.addClass('typesOnItem');
	if (vMethod==tOFF)
	{
		setMethodAvim(-1);
		e.removeClass('typesOnItem');
		e.addClass('typesOffItem');
	}
	else
	{
		setMethodAvim(vMethod);
	}
}
/*--- Typing Alert Bar ---*/

$(document).ready(function()
{
	cookieTyping(-1);
	$('div.typingBox li').click(function()
	{
		setTypingAlertBar(this.value);
	});
});

/*--- Notify Alert Bar ---*/
notification = function() {
	$.getJSON (
		HOST+'/notify/alert?callback=?',
		function(response) {
			var msg = response['msg'];
			var total = response['total'];
			if (msg) {
				$('#showNotification').html(msg);
				var animStyle = 'slide';
				$('#showNotification').notificationmsg({animation:animStyle});
				$('#showNotification').show();
				if (total) {
					$('#idNotification strong').html(total);
				}
				createCookie('notify', 1);
			} else {
				eraseCookie('notify');
			}
		}
	);
}
typings = function(isclick) {
	var animStyle = 'slide';
	$('#showTypings').notificationmsg({animation:animStyle});
	$('#showTypings').show();
}
notificationHide = function () {
	$('#showNotification').notificationmsg('hide');
	eraseCookie('notify');
}
typingsHide = function () {
	$('#showTypings').notificationmsg('hide');
}
$(document).ready(function(){
	$("#idNotification").click(function() {
		notification();
		typingsHide();
	});
	if (readCookie('notify') == 1) {
		notification();
	}
	$("#idTyping").click(function() {
		typings(1);
		notificationHide();
	});
});
