$(function() {

	$('.post-item').each(function() {
		
		if (typeof($(this).find('div.post-content').attr('id')) == 'undefined') return;
		
		var postId = $(this).find('div.post-content').attr('id').substr(1);
		$('div#p'+postId).css('display', 'none');	
		
		$(this).find('a.more-content').click(function(){

			var newText = '';
			var classParent = '';

			$('.post-item').each(function() {
				var id = $(this).find('div.post-content').attr('id').substr(1);
				$('div#p'+id).slideUp('fast');											 
				$(this).find('a.more-content').text(expand);
				$(this).find('a.more-content').parent().removeClass().addClass('read-it close');
			});
			
			if ($('div#p'+postId+':visible').length == 0)
			{
				$('div#p'+postId).slideDown('fast');
				newText = collapse;
				classParent = 'read-it open';
			}
			else{
				$('div#p'+postId).slideUp('fast');
				newText = expand;
				classParent = 'read-it close';
			}

			$(this).text(newText);
			$(this).parent().removeClass().addClass(classParent);

			return false;
		});

	});
	
	/**
	* HACK FOR LIJIT
	*
	$('input#lwp_2_searchbutton').attr('value','ok');
	expression = new RegExp('\\?en');
	$('div#lwp_ps div:first').addClass('lijitTitle');
	if (!expression.test(document.location))
	{
		$('div#lwp_cloud h3').text('Recherches populaires');
	}
	$('input#lwp_sfd').attr('size', '15');
	*/
	$('div#lwp_f').remove();
	
	
	$('div#gmap').html('<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.fr/maps?f=q&amp;source=s_q&amp;hl=fr&amp;geocode=&amp;q=NextStage%2B25%2Brue%2BMurillo%2B75008%2BParis&amp;sll=47.15984,2.988281&amp;sspn=26.646422,67.675781&amp;ie=UTF8&amp;filter=0&amp;cid=17006357813641342674&amp;s=AARTsJoyLYyGa_f4_6wk1pzrGI1B-cAOig&amp;ll=48.892712,2.310905&amp;spn=0.039502,0.072956&amp;z=13&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="http://maps.google.fr/maps?f=q&amp;source=embed&amp;hl=fr&amp;geocode=&amp;q=NextStage%2B25%2Brue%2BMurillo%2B75008%2BParis&amp;sll=47.15984,2.988281&amp;sspn=26.646422,67.675781&amp;ie=UTF8&amp;filter=0&amp;cid=17006357813641342674&amp;ll=48.892712,2.310905&amp;spn=0.039502,0.072956&amp;z=13&amp;iwloc=A" style="color:#0000FF;text-align:left">Agrandir le plan</a></small>');
	
	
	/* *
	* FORM FILTER PORTEFEUILLE 
	*/
	$('form#filter').find(':submit').hide();
	$('form#filter').change(function(){
		$(this).submit();
		$(this).find(':submit').hide();
	})
	
	
	
	/* *
	* LIMIT UL 
	*/
	function limitLi(This) {
		
		var i = 0;
		$(This).find('li').each(function (){
			
			if (i > nb_limit) $(this).toggle();
			i++;
		});
		
	}
	
	if (typeof(colLimitUl) == 'undefined')
	{
		//return;
	}
	else
	{ 
		//$(colLimitUl).find('ul.limit').each(function(){
		$(colLimitUl).find('ul').each(function(){
											 
			var i = 0 ;					 
			var more = 0 ;
			var h = $(this).prev().text();
			var ul = this;
			
			$(this).find('li').each(function (){
			
				if (i > nb_limit) $(this).toggle();
				if (more == 0 && i > nb_limit) 
				{
					var a = document.createElement('a');
					var p = document.createElement('p');
					$(a).attr('href','#');
					$(a).text(expand);
					$(p).addClass('moreUl close');
					$(p).append(a);
					$(this).parent().after(p);
					
					$(a).toggle(
						function(){
							limitLi(ul);
							$(this).text(collapse);
							$(this).parent().removeClass().addClass('moreUl open');
							return false;
						},
						function(){
							limitLi(ul);
							$(this).text(expand);
							$(this).parent().removeClass().addClass('moreUl close');
							return false;
						}
					);
					more = 1;
				}
				i++;
			
			});
		});
	}
	
	$('form#go-to-extranet').each(function(){
		var This = this;
		$(this).find('input[type=submit]').hide();
		$(this).find('a#extranet-cgp').click(function(){
			$(This).submit();
			return false;
		});
	});
	
	
	
});
