
// Quan cliques a les categories

$(function(){
	var LoadMsg = 'Please Wait...';
	$('#nav ul li a').click(function(){
    	if(!$(this).hasClass("a_current")) {
		$('#nav ul li a').attr('class','a_no_current');
		$(this).attr('class','a_current');
		
		
		
		
		$(this).css('cursor','arrow');
		
		var _Href = $(this).attr('href');
		$('#loading_wrap').fadeIn('slow',function(){
			$.ajax({
				type:	'POST',
				url:	_Href,
				data:	"ajax=1",
				dataType:	'html',
				timeout:	5000,
				success: function(d,s){
						$('#loading_wrap').fadeOut('slow',function(){
						//$(this).remove();
						$('#wrapper').fadeOut('slow',function(){
						$(this).html(d).fadeIn('slow');

								////////////////////////
		escolador = 0;														
		var mio = (($('#longuis').attr('class'))*868);
		$('.contenedor').width(mio);
							
								
								//////////////////////// copia de lo de recent per actualitzar els minis
								
								
								// Actualització de el minipost marcat
		
							
					$('#posts_list a').each(function(){
							var pol = 	$('div#title').attr('class');			  
						
						
						if($(this).hasClass("current") && $(this).attr('id')!=pol){
							$(this).attr('class','no_current');
						}
						else{
							
							if($(this).hasClass("no_current") && $(this).attr('id')==pol){
								$(this).attr('class','current');
							}
							else{
								$(this).attr('class','no_current');	
							}
							
						}
					
					
					
					
					});
		
		
					var lupi_mini = 0;
					$('#posts_list li').each(function(){
							
							if ($(this).attr('class') == 'actual_recent'){
								
								var getfirst_mini = $(this).attr('id');
								var gotit_mini = getfirst_mini.replace(/actual_recent/,"");
								$(this).attr('id','no_recent'+gotit_mini);
								
								if(lupi_mini == 1){
								$(this).attr('class','no_recent');
								lupi_mini = 0;
								}else{
								$(this).attr('class','no_recent2');
								lupi_mini = 1;
								}	
								$(this).css('cursor','pointer');
							}
							else
							{
								if ($(this).attr('id') == 'no_recent'+pol){
								$(this).attr('class','actual_recent');	
								$(this).attr('id','actual_recent'+pol);
								$(this).css('cursor','default');
										if(lupi_mini == 1){
										lupi_mini = 0;
										}else{
										lupi_mini = 1;
										}
								}
								else{
										if(lupi_mini == 1){
										$(this).attr('class','no_recent');
										lupi_mini = 0;
										}else{
										$(this).attr('class','no_recent2');
										lupi_mini = 1;
										}
								}
							}
					});
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
					
		
		////////// Fi de la actualització dels miniposts
								
								
								
								
								
								
								
								
								
								
								
								
								
								///////////////////////
								
								/////////////////////// Copia de tota la generacio de minis de mes abaix
								
								
								
		$('#posts_list a').click(function(){		   
    	if(!$(this).hasClass("current")) {
		$('#posts_list a').attr('class','no_current');
		$(this).attr('class','current');
		//////
		var po = $(this).attr('id');
		//////////////////////////////
		
		
		
		var lupi_mini = 0;
		$('#posts_list li').each(function(){
				
				if ($(this).attr('class') == 'actual_recent'){
					
					var getfirst_mini = $(this).attr('id');
					var gotit_mini = getfirst_mini.replace(/actual_recent/,"");
					$(this).attr('id','no_recent'+gotit_mini);
					
					if(lupi_mini == 1){
					$(this).attr('class','no_recent');
					lupi_mini = 0;
					}else{
					$(this).attr('class','no_recent2');
					lupi_mini = 1;
					}
					
					$(this).css('cursor','pointer');
				}
				else
				{
					
					if ($(this).attr('id') == 'no_recent'+po){
					$(this).attr('class','actual_recent');	
					$(this).attr('id','actual_recent'+po);
					$(this).css('cursor','default');
					
					
							if(lupi_mini == 1){
							lupi_mini = 0;
							}else{
							lupi_mini = 1;
							}
					
					}
					else{

							if(lupi_mini == 1){
							$(this).attr('class','no_recent');
							lupi_mini = 0;
							}else{
							$(this).attr('class','no_recent2');
							lupi_mini = 1;
							}
						
					}
				}
			
		
		});
		
		
		
		/////////////  Actualització de la barra de recents
		
		
		
		
					$('#recents a').each(function(){
													  
						
						if($(this).hasClass("current") && $(this).attr('id')!=po){
							$(this).attr('class','no_current');
						}
						else{
							
							if($(this).hasClass("no_current") && $(this).attr('id')==po){
								$(this).attr('class','current');
							}
							else{
								$(this).attr('class','no_current');	
							}
							
						}
					
					});
					
					var lupi = 0;
					$('#recent_list li').each(function(){
					
							
							if ($(this).attr('class') == 'actual_recent'){
								
								var getfirst = $(this).attr('id');
								var gotit = getfirst.replace(/actual_recent/,"");
								$(this).attr('id','no_recent'+gotit);
								
								if(lupi == 1){
								$(this).attr('class','no_recent');
								lupi = 0;
								}else{
								$(this).attr('class','no_recent2');
								lupi = 1;
								}
								
								$(this).css('cursor','pointer');
							}
							else
							{
								
								if ($(this).attr('id') == 'no_recent'+po){
								$(this).attr('class','actual_recent');	
								$(this).attr('id','actual_recent'+po);
								$(this).css('cursor','default');
								
								
										if(lupi == 1){
										lupi = 0;
										}else{
										lupi = 1;
										}
								
								}
								else{
			
										if(lupi == 1){
										$(this).attr('class','no_recent');
										lupi = 0;
										}else{
										$(this).attr('class','no_recent2');
										lupi = 1;
										}
									
								}
							}
						
					
					});
					
					
		
		
		
		
		
		
		
		
		
		/////////////  Fi de l'actualització de la barra de recents
		
		
		
		////////////////////////////////
		
		var _Href = $(this).attr('href');
		$('#loading').fadeIn('slow',function(){
			$.ajax({
				type:	'POST',
				url:	_Href,
				data:	"ajax=1",
				dataType:	'html',
				timeout:	5000,
				success: function(d,s){
					
						$('#loading').fadeOut('slow',function(){
						//	$(this).remove();
							$('#grande').fadeOut('slow',function(){
								
								$(this).html(d).fadeIn('slow');
								//inicialitzar el lightbox molt important
								jQuery.Lightbox.relify(); 

									///////
									var entre='?p=';
									
				
									
									
									$('#nav ul li a').each(function(){
										
										var on=$(this).attr('id');
										$(this).attr('href',on+entre+po);
										
										
									
									});
									
							
				////////////////// Assignació de les funcions dels iconos de veure post i comentaris
				
				
				$('.post_view').hover(function() {
					$(this).css("background","url(../img/postview_act.png) no-repeat");
					}, function() {
						
						id = $('.post_view').attr("id");
						
						if ($("div#contento_"+id).is(':hidden')){
  						$(this).css("background","url(../img/viewpost.png) no-repeat");				
						}
			});
			
			$('#comments_view').hover(function() {
					$(this).css("background","url(../img/comments_act.png) no-repeat");
					}, function() {
					
						if ($(".comments").is(':hidden')){
  						$(this).css("background","url(../img/commentsview.png) no-repeat");
						}
			});
		
		
		
		
		
		$('.post_view').click(function() {
			id = $(this).attr("id");	


			if (!$("div#contento_"+id).is(':animated') && !$(".comments").is(':animated')) {
			
					if ($(".comments").is(':visible')){
						$(".comments").slideToggle(800, 'easeOutSine', 'easeInSine');
						$("#comments_view").css('background','url(../img/commentsview.png) no-repeat'); 
					}
					
						if($("div#contento_"+id).is(':hidden')){
						$(this).css("background","url(../img/postview_act.png) no-repeat"); 
						}else{
						$(this).css("background","url(../img/viewpost.png) no-repeat");
			
						}
			
			$("div#contento_"+id).slideToggle(800, 'easeOutSine', 'easeInSine');
			
			}
			
			return false;

		});
		
		$('#comments_view').click(function() {
			id = $('.post_view').attr("id");
			
			if (!$(".comments").is(':animated') && !$("div#contento_"+id).is(':animated')) {
					
					if ($("div#contento_"+id).is(':visible')){
						$("div#contento_"+id).slideToggle(800, 'easeOutSine', 'easeInSine');
						$(".post_view").css('background','url(../img/viewpost.png) no-repeat'); 
					}
					if($(".comments").is(':hidden')){
						$(this).css("background","url(../img/comments_act.png) no-repeat"); 
						}else{
						$(this).css("background","url(../img/commentsview.png) no-repeat");
			
						}
					$(".comments").slideToggle(800, 'easeOutSine', 'easeInSine');
			}
			return false;
		});
				
				
				
				
				//////////////////////
								
								
								
								
								});
							});
						},
				error: function(o,s,e){
							window.location = _Href;
						}
			});
		});
        }
		return false;
	});
								
								
	
	
			
									
									
									
									/////////////////////////////
						
									
								});
							});
						},
				error: function(o,s,e){
							window.location = _Href;
						}
			});
		});
        }
		return false;
	});
});



