$.postJSON = function(url, data, callback) {
	$.post(url, data, callback, "json");
};
var C={
	bookmark: {
		add: function(topicId,tp) {
			$.postJSON('/addbookmarks.php?item=' + topicId + '&tp=' + tp, function(json) {
				link = $('a.favorites');
				if (json.action == 'done') {
					$(link).remove();
//					$(link).text('Удалить закладку');
//					$(link).attr('href', 'javascript:C.bookmark.del('+ topicId + ');');
				} 
			});
		},
		del: function(topicId) {
			$.postJSON('/delbookmarks.php?item=' + topicId, function(json) {
				link = $('a.favorites');
				if (json.action == 'done') {
					$(link).text('Добавить в закладки');
					$(link).attr('href', 'javascript:C.bookmark.add('+ topicId + ');');
				} 
			});
		}
	}
}

$(document).ready(function() {
	$(".tab_content").hide();
	$("ul.loginformtab li:first").addClass("active").show();
	$(".tab_content:first").show();
	$('#top_signIn').click(function(e) {
		e.preventDefault();
		var wdth = ($('html')[0].clientWidth - 356); // здесь должна быть другая формула в случае если ширина экрана 1024рх
		$('#loginform').css({left:wdth});
		$('#loginform').css('top', 29);
		$('#sendform1').remove();
		$('.overlay').show();
		$('#loginform').addClass('open');
	}); 

	$('.readnews').click(function(e){
		e.preventDefault();
		$('#loginform').css('top', parseInt($(window).scrollTop(), 10) + parseInt($(window).height(), 10) / 2 - 142);
		$('#loginform').css('left', parseInt($(window).width(), 10) / 2 - 176);
		$('<input type="hidden" name="sendform" value="1" id="sendform1">').insertAfter('.sendbutt');
		$('.overlay').show();
		$('#loginform').addClass('open');
	});
	$('.closebutt').click(function(){
		$('#loginform').removeClass('open');
		$('.overlay').hide();
	});
	$('.overlay').click(function(){
		$('.overlay').hide();
		$('#loginform').removeClass('open');
	});
});
