// JavaScript Document
$(document).ready(function(){

/*Forum post*/
	$('#post_top').click(function(){
			var id = $(this).attr('id');
			var href = $(this).attr('href');
			var parent = $('.f_buttons').html();
	 		$('.f_buttons').load(href).fadeIn('slow');
		return false;
		});
	  
	  
	$('.i_post_content a').click(function(){
			var parent = $('.f_buttons').html();
			var id = $(this).attr('id');
			var href = $(this).attr('href');
	  		$('.f_buttons').load(href).fadeIn('slow');
	  	return false;
		});
	  
/*Karma*/
	var sbl, uid;
	$('.m_post_content a').click(function(){
			var symbol = $(this).text();
			var id = $(this).attr('id');
			if(symbol != "" && symbol == '[+] '){
				update_carma('p', id);
			}
			else if(symbol != "" && symbol == ' [-]'){
				update_carma('m', id);
			}
		});
		
	function update_carma(sbl, uid){
		var url = 'carma.php'
		$.post(url, {'symbol': sbl , 'user_id': uid }, function(data){
				alert(data);
				location = location.search;
		});	
	}
	
/*New topic*/

	$("#nw_topic").click(function(){
			var href = $(this).attr('href');
			$('.f_topic_buttons').remove();
			$('.new_topic').load(href);
		return false;
		});
		
/*Profile*/
	$('#edit_user').click(function(){
			$('.edit_prof').slideDown(400);
		});
		
	$('#profile_update').submit(function(){
			var serial = $(this).serialize();
			$.post( "forum/jqueryupd.php?up=profile", serial, function(data){ 
			location = location.href;
			});
		});
		
/*Admin post delete*/
	$('.post_list a').click(function(){
			var id = $(this).attr('id');
			$('#post'+id).html('<span style=" color:red;">Deleted</span>');
			$.post( "forum/jqueryupd.php?up=delete",{'post': id}, function(data){ 
			alert('DELETED!');
			
			});
		});
		
/*Admin user block*/
	$('.user_list a').click(function(){
			var too, update;
			var id = $(this).attr('id');
			var value = $(this).text();
			switch(value){
				case 'Block':
					too = '<span style=" color:red;">Unblock</span>';
					update = 'permit';
				break;
				case 'Unblock':
					too = 'Block';
					update = 'permit';
				break;
				case 'Make':
					too = '<span style=" color:red;">Unmake</span>';
					update = 'status';
				break;
				case 'Unmake':
					too = 'Make';
					update = 'status';
				break;	
			}
			$(this).html(too);
			$.post( "forum/jqueryupd.php?up=update",{'update': update , 'id': id}, function(data){ 
			
			});
		});
		
/**/
	$('.forum_table a').click(function(){
			var type = $(this).attr('class');
			var id = $(this).attr('id');
			var text = $(this).text();
			if(text == 'Delete'){
				$.post( "forum/jqueryupd.php?up=forum",{'type': type , 'id': id, 'button': text}, function(data){ 
				alert(data);
				$('#line'+id).remove();
				location = location.href;
				});
			}

		});


/*Add*/
	$('button').click(function(){
			var html;
			var name = $(this).attr('id');
			switch(name){
				case 'add_cat':
					$('.change2').hide();
					$('.change1').slideDown(400);
				break;
				case 'add_forum':
					$('.change1').hide();
					$('.change2').slideDown(400);
				break;
			}
	});
	
	$('#sub_f1').click(function(){
			$.post("forum/jqueryupd.php?up=newcat", $('#update_f1').serialize() , function(){
			location = location.href;
				});
		});
		
	$('#sub_f2').click(function(){
			$.post("forum/jqueryupd.php?up=newforum", $('#update_f2').serialize() , function(){
				location = location.href;
				});
			
		});
		
/*Topic lock*/
	$('.topic_list a').click(function(){
			var type;
			var id = $(this).attr('id');
			var value = $(this).text();
			switch(value){
				case 'Lock':
					type = 5;
					too = '<span style=" color:red;">Locked</span>';
				break;
				case 'Locked':
					type = 1;
					too = '<span style=" color:green;">Lock</span>';
				break;
			}
			$(this).html(too);
			$.post( "forum/jqueryupd.php?up=topic",{'type': type , 'id': id}, function(data){ 
				location = location.href;
			});
		});
	
});