// Quan cliques als miniposts


$(function(){
	$('#posts_list a').click(function(){		   
    	if(!$(this).hasClass("current")) {
		$('#posts_list a').attr('class','no_current');
		$(this).attr('class','current');
		//////
		var po = $(this).attr('id');
		//////////////////////////////
		
		
		
		var lupi_mini = 0;
		$('#posts_list li').each(function(){
				
				if ($(this).attr('class') == 'actual_recent'){
					
					var getfirst_mini = $(this).attr('id');
					var gotit_mini = getfirst_mini.replace(/actual_recent/,"");
					$(this).attr('id','no_recent'+gotit_mini);
					
					if(lupi_mini == 1){
					$(this).attr('class','no_recent');
					lupi_mini = 0;
					}else{
					$(this).attr('class','no_recent2');
					lupi_mini = 1;
					}
					
					$(this).css('cursor','pointer');
				}
				else
				{
					
					if ($(this).attr('id') == 'no_recent'+po){
					$(this).attr('class','actual_recent');	
					$(this).attr('id','actual_recent'+po);
					$(this).css('cursor','default');
					
					
							if(lupi_mini == 1){
							lupi_mini = 0;
							}else{
							lupi_mini = 1;
							}
					
					}
					else{

							if(lupi_mini == 1){
							$(this).attr('class','no_recent');
							lupi_mini = 0;
							}else{
							$(this).attr('class','no_recent2');
							lupi_mini = 1;
							}
						
					}
				}
			
		
		});
		
		
		
		/////////////  Actualització de la barra de recents
		
		
		
		
					$('#recents a').each(function(){
													  
						
						if($(this).hasClass("current") && $(this).attr('id')!=po){
							$(this).attr('class','no_current');
						}
						else{
							
							if($(this).hasClass("no_current") && $(this).attr('id')==po){
								$(this).attr('class','current');
							}
							else{
								$(this).attr('class','no_current');	
							}
							
						}
					
					});
					
					var lupi = 0;
					$('#recent_list li').each(function(){
					
							
							if ($(this).attr('class') == 'actual_recent'){
								
								var getfirst = $(this).attr('id');
								var gotit = getfirst.replace(/actual_recent/,"");
								$(this).attr('id','no_recent'+gotit);
								
								if(lupi == 1){
								$(this).attr('class','no_recent');
								lupi = 0;
								}else{
								$(this).attr('class','no_recent2');
								lupi = 1;
								}
								
								$(this).css('cursor','pointer');
							}
							else
							{
								
								if ($(this).attr('id') == 'no_recent'+po){
								$(this).attr('class','actual_recent');	
								$(this).attr('id','actual_recent'+po);
								$(this).css('cursor','default');
								
								
										if(lupi == 1){
										lupi = 0;
										}else{
										lupi = 1;
										}
								
								}
								else{
			
										if(lupi == 1){
										$(this).attr('class','no_recent');
										lupi = 0;
										}else{
										$(this).attr('class','no_recent2');
										lupi = 1;
										}
									
								}
							}
						
					
					});
					
					
		
		
		
		
		
		
		
		
		
		/////////////  Fi de l'actualització de la barra de recents
		
		
		
		////////////////////////////////
		
		var _Href = $(this).attr('href');
		$('#loading').fadeIn('slow',function(){
			$.ajax({
				type:	'POST',
				url:	_Href,
				data:	"ajax=1",
				dataType:	'html',
				timeout:	5000,
				success: function(d,s){
					
						$('#loading').fadeOut('slow',function(){
						//	$(this).remove();
							$('#grande').fadeOut('slow',function(){
								
								$(this).html(d).fadeIn('slow');
								//inicialitzar el lightbox molt important
								jQuery.Lightbox.relify(); 

									///////
									var entre='?p=';
									
				
									
									
									$('#nav ul li a').each(function(){
										
										var on=$(this).attr('id');
										$(this).attr('href',on+entre+po);
										
										
									
									});
									
							
				////////////////// Assignació de les funcions dels iconos de veure post i comentaris
				
				
				$('.post_view').hover(function() {
					$(this).css("background","url(../img/postview_act.png) no-repeat");
					}, function() {
						
						id = $('.post_view').attr("id");
						
						if ($("div#contento_"+id).is(':hidden')){
  						$(this).css("background","url(../img/viewpost.png) no-repeat");				
						}
			});
			
			$('#comments_view').hover(function() {
					$(this).css("background","url(../img/comments_act.png) no-repeat");
					}, function() {
					
						if ($(".comments").is(':hidden')){
  						$(this).css("background","url(../img/commentsview.png) no-repeat");
						}
			});
		
		
		
		
		
		$('.post_view').click(function() {
			id = $(this).attr("id");	


			if (!$("div#contento_"+id).is(':animated') && !$(".comments").is(':animated')) {
			
					if ($(".comments").is(':visible')){
						$(".comments").slideToggle(800, 'easeOutSine', 'easeInSine');
						$("#comments_view").css('background','url(../img/commentsview.png) no-repeat'); 
					}
					
						if($("div#contento_"+id).is(':hidden')){
						$(this).css("background","url(../img/postview_act.png) no-repeat"); 
						}else{
						$(this).css("background","url(../img/viewpost.png) no-repeat");
			
						}
			
			$("div#contento_"+id).slideToggle(800, 'easeOutSine', 'easeInSine');
			
			}
			
			return false;

		});
		
		$('#comments_view').click(function() {
			id = $('.post_view').attr("id");
			
			if (!$(".comments").is(':animated') && !$("div#contento_"+id).is(':animated')) {
					
					if ($("div#contento_"+id).is(':visible')){
						$("div#contento_"+id).slideToggle(800, 'easeOutSine', 'easeInSine');
						$(".post_view").css('background','url(../img/viewpost.png) no-repeat'); 
					}
					if($(".comments").is(':hidden')){
						$(this).css("background","url(../img/comments_act.png) no-repeat"); 
						}else{
						$(this).css("background","url(../img/commentsview.png) no-repeat");
			
						}
					$(".comments").slideToggle(800, 'easeOutSine', 'easeInSine');
			}
			return false;
		});
				
				
				
				
				//////////////////////
								
								
								
								
								});
							});
						},
				error: function(o,s,e){
							window.location = _Href;
						}
			});
		});
        }
		return false;
	});
});







