$j(document).ready(function() {
	$j('.home_reward').hide();
	nextAward();
});

function showAward(award)
{
	$j.blockUI({
		message: award,
		overlayCSS: {
			backgroundColor: '#FFF',
			opacity: 0.8
		},
		css: {
			width: '426px',
			height: $j(award).height(),
			top:  ($j(window).height() -  $j(award).height() - 30) /2 + 'px',
            left: ($j(window).width() - 426) /2 + 'px'
		}
	});
	$j('.get_reward', award).click(function(){
		$j.unblockUI();
		var popup = $j(this).parents('.home_reward');
		//$j(this).hide();
		var checkbox = $j(this).siblings('p').children('input:checked');
		if(checkbox.length) {
			try {
				checkbox_id_bits = checkbox.attr('id').split('_');
				$j.post('/en/main/wall-post/automatic/', {
					_token: $j('#award_token').val(),
					message: checkbox.val(),
					awardId: checkbox_id_bits[3]
				}, function(response) {
					if(!response.message) {
						alert(response.error_message);
					}
				}, 'json');
			} catch(e) {alert(e);}
		}
		setTimeout(function(){
			popup.remove();
			nextAward();
			var awards = $j('.home_reward');
			// if (!awards.length && $j('#showNewMissionBubble').val()) {
				// popNewMissionBubble();
				// $j('#showNewMissionBubble').remove();
			// } else if (!awards.length && ($j('#showBubble').val() || $j('#pvpShowBubble').val())) {
				// popCompleteBubble();
				// $j('#showBubble').remove();
				// $j('#pvpShowBubble').remove();
			// }
		}, 600);
		
	});
}

function nextAward()
{
	var awards = $j('.home_reward');
	if (awards.length) {
		showAward(awards[0]);
	}
}

