/*   jQuery   */

$(function(){

// This toggle the comment form in the main page
	$('a#toggle_create').click(function(){
	$('#create_post').toggle('slow');
	return false;
	});

//	This makes the preview
	$('a#ask_preview').click(function(){
	var comment = $('textarea#comment').val();
	comment = jQuery.trim(comment);
	comment = encodeURIComponent(comment);
	if(comment){
	$('#preview_post').hide('fast',function(){
	$.ajax({
		url: 'http://chan.technotaku.com/engine/preview.php',
		type: 'POST',
		data: 'comment=' + comment,
		success: function(result){
			var comentario = result.replace(/\n/g,"<br>");
	$('#preview_post').show('fast');
	$('#preview_post').html(comentario);
		}
	});
	});
	}
	});


// This don't let you send the form without title or text
	$('input#send_post').click(function(){
	var comment = $('textarea#comment').val();
	comment = jQuery.trim(comment);
	var title = $('input#title').val();
	title = jQuery.trim(title);
	var category = $('select#category').val();
	if(!title){
	$('input#title').focus();
	return false;
	}
	if(!comment){
	$('textarea#comment').focus();
	return false;
	}
	if(!category){
	$('select#category').focus();
	return false;
	}
	});

//	Youtube

	$('img.yt_link').live('click',function(){
	var theseids = $(this).attr('id');
	$('#' + theseids + '_video').toggle('fast');
//	$(this).toggle('fast');
	return false;
	});

	$('p.yt_link').live('click',function(){
	var theseids = $(this).attr('id');
	$('#' + theseids + '_video').toggle('fast');
//	$(this).toggle('fast');
	return false;
	});



	$('a#load_last_comments').click(function(){
	var currentposts = $('ul#chan_post_list li').size();
	var page = (currentposts / 10) + 1;
	$.ajax({
		url: 'http://chan.technotaku.com/engine/ajax.loadposts.php?page=' + page,
		type: 'POST',
		data: 'action=last_comments',
		success: function(result){
		$(result).appendTo('ul#chan_post_list');
		}
	});
	return false;
	});

	$('a#load_last_posts').click(function(){
	var currentposts = $('ul#chan_post_list li').size();
	var page = (currentposts / 10) + 1;
	$.ajax({
		url: 'http://chan.technotaku.com/engine/ajax.loadposts.php?page=' + page,
		type: 'POST',
		data: 'action=last_posts',
		success: function(result){
		$(result).appendTo('ul#chan_post_list');
		}
	});
	return false;
	});













});




