jQuery.getDocWidth = function(){
				  return Math.max(
				      //jQuery(document).width(),
				      jQuery(window).width(),
				      /* For opera: */
				      document.documentElement.clientWidth
				  );
			};
			
			
$(function() {
				/**
				* solve IE AJAX cache problem
				*/
				$.ajaxSetup({cache: false});
                
				/**
				* the index of the current element / blog selected
				* and the total number of elements / blogs
				*/
				//var current = -1;
				//var total	= $('#friendsList').children().length;
				
				/**
				* when we click on a blog link,
				* we get the latest post with an AJAX request
				*/
				$('#mentions_legales a').bind('click',function(e){
					var $this = $(this);
					show();
					/*var $elem	= $this.parent();
					current 	= $elem.index() + 1;
					var source 	= $elem.attr('class');*/
					/**
					* add the title and image of the blog
					*/
					/*$('#blog_info').empty()
								   .html('<img src="images/' + source + '.jpg"></img>' + $this.find('em').html());	*/
					$.get('mentions_legales.php', {} , function(data) {
						$('#latest_post').removeClass('loading').html(data);
					});
					e.preventDefault();
				});
				
				/**
				* show the dialog with the post
				*/
				function show(){
				var haut_page=jQuery.getDocWidth();
				var left_modal = (haut_page-500)/2;
			
					$('#overlay').show();
					if(!$('#modal').is(':visible'))
					//$('#modal').css('left','-260px')
					$('#modal').css({'left':'-260px','z-index':'1002'})
							   .show()
							   .stop()
								   .animate({'left':left_modal+'px'}, 500);
				}
				
				/**
				* hide the dialog
				*/
				function hide(){
					$('#modal').stop()
							   .animate({'left':'150%'}, 500, function(){
									$(this).hide();
									$('#overlay').hide();
									//$('#latest_post').empty();
							   });
				}
				
				/**
				* clicking on the cross hides the dialog
				*/
				$('#modal .close').bind('click',function(){
					hide();
				});
				
				/**
				* clicking on the next on the dialog
				*/
				$('#modal .next').bind('click',function(e){
					if(current == total){ 
						e.preventDefault();
						return;
					}	
					//$('#latest_post').empty().addClass('loading');
					//$('#friendsList li:nth-child('+ parseInt(current+1) +')').find('a').trigger('click');
					e.preventDefault();
				});
				
				/**
				* clicking on the prev on the dialog
				*/
				$('#modal .prev').bind('click',function(e){										
					if(current == 1){ 
						e.preventDefault();
						return;
					}	
					//$('#latest_post').empty().addClass('loading');
					//$('#friendsList li:nth-child('+ parseInt(current-1) +')').find('a').trigger('click');
					e.preventDefault();
				});
});
