	$(function(){

		$.ajax({                       
				url: "./index.php/home/get_num_pages_noticias",
				type: 'POST',
				dataType: 'text',
				success: function(data) {    
					if(data == '1')
					{
						$('.sec').children().html('');
						$('.news-area').load("./index.php/home/get_noticias_page", { 'page': '1' });
					}
					else
					{
						$('.news-area').load("./index.php/home/get_noticias_page", { 'page': '1' });
					}
				}
		});
		
		$(".more>a").live('click',function(){
			
			cnt_backup = $(".cnt-area").html();
			var title = $(this).parent().parent().children().html();
			var texto_total = $(this).parent().prev().html();
						
			var html = '<div class="noticias"><p><strong>NOT&Iacute;CIAS</strong></p></div><div class="news_area"><div class="point"><div class="news_area_box title2"><span>'+title+'</span><div class="div_text"><p>'+texto_total+'</p> <p class="less" style="color:#5D5D5D;">[<a href="#">voltar</a>]</p></div> </div></div>';
			
			$(".cnt-area").fadeOut('slow', function(){
				$(".cnt-area").html(html).fadeIn('slow');
			});
		});
		
		$(".less>a").live('click',function(){
						 
			$(".cnt-area").fadeOut('slow', function(){
				$(".cnt-area").html(cnt_backup).fadeIn('slow');
			});
		});
		
		$('.prev1').click(function(){
			$('.prev').attr("disabled", "disabled");
			$('.next').attr("disabled", "disabled");
			
			if($('.pri').children().html() == 1)
				return false;

			var pri = $('.pri').children().html(); 
			pri--;
			var sec =  parseInt(pri)+1;
			
			$('.pri').children().html(pri);
			$('.sec').children().html(sec);
			
			$('.news-area').fadeTo('medium',0.2,function(){
				$('.news-area').load("./index.php/home/get_noticias_page", { 'page': pri }, function(){
					$('.prev').attr("disabled", "");
					$('.next').attr("disabled", "");
					$('.news-area').fadeTo('medium',1);
				});
			});
			
			
			
			return false;
		});
	
		$('.next1').click(function(){
			
			$('.prev').attr("disabled", "disabled");
			$('.next').attr("disabled", "disabled");
			
			var pri = $('.pri').children().html(); 
			//pri--;
			var sec =  $('.sec').children().html();
			//sec--;
			if(sec == '') return false;
			
			$.ajax({                       
				url: "./index.php/home/get_num_pages_noticias",
				type: 'POST',
				dataType: 'text',
				success: function(data) {    
					if(parseInt(sec) < parseInt(data))
					{
						$('.pri').children().html(parseInt(pri)+parseInt(1));
						$('.sec').children().html(parseInt(sec)+parseInt(1));
						$('.news-area').fadeTo('medium',0.2,function(){
							$('.news-area').load("./index.php/home/get_noticias_page", { 'page': (parseInt(pri)+parseInt(1)) }, function(){
								$('.prev').attr("disabled", "");
								$('.next').attr("disabled", "");
								$('.news-area').fadeTo('medium',1);
							});
						});
					}
					else if(sec == data)
					{
						$('.pri').children().html(sec);
						$('.sec').children().html('');
						
						$('.news-area').fadeTo('medium',0.2,function(){
							$('.news-area').load("./index.php/home/get_noticias_page", { 'page': parseInt(sec) }, function(){
								$('.prev').attr("disabled", "");
								$('.next').attr("disabled", "");
								$('.news-area').fadeTo('medium',1);
							});
						});
					}
					else
					{
						$('.prev').attr("disabled", "");
						$('.next').attr("disabled", "");
						return false;
					}
				}
			});
			
			return false;
		});     
	});

