var LikeIt = {
	Login : function(object) {
		attrValue = jQuery.parseJSON(object.getAttribute("data-details"));
		jQuery.overbox.show('#overDivLogin');
		var leader_id  = attrValue.leader_id;
		var leader_type = attrValue.leader_type;
		var activity_type = attrValue.activity_type;
		var object_id = 0;
		var object_type = 0;
		if (typeof (attrValue.object_id) != "undefined") object_id = attrValue.object_id;
		if (typeof (attrValue.object_type) != "undefined") object_id = attrValue.object_id;
		var div_id = object.id;
		tmp  = 'like_it_after_login("{&quot;div_id&quot;: &quot;'+div_id+'&quot;';
		tmp += ' , &quot;leader_type&quot;: &quot;'+leader_type+'&quot;';
		tmp += ' , &quot;leader_id&quot;: &quot;'+leader_id+'&quot;';
		tmp += ' , &quot;activity_type&quot; : ' + activity_type;
		if (typeof (attrValue.object_type) != "undefined") tmp += ' , &quot;object_type&quot;: '+object_type;
		if (typeof (attrValue.object_id) != "undefined") tmp += ' , &quot;object_id&quot;: '+object_id;
		tmp += ' }"); ';
		$('#eval_after_overlay_login').val(tmp);
	},

	Universal : function(object) {
		attrValue = jQuery.parseJSON(object.getAttribute("data-details"));
		$.ajax({
			type: "POST",
			url: '/_json_/like_it/',
			dataType: "json",
			data: {
				'action' : 'like_it_universal',
				'leader_id' : attrValue.leader_id,
				'leader_type' : attrValue.leader_type,
				'activity_type' : attrValue.activity_type,
				'object_id' : attrValue.object_id,
				'object_type' : attrValue.object_type,
				'likeit_count' : attrValue.likeit_count
			},
			beforeSend: function(){
				//showGlobalLoader();
			},
			success: function(doc){
				if(doc.status == 1) {
					$('#'+object.id+' .counter').html(doc.likeit_count);
					$('#'+object.id+' .likeit_word').css({
						'display':doc.likeit_word
					});
					$('#'+object.id+' .dontlikeit_word').css({
						'display':doc.dontlikeit_word
					});
				}
				//hideGlobalLoader();
			}
		});
	}
}


function like_it_after_login (json){
	attrValue = jQuery.parseJSON(json.replace(/&quot;/g, "\""));
	var leader_type = attrValue.leader_type;
	var leader_id = attrValue.leader_id;
	var activity_type = attrValue.activity_type;
	var div_id = attrValue.div_id;
	if (typeof (attrValue.object_id) != "undefined") object_id = attrValue.object_id;
	if (typeof (attrValue.object_type) != "undefined") object_type = attrValue.object_type;
	var object_type = attrValue.object_type;
	

	$.ajax({
		type: "POST",
		url: '/_json_/like_it/',
		dataType: "json",
		data: {
			'action' : 'like_it_after_login',
			'leader_type' : leader_type,
			'leader_id' : '',
			'activity_type' : activity_type,
			'likeit_counter' : likeit_counter,
			'object_type' : (typeof (attrValue.object_type) != "undefined") ? object_type : null,
			'object_id' : (typeof (attrValue.object_id) != "undefined") ? object_id : null
		},

		beforeSend: function(){
			showGlobalLoader();
		},

		success: function(doc){
			if(doc.status == 1) {
				$('#'+div_id+' .likeit_word').css({
					'display':doc.likeit_word
				});
				$('#'+div_id+' .dontlikeit_word').css({
					'display':doc.dontlikeit_word
				});
			}
			hideGlobalLoader();
		}
	}); 
}

var GroupIt = {
	Login : function(object) {
		alert('zaloguj sie');
	},
	
	Universal : function(object) {
		attrValue = jQuery.parseJSON(object.getAttribute("data-details"));
		switch(attrValue.action)
		{
			//CANCEL_AUTH
			case 'ADD2GROUP':
				$.get("/_json_/group_it/", {
					"action":"ADD2GROUP",
					"group_id":attrValue.group_id
				}, function(returned_data) {
					$(object).html(returned_data.link);
					$(object).attr('data-details', '{"action":"REMOVE_FROM_GROUP", "group_id":'+attrValue.group_id+'}');
				}, "json");
				break;

			case 'REMOVE_FROM_GROUP':
				jConfirm('Jesteś pewien że chcesz się odłączyć z grupy?', 'Oczekiwanie potwierdzenia', function(r) {
					if (r) {
						$.get("/_json_/group_it/", {
							"action":"REMOVE_FROM_GROUP",
							"group_id":attrValue.group_id
						}, function(returned_data) {
							$(object).html(returned_data.link);
							$(object).attr('data-details', '{"action":"ADD2GROUP", "group_id":'+attrValue.group_id+'}');
						}, "json");
					}
				});
				break;

			case 'CANCEL_AUTH':
				$.get("/_json_/group_it/", {
					"action":"CANCEL_AUTH",
					"group_id":attrValue.group_id
				}, function(returned_data) {
					$(object).html(returned_data.link);
					$(object).attr('data-details', '{"action":"ADD2GROUP", "group_id":'+attrValue.group_id+'}');
				}, "json");
				break;

			default:
				alert('default');
		}
	}
}


