function show_hide_no_img(id) {
	var klappText = document.getElementById(id);	
	if ($(klappText).css('display') == 'none') {
		$(klappText).slideDown("normal");
	} else {
		$(klappText).slideUp("normal");
	}
}

function show_hide(id) {
	var klappText = document.getElementById('s' + id);
	var klappBild = document.getElementById('pic' + id);

	if ($(klappText).css('display') == 'none') {
		$(klappText).slideDown("normal");
		$(klappBild).attr('class', 'icon_minus');
		klappBild.title = 'Скрыть';
	} else {		
		$(klappText).slideUp("normal");		
		$(klappBild).attr('class', 'icon_plus');
		klappBild.title = 'Показать';
	}
}

prev_cat_id = 0;
function show_tags(cat_id) {
	if (prev_cat_id != cat_id) {
		prev_cat_id = cat_id;
		if ($('#cat_tags').css('display') != 'none')
			$('#cat_tags').slideUp("fast");
		$.post(
			'/ajax.php',
			{func: 'show_tags',
			cat_id: cat_id},
			function (data) {
				$('#cat_tags').html(data);
				$('#cat_tags').slideDown("fast");
			}
		);
	} else {
		if ($('#cat_tags').css('display') == 'none')
			$('#cat_tags').slideDown("fast");
		else
			$('#cat_tags').slideUp("fast");
	}
}

function browse_switch(type) {
	$.cookie("browse_type", type, {expires: 30});
	window.location.reload();
}

function formSubmit(formID) {
	$('#'+formID).submit();
}

function voteMoimir(){
	var url = "http://connect.mail.ru/share?url="+encodeURIComponent(texts.url)+"&title="+encodeURIComponent(texts.title)+"&description="+encodeURIComponent(texts.descr)+"&imageurl="+encodeURIComponent(texts.image);
	window.open(url,'','toolbar=0,status=0,width=626,height=436');
	$.modal.close();
	return false;
}
function voteFacebook(){
	var url = "http://www.facebook.com/sharer.php?s=100&p[title]="+encodeURIComponent(texts.title)+"&p[summary]="+encodeURIComponent(texts.descr)+"&p[url]="+encodeURIComponent(texts.url)+"&p[images][0]="+encodeURIComponent(texts.image);
	window.open(url,'','toolbar=0,status=0,width=626,height=436');
	$.modal.close();
	return false;
}
function voteVkontakte(){
	var url = "http://vkontakte.ru/share.php?title="+encodeURIComponent(texts.title)+"&description="+encodeURIComponent(texts.descr)+"&url="+encodeURIComponent(texts.url)+"&image="+encodeURIComponent(texts.image);
	window.open(url,'','toolbar=0,status=0,width=626,height=436');
	$.modal.close();
	return false;
}
function voteTwitter(){
	var url = "http://twitter.com/share?text="+encodeURIComponent(texts.title)+"&url="+encodeURIComponent(texts.url);
	window.open(url,'','toolbar=0,status=0,width=626,height=436');
	$.modal.close();
	return false;
}
function vote(id, type, vote) {
	$.post(
		'/reputation.php',
		{action: 'add',
		targetid: id,
		type: type,
		vote: vote},
		function (data) {
			result = $.parseJSON(data);
			if (result.status == 'error')
				alert(result.msg);
			else if (type == 'comment') {
				$('#comment'+id+' .reputation .btn').hide();
				var val_obj = $('#comment'+id+' .reputation .value');
				var reputation = parseInt($(val_obj).html()) + parseInt(result.value);
				if (reputation > 0) {
					reputation = '+'+reputation;
					if (!$(val_obj).hasClass('up'))
						$(val_obj).addClass('up').removeClass('down');
				} else if (reputation < 0) {
					reputation = '-'+reputation;
					if (!$(val_obj).hasClass('down'))
						$(val_obj).addClass('down').removeClass('up');
				} else if (reputation == 0)
					$(val_obj).attr('class', '');
				$('#comment'+id+' .reputation .value').html(reputation);
			}
		}
	);
}

function support_localStorage() {
	try {
		return 'localStorage' in window && window['localStorage'] !== null;
	} catch (e) {
		return false;
	}
}

function unescapeHtml(html) {
	var temp = document.createElement("div");
	temp.innerHTML = html;
	var result = temp.childNodes[0].nodeValue;
	temp.removeChild(temp.firstChild)
	return result;
}
