$(function(){
	$('#postcomment').submit(function(){
		if ($.trim($('[name=comment]').val()) == '') return false;
		if (window.commentsubmited) return false;
		window.commentsubmited = true;
		return true;
	});
	$('.delcomment').click(function(){
		var match = $(this).attr('class').match("comment-(\\d*)");
		var comment = $(this).parents("li:first");
		if (match && confirm("Tiešām dzēst šo komentāru?")) {
			$.get("admin/external.php?action=comments_del&comment_id="+match[1],function(data){
				if (data.error == 0) {
					comment.fadeOut('fast',function(){$(this).remove();});
					$('#comments-counter').html(parseInt($('#comments-counter').html())-1)
				}
				else {
					alert(data.error+': '+data.msg);
				}
			},"json");
		}
	});
	keyCode = 69;
	dontchange = false;
	$('.search-text').bind('keyup',function(e){
		if (e.keyCode == keyCode) {
			dontchange = true;
		}
	}).bind('blur',function(){
		if ($(this).val() == '') { $(this).val(startText); dontchange = false; }
	}).bind('focus',function(){
		if ($(this).val() == startText && !dontchange) $(this).val('');
	});
	$('.search-box').submit(function(){
		if ($('.search-text').val() == startText && !dontchange) return false;
		else if ($('.search-text').val() == '') return false;
		else document.location.href='search/?q='+$('.search-text').val();
		return false;
	});
});
function initFB(fb_id) {
	$('#fb-login').click(function(){
		FB.init({appId: fb_id, status: true,
			cookie: false, xfbml: true});
		FB.login(function(response) {
			if (response.session) {
				$.post("facebook_login/",{credits:response.session},function(data){
					document.location.reload();
				});
			}
		});						
		return false;
	});
}