// funcio per la barra de recent posts lateral

$(function(){
	
	
	
	$('#recents a').click(function(){
									
    	if(!$(this).hasClass("current")) {
		$('#recents a').attr('class','no_current');
		$(this).attr('class','current');
		//////
		var por = $(this).attr('id');
		//////
		
		
		// Actualitzo la classe de cada un dels links de la barra de recents
		var lupi = 0;
		$('#recent_list li').each(function(){
		
				
				if ($(this).attr('class') == 'actual_recent'){
					
					var getfirst = $(this).attr('id');
					var gotit = getfirst.replace(/actual_recent/,"");
					$(this).attr('id','no_recent'+gotit);
					
					if(lupi == 1){
					$(this).attr('class','no_recent');
					lupi = 0;
					}else{
					$(this).attr('class','no_recent2');
					lupi = 1;
					}
					
					$(this).css('cursor','pointer');
				}
				else
				{
					
					if ($(this).attr('id') == 'no_recent'+por){
					$(this).attr('class','actual_recent');	
					$(this).attr('id','actual_recent'+por);
					$(this).css('cursor','default');
					
					
							if(lupi == 1){
							lupi = 0;
							}else{
							lupi = 1;
							}
					
					}
					else{

							if(lupi == 1){
							$(this).attr('class','no_recent');
							lupi = 0;
							}else{
							$(this).attr('class','no_recent2');
							lupi = 1;
							}
						
					}
				}
			
		
		});
		
		
		// Actualització de el minipost marcat
		
		
					$('#posts_list a').each(function(){
													  
						
						if($(this).hasClass("current") && $(this).attr('id')!=por){
							$(this).attr('class','no_current');
						}
						else{
							
							if($(this).hasClass("no_current") && $(this).attr('id')==por){
								$(this).attr('class','current');
							}
							else{
								$(this).attr('class','no_current');	
							}
							
						}
					
					
					
					
					});
		
		
					var lupi_mini = 0;
					$('#posts_list li').each(function(){
							
							if ($(this).attr('class') == 'actual_recent'){
								
								var getfirst_mini = $(this).attr('id');
								var gotit_mini = getfirst_mini.replace(/actual_recent/,"");
								$(this).attr('id','no_recent'+gotit_mini);
								
								if(lupi_mini == 1){
								$(this).attr('class','no_recent');
								lupi_mini = 0;
								}else{
								$(this).attr('class','no_recent2');
								lupi_mini = 1;
								}	
								$(this).css('cursor','pointer');
							}
							else
							{
								if ($(this).attr('id') == 'no_recent'+por){
								$(this).attr('class','actual_recent');	
								$(this).attr('id','actual_recent'+por);
								$(this).css('cursor','default');
										if(lupi_mini == 1){
										lupi_mini = 0;
										}else{
										lupi_mini = 1;
										}
								}
								else{
										if(lupi_mini == 1){
										$(this).attr('class','no_recent');
										lupi_mini = 0;
										}else{
										$(this).attr('class','no_recent2');
										lupi_mini = 1;
										}
								}
							}
					});
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
					
		
		////////// Fi de la actualització dels miniposts
		
		var _Href = $(this).attr('href');
		$('#loading').fadeIn('slow',function(){
			$.ajax({
				type:	'POST',
				url:	_Href,
				data:	"ajax=1",
				dataType:	'html',
				timeout:	5000,
				success: function(d,s){
					
						$('#loading').fadeOut('slow',function(){
						//	$(this).remove();
							$('#grande').fadeOut('slow',function(){
								
								$(this).html(d).fadeIn('slow');
								//inicialitzar el lightbox molt important
								jQuery.Lightbox.relify(); 

									
								//////////////
								
								
			////////////////// Assignació de les funcions dels iconos de veure post i comentaris
				
				
				$('.post_view').hover(function() {
					$(this).css("background","url(../img/postview_act.png) no-repeat");
					}, function() {
						
						id = $('.post_view').attr("id");
						
						if ($("div#contento_"+id).is(':hidden')){
  						$(this).css("background","url(../img/viewpost.png) no-repeat");				
						}
			});
			
			$('#comments_view').hover(function() {
					$(this).css("background","url(../img/comments_act.png) no-repeat");
					}, function() {
					
						if ($(".comments").is(':hidden')){
  						$(this).css("background","url(../img/commentsview.png) no-repeat");
						}
			});
		
		
		
		
		
		$('.post_view').click(function() {
			id = $(this).attr("id");	


			if (!$("div#contento_"+id).is(':animated') && !$(".comments").is(':animated')) {
			
					if ($(".comments").is(':visible')){
						$(".comments").slideToggle(800, 'easeOutSine', 'easeInSine');
						$("#comments_view").css('background','url(../img/commentsview.png) no-repeat'); 
					}
					
						if($("div#contento_"+id).is(':hidden')){
						$(this).css("background","url(../img/postview_act.png) no-repeat"); 
						}else{
						$(this).css("background","url(../img/viewpost.png) no-repeat");
			
						}
			
			$("div#contento_"+id).slideToggle(800, 'easeOutSine', 'easeInSine');
			
			}
			
			return false;

		});
		
		$('#comments_view').click(function() {
			id = $('.post_view').attr("id");
			
			if (!$(".comments").is(':animated') && !$("div#contento_"+id).is(':animated')) {
					
					if ($("div#contento_"+id).is(':visible')){
						$("div#contento_"+id).slideToggle(800, 'easeOutSine', 'easeInSine');
						$(".post_view").css('background','url(../img/viewpost.png) no-repeat'); 
					}
					if($(".comments").is(':hidden')){
						$(this).css("background","url(../img/comments_act.png) no-repeat"); 
						}else{
						$(this).css("background","url(../img/commentsview.png) no-repeat");
			
						}
					$(".comments").slideToggle(800, 'easeOutSine', 'easeInSine');
			}
			return false;
		});
				
				
				
				
				//////////////////////
								
								
								
								
								
								
								///////////////
								
								
								
								
								
								});
							});
						},
				error: function(o,s,e){
							window.location = _Href;
						}
			});
		});
        }
		return false;
	});
});


jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}