// JavaScript Document
  $(document).ready(function(){
	//Menu desplegable
		theRotator();
	$("#menu ul li ul").hide();	
	$("#menu ul li span.current").addClass("open").next("ul").show();
	$("#menu ul li span").click(function(){	
		$(this).next("ul").slideToggle("slow").parent("li").siblings("li").find("ul:visible").slideUp("slow");
		$("#menu ul li").find("span").removeClass("open");
		$(this).addClass("open");
	});
	
	$("a.switch_thumb").toggle(function(){
	  $(this).addClass("swap"); 
	  $("ul.display").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").addClass("thumb_view"); 
		 });
	  }, function () {
      $(this).removeClass("swap");
	  $("ul.display").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").removeClass("thumb_view");
		});
	}); 
		$("#flash").hide();	
$('.loading').show();
        pagina(1,'Fecha',1);

}); 	
 
 function theRotator() {
	$('div#rotatorder ul li').css({opacity: 0.0});
	$('div#rotatorder ul li:first').css({opacity: 1.0});
	setInterval('rotate()',10000);
}
function rotate() {	
	var current = ($('div#rotatorder ul li.show')?  $('div#rotatorder ul li.show') : $('div#rotatorer ul li:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotatorder ul li:first') :current.next()) : $('div#rotatorder ul li:first'));	
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};
     function pagina(cat,ord1,page_id){
        var first = (page_id*10)+1, second = (page_id*10)+10;
		//$('.mediaNavHeader').html("Noticias de San Pedro del Pinatar. <span>Ordenados por: "+ord1+" </span>");
		$('#resj').hide();
		$('.loading').show();
        $.ajax({
        type:'GET',
        url:'pagplenosp.php',
        data:'q2=1&ord2='+ord1+'&pag='+page_id,
        success:function(msg) {
		$('.loading').hide();
		$('#resj').fadeIn('slow');		
			$('#resj').html(msg);
        }
        });
    }
$(function() {
	$(".pag").click(function() {
	var name = this.text;
	pagina(1,name,1);
							 })
return false;
	}); 
$(function(){
	$(".button").click(function() {
		var nid=$(this).attr("id");
		var id =nid.substr(1,10);
		var fmen = $(this).attr("name");
		if (id==0){
			document.getElementById('parent_id').value='0';
			$("#flash").fadeOut(1000);			
		}else{					
			$("#parent_id").attr("value", id);
			$("#flash").show();
			$(".freply").html('Responder a: '+fmen);		
		}
		$("#comment_body").focus();
	});
});


/*************************************/

$(function() {

$(".submit").click(function() {
var parent_id = $("#parent_id").val();
var noticia = $("#noticia").val();
	var comment_body = $("#comment_body").val();
    var dataString = 'noticia='+ noticia + '&parent_id=' + parent_id + '&comment_body=' + comment_body;
	
	if(comment_body=='')
     {
	$("#flash2").addClass("error");
	$("#flash2").removeClass("user_ok");	
	$("#flash2").html("Por Favor aņade algun comentario");
	$("#flash2").show();
	
     }
	else
	{
	$("#flash2").removeClass("error");	
	$("#flash2").addClass("user_ok");
	$("#flash2").show();
	$("#flash2").fadeIn(400).html('Aņadiendo Comentario...');
	$.ajax({
		type: "POST",
		url: "con_imtv/post_com_ple.php",
	    data: dataString,
		cache: false,
		success: function(html){
	    document.getElementById('comment_body').value='';
		document.getElementById('parent_id').value='0';
		$("#flash2").show();
		$("#flash2").html(html);
		$("#flash").fadeOut(2000);
		$("#flash2").fadeOut(5000);
		}
 	});
	}
return false;
	});

});