$(document).ready(function(){
	setTimeout(function(){
		if(!$('#iframed_banner').hasClass('closed')){
			hide_rsr_banner();
		}
	}, 4000);
	
	
	$('#banner_rsr_button').click(function(){ 
		if($('#iframed_banner').hasClass('closed')){
			show_rsr_banner();
		}else{
			hide_rsr_banner();
		}
	});
	if(getCookie('banner_status') != 'true'){
		var expdate = new Date ();
		DateExpiration (expdate);
		expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); 
		FixCookie('banner_status', 'true', expdate);	
	}
		ajax_serv = "http://"+document.domain+"/";
		audio_url = $('#first_audio_url').text();	
		object_str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="160" height="20" id="dewplayer" align="middle"><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+ajax_serv+'dewplayer-mini.swf?mp3='+audio_url+'&amp;showtime=1&amp;autostart=0" /><param name="quality" value="high" /><param name="bgcolor" value="FFFFFF" /><embed src="'+ajax_serv+'dewplayer-mini.swf?mp3='+audio_url+'&amp;showtime=1&amp;autostart=0" quality="high" bgcolor="FFFFFF" width="160" height="20" name="dewplayer" wmode="transparent" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';		
		document.getElementById('dewplayer').innerHTML= object_str;
	   	$('.images_vignettes_audio').click(function(){
	   		/*if((filter != "default")&&(filter != "onglet_audio")){
	   			no_last_hash = true;
	   			load_article_call(hashContent, param, animate_left_menu, "onglet_audio");	   		
	   		}*/
	   		$('.nextselection').hide();
	   		$('.previewselection').hide();
	   		$('#rang_top_gallery').hide();
	   		if($('#rang_top_gallery').hasClass('block')){
	   			$('#rang_top_gallery').removeClass('block');
	   		}
	   		if(!$('#rang_top_gallery').hasClass('none')){
	   			$('#rang_top_gallery').addClass('none');
	   		}
	   		$('#rang_top_audio').show();
	   		if($('#rang_top_audio').hasClass('none')){
	   			$('#rang_top_audio').removeClass('none');
	   		}
	   		if(!$('#rang_top_audio').hasClass('block')){
	   			$('#rang_top_audio').addClass('block');
	   		}
	   		
	   	});
	   	$('.images_vignettes_image').click(function(){
	   		/*if(filter != "onglet_image"){
	   			no_last_hash = true;
	   			load_article_call(hashContent, param, animate_left_menu, "onglet_image");	   		
	   		}*/
	   		
	   		$('#rang_top_audio').hide();
	   		if($('#rang_top_audio').hasClass('block')){
	   			$('#rang_top_audio').removeClass('block');
	   		}
	   		if(!$('#rang_top_audio').hasClass('none')){
	   			$('#rang_top_audio').addClass('none');
	   		}
	   		$('#rang_top_gallery').show();
	   		if($('#rang_top_gallery').hasClass('none')){
	   			$('#rang_top_gallery').removeClass('none');
	   		}
	   		if(!$('#rang_top_gallery').hasClass('block')){
	   			$('#rang_top_gallery').addClass('block');
	   		}
			if(($('.div_images_vignettes').length > 4)){  	
				if(!$("#rang_top_gallery").children('div').hasClass('__scrollable')){
					$("#rang_top").hide();
					$("#rang_down").hide();
					setTimeout("set_gal_scrollable()",0.1);
				}else{
					$("#rang_top_gallery").scrollable().setPage(0);
					$('.nextselection').show();
				}
		   	}	   		
	   	});
	   	/*$('.images_vignettes_video').click(function(){
	   		if(filter != "onglet_video"){
	   			no_last_hash = true;
	   			load_article_call(hashContent, param, animate_left_menu, "onglet_video");	   		
	   		}
	   	});
	   	$('.images_vignettes_fichier').click(function(){
	   		if(filter != "onglet_fichier"){
	   			no_last_hash = true;
	   			load_article_call(hashContent, param, animate_left_menu, "onglet_fichier");	   		
	   		}
	   	});*/	   	
	   	$('.add_article_playlist').click(function () { 
	   		if($(this).hasClass('front')){
	   			add_item_to_playlist($(this).attr('id'), 'transfer', '', 'thema_index');
	   		}else{
 				add_item_to_playlist($(this).attr('id'), 'transfer', '', 'article_index');
 			}
		});
		$('.add_comment').click(function () { 
			if($('#bloc_add_comment').length == 0){
				article = $(this).attr('id').split('_')[2];
				load_zone_add_comment(article);
			}
		});
		$('.show_comments').click(function () {
			if($('#bloc_show_comment').length == 0){
					article = $(this).attr('id').split('_')[2];
					load_zone_show_comments(article);
			}
		});
		$('.images_vignettes').click(function(){
			toCrop = false;
			if($(this).hasClass('small_croppable')){
				toCrop = true;
			}
			large_image_url = $(this).parent().attr('id');
			title = $(this).parent().children('div').text();
			show_article_large_image(large_image_url, toCrop, title);
		});
		$('.small_croppable').each(function(){
			$(this).crop({x:15, y:48, height:57, width:80});
		});
		$("#fancy_gal").fancybox({
			'zoomSpeedIn':	145, 
			'zoomSpeedOut':	0,
			'overlayShow':	true
		});		
		$('.read_article_lien').each(function(){
				var href = $(this).attr('href');
				var target = $(this).attr('target');
				$(this).parent().parent().children('.article_p2').click(function(){
					document.location.href = href;
				});
				$(this).parent().parent().children('.article_p1').children('.titre_milieu').click(function(){
					document.location.href = href;
				});
				$(this).parent().parent().children('#titre_news').click(function(){
					if(target == '_blank'){
						window.open(href,target);
					}else{
						document.location.href = href;
					}				
				});
				$(this).parent().parent().children('#texte_news').click(function(){
					if(target == '_blank'){
						window.open(href,target);
					}else{
						document.location.href = href;
					}	
				});			
				$(this).parent().parent().children('#image_news').click(function(){
					if(target == '_blank'){
						window.open(href,target);
					}else{
						document.location.href = href;
					}	
				});
			});			
		$('.audio_element_link').click(function(){
			audio_url = $(this).children('div').text();
			object_str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="160" height="20" id="dewplayer" align="middle"><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+ajax_serv+'dewplayer-mini.swf?mp3='+audio_url+'&amp;showtime=1&amp;autostart=1" /><param name="quality" value="high" /><param name="bgcolor" value="FFFFFF" /><embed src="'+ajax_serv+'dewplayer-mini.swf?mp3='+audio_url+'&amp;showtime=1&amp;autostart=1" quality="high" bgcolor="FFFFFF" width="160" height="20" name="dewplayer" wmode="transparent" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
			document.getElementById('dewplayer').innerHTML= object_str;
		});
		$("#auth_form").fancybox({
			'zoomSpeedIn':	145, 
			'zoomSpeedOut':	0, 
			'frameWidth' : 300,
			'frameHeight' : 260,
			'overlayShow':	true
		});
		$("a#super_admin_zone_anchor").fancybox({
			'zoomSpeedIn':	0, 
			'zoomSpeedOut':	0,
			'frameWidth' : 800,
			'frameHeight' : 600
		});
	$("a#show_manual").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0,
		'frameWidth' : 1020,
		'frameHeight' : 355
	});
		//$("#search").bind("click", load_search_zone);
		$('#onglet_logout').click(function(){
			disconnect_user();
		});
		if(($('.div_images_vignettes').length > 4)){  	
			if($('.div_images_vignettes').parent().hasClass('block')){
				$("#rang_top").hide();
				$("#rang_down").hide();
				setTimeout("set_gal_scrollable()",0.1);
			}
	   	}
	   	$("#search").bind("click", load_search_zone);
		if(getCookie('animation') != "true"){
			setTimeout("toggledMenuInit(0)",1000);
			var expdate = new Date ();
			DateExpiration (expdate);
			expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); 
			FixCookie('animation', 'true', expdate, '/');
		}
});	
function set_topic_scrollable(){	
	var step = 0;
	$("#scrollable").scrollable({size:4, prev:'.prev_topic', next:'.next_topic', clickable: false});
	if($('.topic_actif').length > 0){			
		tokens = $('.topic_actif').attr('id').split('_');
		
		pos = tokens[3] *1;
		
		page = Math.floor((pos)/4);
		if($("#scrollable").scrollable().getStatus().page != page){

			step = pos - ($("#scrollable").scrollable().getStatus().size-1);
			for(i=0; i< step; i++){
				$("#scrollable").scrollable().next(10);
			}
		}
	}
	if(step==($("#scrollable").scrollable().getStatus().total-$("#scrollable").scrollable().getStatus().size)){
		$('#next_topic').removeClass('next_appear');
		//$('#next_topic').hide(); 
	}else{
		$('#next_topic').addClass('next_appear');
		//$('#next_topic').show(); 
	}
	if(step == 0){
		$('#prev_topic').removeClass('prev_appear');
		//$('#prev_topic').hide();
	}else{
		$('#prev_topic').addClass('prev_appear');
		//$('#prev_topic').show();
	}
	

	//alert($("#scrollable").scrollable().getStatus().total);

	$('#next_topic').click(function(){
		step++;
		$('#prev_topic').addClass('prev_appear');
		//$('#prev_topic').show();	
		$("#scrollable").scrollable().next();
		if(($("#scrollable").scrollable().getStatus().size+$("#scrollable").scrollable().getStatus().index)==$("#scrollable").scrollable().getStatus().total){
			$('#next_topic').removeClass('next_appear');
			//$('#next_topic').hide();
		}
	});
	$('#prev_topic').click(function(){
		step--;
		$('#next_topic').addClass('next_appear');
		//$('#next_topic').show();
		$("#scrollable").scrollable().prev();
		if($("#scrollable").scrollable().getStatus().index==0){
			$('#prev_topic').removeClass('prev_appear');
			//$('#prev_topic').hide();
		}
	});
}
function auth_user(){
	login = "";
	password = "";
	$('#fancy_div').children('div:eq(0)').children('div:eq(0)').children().each(function(){
		if($(this).attr('id')=='login_input'){
			login = $(this).val();
		}else if($(this).attr('id')=='password_input'){
			password = $(this).val();
			if(password != ""){
			password = password.md5();
			}
		}
	});
	if((login != "") && (password != "")){
		data_string = 'login='+login+'&password='+password;
		$.ajax({
		   type: 'POST',
		   url: ajax_serv+'auth_user.php',
		   data: data_string,
		   success: function(msg){
		   	if(msg.substr(-8) == "not_auth"){
		   		show_error_field();
		   		$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error'><br /></div>");
		   		$('#fancy_div').children('div:eq(0)').children('#login_info').children('#auth_error').fadeIn('slow').append("Mauvais login et/ou password");
		   	}else if(msg == "reload"){
		   		window.location.reload();
		   	}
		   }
		 }); 		
	}else if((login == "") && (password == "")){ 
		show_error_field();
		$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error' style='display:none'><br />Champs Login vide!<br />Champs Password vide!</div>");
		$('#fancy_div').children('div:eq(0)').children('#login_info').children('#auth_error').fadeIn('slow');
	}else{
		show_error_field();
		if(login == ""){
			$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error' style='display:none'><br />Champs Login vide!</div>");
		}else if(password == ""){
			$('#fancy_div').children('div:eq(0)').children('#login_info').append("<div id='auth_error' style='display:none'><br />Champs Password Vide</div>");
		}
		$('#fancy_div').children('div:eq(0)').children('#login_info').children('#auth_error').fadeIn('slow');
	}
}
function disconnect_user(){
	data_string = '';
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'disconnect_user.php',
	   data: data_string,
	   success: function(msg){
   		window.location.reload();
	   }
	 }); 
}
function show_error_field(){
	if($('#auth_error').text()==""){
		$('#fancy_outer').animate({"height": "+=40px"}, 'slow');
	}else{
		$('#auth_error').remove();
	}
}
function handle_pwd_form(){
	if(!$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_loosed').hasClass('shown')){
		$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_loosed').addClass('shown');
		$('#fancy_outer').animate({"height": "+=50px"}, 'fast', function(){
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').fadeIn('fast');
		});
	}else{
		$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_loosed').removeClass('shown');
		$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').fadeOut('fast', function(){
			$('#fancy_outer').animate({"height": "-=50px"}, 'fast');
		});
	}
}
function regenerate_password(){
	email = $('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_email_input').val();
	if(echeck(email)){
		data_string = 'email='+email;
		$.ajax({
		   type: 'POST',
		   url: ajax_serv+'regenerate_password.php',
		   data: data_string,
		   success: function(msg){
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_email_input').removeClass('account_form_error');
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_reg_msg').remove();
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').append("<div id='pwd_reg_msg' style='display:none'><br />"+msg+"</div>");
			$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_reg_msg').fadeIn('slow');
		   }
		 }); 
	 }else{
	 	$('#fancy_div').children('div:eq(0)').children('#pwd').children('#pwd_form').children('#pwd_email_input').addClass('account_form_error');
	 }
}
function handle_account_form(){
	if(!$('#fancy_div').children('div:eq(0)').children('#account').children('#create_account').hasClass('shown')){
		$('#fancy_div').children('div:eq(0)').children('#account').children('#create_account').addClass('shown');
		$('#fancy_outer').animate({"height": "+=120px"}, 'fast', function(){
			$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').fadeIn('fast');
		});
	}else{
		$('#fancy_div').children('div:eq(0)').children('#account').children('#create_account').removeClass('shown');
		$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').fadeOut('fast', function(){
			$('#fancy_outer').animate({"height": "-=120px"}, 'fast');
		});
	}
}
function create_new_account(){
	errors = false;
	login = "",
	password = "";
	email = "";
	$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children().each(function(){
		verify_field($(this).attr('id'));
	});
	$('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children().each(function(){
		if($(this).hasClass('account_form_error')){
			errors = true;
		}else{
			if($(this).attr('id')=="account_login_input"){
				login = $(this).val();
			}else if($(this).attr('id')=="account_password_input"){
				password = $(this).val();
			}else if($(this).attr('id')=="account_email_input"){
				email = $(this).val();
			}
		}
	});
	if(errors == true){
	}else{
		data_string = 'login='+login+'&password='+password+'&email='+email;
		$.ajax({
		   type: 'POST',
		   url: ajax_serv+'add_new_user.php',
		   data: data_string,
		   success: function(msg){
			if(msg == "login used"){
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_login_input');
				element.addClass('account_form_error');
			}else if(msg == "mail adress used"){
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_email_input');
				element.addClass('account_form_error');
			}else if(msg == "login and mail adress used"){
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_login_input');
				element.addClass('account_form_error');
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#account_email_input');
				element.addClass('account_form_error');
			}else{
				element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form');
				element.empty();
				element.append("<div id='create_account_success'>Inscription effectuée avec succès! Pour terminer votre inscription, cliquez sur le lien envoyé par mail!</div>");
			}
		   }
		 }); 					
	}
}
function verify_field(element_name){
	element = $('#fancy_div').children('div:eq(0)').children('#account').children('#account_form').children('#'+element_name);
	if(element_name == 'account_login_input'){
		if((element.val() =="") || (element.val().length < 2)){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}
	}
	if(element_name == 'account_password_input'){
		if((element.val() =="") || (element.val().length < 4)){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}		
	}
	if(element_name == 'account_password_input_bis'){
		if((element.val() =="") || (element.val().length < 4) ||((element.val())!=(element.parent().children('#account_password_input').val()))){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}		
	}
	if(element_name == 'account_email_input'){
		if(!echeck(element.val())){
			element.addClass('account_form_error');
		}else{
			element.removeClass('account_form_error');
		}		
	}
}
function add_item_to_playlist(element, animation, stringToPrepend, location){	
	isRep = false;
	if(animation == 'transfer'){
		itemID = "";
		divID = "";
		text = "";
		if((((element+'').substr(0, 12))=='article_list')||(((element+'').substr(0, 12))=='reperto_list')){
			
			if($('#'+element).hasClass('rep')){
				isRep = true;
			}
			itemID = (element+'').substr(12, (element+'').length);
			itemIDSTR = itemID+"";
			if(itemID.substr(0, 3)=='rep'){
				itemID = (itemID+'').substr(3, (itemID+'').length);
			}
			if(isRep){
				divID = "repid"+itemID;
			}else{
				divID = "itemid"+itemID;
			}	
			if($('#'+element).hasClass('front')){
				item_title = $('#'+divID+'').contents('#titre_news').text();
			}else{
				item_title = $('#'+divID+'').contents('.article_p1').contents('.titre_milieu').text();
			}
			if(isRep){
				clickStr = 'remove_from_playlist("rep_'+itemID+'")';	
			}else{
				clickStr = 'remove_from_playlist('+itemID+')';				
			}
			if(isRep){
				text = '<div class="item_in_pl rep" id="in_plrep_'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong(item_title)+'</div>';
				itemID = 'rep_'+itemID;
			}else{
				text = '<div class="item_in_pl" id="in_pl'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong(item_title)+'</div>';
			}	
		}else if(((element+'').substr(0, 15))=='current_article'){ 
			itemID = (element+'').substr(15, (element+'').length);
			divID = "titre_milieu_large";		
			clickStr = 'remove_from_playlist('+itemID+')';	
			text = '<div class="item_in_pl" id="in_pl'+itemID+'"><div class="remove_from_pl" onclick='+clickStr+'><img src="'+ajax_serv+'img/cross.gif"/></div>'+cutIflong($('#'+divID+'').text())+'</div>';		
		}
	}else{		
		itemID = element;
		text = stringToPrepend;
	}
	data_string = 'item_id='+itemID;
	if(isRep){
		if(itemID.length > 4){
			if(itemID.substr(0, 3)=='rep'){
				itemID_tokens = itemID.split('_');
				itemID = itemID_tokens[1]; 
			}
		}	
	}
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'add_item_to_playlist.php',
	   data: data_string,
	   success: function(msg){
         	if(msg == "success"){
			if(itemID.length > 4){
				if(itemID.substr(0, 3)=='rep'){
					itemID_tokens = itemID.split('_');
					itemID = itemID_tokens[1]; 
					isRep = true;
				}
			}
			if($('#text_playlist')!=null)
			{
				$('#text_playlist').remove();
			}
			$('#carre_playlist').prepend(text);
			if(location == "thema_index"){
				$('#article_list'+itemID).children('.ajouter_article_icon').hide();
				$('#article_list'+itemID).children('.ajouter_article').hide();
				$('#article_list'+itemID).children('.supprimer_article_icon').show();
				$('#article_list'+itemID).children('.supprimer_article').show();
				if($('#current_article'+itemID).length > 0){
					$('#current_article'+itemID).children('.ajouter_article_icon').hide();
					$('#current_article'+itemID).children('.ajouter_article').hide();
					$('#current_article'+itemID).children('.supprimer_article_icon').show();
					$('#current_article'+itemID).children('.supprimer_article').show();				
				}
			}else if(location == "article_index"){
				$('#current_article'+itemID).children('.ajouter_article_icon').hide();
				$('#current_article'+itemID).children('.ajouter_article').hide();
				$('#current_article'+itemID).children('.supprimer_article_icon').show();
				$('#current_article'+itemID).children('.supprimer_article').show();
				if($('#article_list'+itemID).length > 0){
					$('#article_list'+itemID).children('.ajouter_article_icon').hide();
					$('#article_list'+itemID).children('.ajouter_article').hide();
					$('#article_list'+itemID).children('.supprimer_article_icon').show();
					$('#article_list'+itemID).children('.supprimer_article').show();				
				}
			}
			if(animation=='transfer'){
				$('#'+divID+'').effect("transfer", { to: "div.carre", className: "transferring" }, 1000);
				if(isRep){
					$('#repid'+itemID).draggable( "disable" );
				}else{
					$('#itemid'+itemID).draggable( "disable" );
				}				
			}else{
				if(isRep){
					$('#repid'+itemID).draggable( "disable" );
				}else{
					$('#itemid'+itemID).draggable( "disable" );
				}
			}
		}else{
			if(itemID.length > 4){
				if(itemID.substr(0, 3)=='rep'){
					itemID_tokens = itemID.split('_');
					itemID = itemID_tokens[1]; 
					isRep = true;
				}
			}	
			if(location == "thema_index"){
				$('#article_list'+itemID).children('.supprimer_article_icon').hide();
				$('#article_list'+itemID).children('.supprimer_article').hide();	
				$('#article_list'+itemID).children('.ajouter_article_icon').show();
				$('#article_list'+itemID).children('.ajouter_article').show();	
					if(isRep){
						$('#repid'+itemID).draggable( "enable" );
					}else{
						$('#itemid'+itemID).draggable( "enable" );
					}
				if($('#current_article'+itemID).length > 0){
					$('#current_article'+itemID).children('.supprimer_article_icon').hide();
					$('#current_article'+itemID).children('.supprimer_article').hide();
					$('#current_article'+itemID).children('.ajouter_article_icon').show();
					$('#current_article'+itemID).children('.ajouter_article').show();				
				}
			}else if(location == "article_index"){
				$('#current_article'+itemID).children('.supprimer_article_icon').hide();
				$('#current_article'+itemID).children('.supprimer_article').hide();
				$('#current_article'+itemID).children('.ajouter_article_icon').show();
				$('#current_article'+itemID).children('.ajouter_article').show();
				if($('#article_list'+itemID).length > 0){
					$('#article_list'+itemID).children('.supprimer_article_icon').hide();
					$('#article_list'+itemID).children('.supprimer_article').hide();	
					$('#article_list'+itemID).children('.ajouter_article_icon').show();
					$('#article_list'+itemID).children('.ajouter_article').show();				
				}
			}	
			if(isRep){
				$('#in_plrep_'+itemID).empty();
				$('#in_plrep_'+itemID).remove();
			}else{
				$('#in_pl'+itemID).empty();
				$('#in_pl'+itemID).remove();
			}
			if($('.item_in_pl').length==0){
				$('#carre_playlist').append('<div id="text_playlist">Glisser ici les articles que vous souhaitez ajouter à la playlist</div>');
			}
		}
         }
	 });
}
function remove_from_playlist(itemID){

		add_item_to_playlist(itemID, 'drag', '', 'article_index');

}
function cutIflong(str){
	if(str.length > 35){
		str = str.substr(0, 35);
		str += " ...";
	}
	return str;
}
function toggledMenuInit(menu_id){
	id = menu_id;
	menus_count = $('.menu_toggle').length;
	if(menu_id < menus_count){
		menu_id = $('.menu_toggle')[menu_id].id;
		if(!$("#"+menu_id).hasClass('activ') && !$("#"+menu_id).hasClass('inactiv')){
			InitMenu(menu_id, id);
		}else{
			menu_id = id + 1;
			this.toggledMenuInit(menu_id);
		}
	}else{
		menus_count = $('.menu_toggle').length;
		for(i=0;i<menus_count;i++){
			menu_id = $('.menu_toggle')[i].id;
			if(!$("#"+menu_id).hasClass('activ')){
				onmouseoverInit(menu_id);
			}
		}
	}
}
function InitMenu(menu_id, id){
	$('#'+menu_id).addClass('inactiv');
	$('#'+menu_id).toggle("slide", {direction:"right"}, 100, function callback() 
		{
			onmouseoverInit(menu_id);
		});
	id = id+1;
	setTimeout("toggledMenuInit("+id+")",100);
}
function onmouseoverInit(menu_id){
	if(document.getElementById(menu_id) != null){
		document.getElementById(menu_id).onmouseover = function() {
			document.getElementById(menu_id).onmouseover = "";
			onmouseoutInit(menu_id);
			$('#'+menu_id).toggle("slide", {direction: "left"}, 100, function(){
				if($('#'+menu_id).parent().attr('id')!='menu_left3'){
						document.getElementById(menu_id).onclick = function(){sortByMedia(menu_id);};
				}
			});
		};	
	}
}
function onmouseoutInit(menu_id){
	if(document.getElementById(menu_id) != null){
		document.getElementById(menu_id).onmouseout = function(){
			document.getElementById(menu_id).onmouseout = "";
			$('#'+menu_id).toggle("slide", {direction:"right"}, 100, function callback()
			{
					onmouseoverInit(menu_id);										
			});
		};
	}
}
function sortByMedia(element_id){
	if((element_id != 'onglet_blogs') && (element_id != 'onglet_forum')){
		href = $('#'+element_id).children('a').attr('href');
		window.location.replace(href);
	}
}
function show_article_large_image(image_url, toCrop, title){
	tokens = image_url.split('-');
	gal_image_url = "";
	for(i=0;i<tokens.length-1;i++){
		gal_image_url += tokens[i]+"-";
	}
	gal_image_url += "gallery.jpg";
	if(!toCrop){
		$('#zone_player').empty().append("<a id='fancy_gal'  alt='ouvrir' title=\""+title+"\" href='"+gal_image_url+"'><img title='Cliquez pour agrandir' id='img_thumb_gal' width='408' height='300' style='display:none' src='"+image_url+"' /></a>");
	}else{
		$('#zone_player').empty().append("<a id='fancy_gal' alt='ouvrir' title=\""+title+"\" href='"+gal_image_url+"'><img title='Cliquez pour agrandir' id='img_thumb_gal' width='225' height='300' style='display:none' src='"+image_url+"' /></a>");
	}
	
	$('#img_tit_copy').text(title);
	$('#zone_player').children('a:eq(0)').children('img:eq(0)').fadeIn('slow');
		$("#fancy_gal").fancybox({
			'zoomSpeedIn':	145, 
			'zoomSpeedOut':	0,
			'overlayShow':	true
		});	
}
function load_zone_show_comments(article){
	data_string = 'article='+article;
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'load_zone_show_comments.php',
	   data: data_string,
	   success: function(msg){
	   	$("#right_global_articles_detail").children('#bloc_add_comment').remove();
	   	$("#right_global_articles_detail").children('div').hide();  
	   	$("#right_global_articles_detail").children('div').hide();  
	   	$("#right_global_articles_detail").append(msg);
	   	$("#right_global_articles_detail").children('#bloc_show_comment').fadeIn('slow');  
	   	$('#scroll_container').jScrollPane({scrollbarWidth:5, maintainPosition:true});
	   	$('#close_add_comment').click(function(){
	   		$("#right_global_articles_detail").children('#bloc_show_comment').remove();
	   		$("#right_global_articles_detail").children('div').fadeIn('slow');
	   	});
   		$('.delete_comment').click(function(){
   			$(this).parent().parent().fadeOut('fast');
   			handle_comment('delete', $(this).attr('id').split('_')[1]);
   		});
     		$('.block_comment').click(function(){
   			//$(this).parent().parent().fadeOut('fast');
   			handle_comment('block', $(this).attr('id').split('_')[1]);
   		});
     		$('.show_comment').click(function(){
   			//$(this).parent().parent().fadeOut('fast');
   			handle_comment('show', $(this).attr('id').split('_')[1]);
   		}); 
	   }
	 }); 	
}
function load_zone_add_comment(article){
	rgb = couleur = $('#lecteur_titre').css('color');
	data_string = 'article='+article+'&rgb='+rgb;
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'load_zone_add_comment.php',
	   data: data_string,
	   success: function(msg){
	   	$("#right_global_articles_detail").children('#bloc_show_comment').remove();
	   	$("#right_global_articles_detail").children('div').hide();
	   	$("#right_global_articles_detail").append(msg);
	   	if($('#captchaform').length > 0){
		   	img = document.getElementById('imgCaptcha'); 
	   		img.src = ajax_serv+'create_image.php?' + Math.random()+'&rgb='+rgb;
	   		$('#imgCaptcha').click(function(){
			   	img = document.getElementById('imgCaptcha'); 
		   		img.src = ajax_serv+'create_image.php?' + Math.random()+'&rgb='+rgb;   			
	   		});
	   	}
  		$("a#charte_anchor").fancybox({
			'zoomSpeedIn':	0, 
			'zoomSpeedOut':	0,
			'frameWidth' : 400,
			'frameHeight' : 200
		});
	   	$("#right_global_articles_detail").children('#bloc_add_comment').fadeIn('slow');  
	   	$('#close_add_comment').click(function(){
	   		$("#right_global_articles_detail").children('#bloc_add_comment').remove();
	   		$("#right_global_articles_detail").children('div').fadeIn('slow');
	   	});
		$("#new_comment_sender").change(function () {
			sender = document.getElementById('new_comment_sender').value;
			if(sender.length < 3){
				$('#new_comment_sender_error').empty();
				$('#new_comment_sender_error').text("Le nom doit être composé d'au moins 3 caractères");
				$('#new_comment_sender_error').addClass('visible');
			}else if(sender.length > 15){
				$('#new_comment_sender_error').empty();
				$('#new_comment_sender_error').text("Le nom doit être composé d'au plus 15 caractères");
				$('#new_comment_sender_error').addClass('visible');
			}else{
				$('#new_comment_sender_error').empty();
				$('#new_comment_sender_error').removeClass('visible');
			}
		}).change();
		$("#new_comment_email").change(function () {
			email = document.getElementById('new_comment_email').value;
			if(!echeck(email)){
				$('#new_comment_email_error').empty('visible');
				$('#new_comment_email_error').text("L'adresse email saisie n'est pas valide");
				$('#new_comment_email_error').addClass('visible');	
			}else{
				$('#new_comment_email_error').empty('visible');
				$('#new_comment_email_error').removeClass('visible');
			}
		}).change();
		$("#new_comment_title").change(function () {
			title = document.getElementById('new_comment_title').value;
			if(title.length < 3){
				$('#new_comment_title_error').empty('visible');
				$('#new_comment_title_error').text("Le titre doit être composé d'au moins 3 caractères");
				$('#new_comment_title_error').addClass('visible');
			}else if(title.length > 100){
				$('#new_comment_title_error').empty('visible');
				$('#new_comment_title_error').text("Le title doit être composé d'au plus 100 caractères");
				$('#new_comment_title_error').addClass('visible');
			}else{
				$('#new_comment_title_error').empty('visible');
				$('#new_comment_title_error').removeClass('visible');
			}
		}).change();
		$("#new_comment_body").change(function () {
			body = document.getElementById('new_comment_body').value;
			if(body.length < 3){
				$('#new_comment_body_error').empty();
				$('#new_comment_body_error').text("Le commentaire doit être composé d'au moins 3 caractères");
				$('#new_comment_body_error').addClass('visible');
			}else if(body.length > 500){
				$('#new_comment_body_error').empty();
				$('#new_comment_body_error').text("Le commentaire doit être composé d'au plus 500 caractères");
				$('#new_comment_body_error').addClass('visible');	
			}else{
				$('#new_comment_body_error').empty();
				$('#new_comment_body_error').removeClass('visible');
			}
		}).change();
		$("#new_comment_charte").change(function () {
			body = document.getElementById('new_comment_body').value;
			if(!$(this).attr('checked')){
				$('#new_comment_charte_error').empty();
				$('#new_comment_charte_error').text("Veuillez accepter la charte d'utilisation");
				$('#new_comment_charte_error').addClass('visible');
			}else{
				$('#new_comment_charte_error').empty();
				$('#new_comment_charte_error').removeClass('visible');
			}
		}).change();	
		$('#send_comment').bind('click', function(){
			send_comment_click(article);
		});
	    }
	 }); 	
}
function send_comment_click(article){
	errors = false;
	if($('.visible').length > 0){
		$('.visible').each(function(){
			$(this).show();
		});
		errors = true;
	}
	if(!errors){
		add_comment(article);
		$('#send_comment').unbind('click', function(){
			send_comment_click(articl);
		});
	}		
}
function add_comment(article){
	sender = document.getElementById('new_comment_sender').value;
	email = document.getElementById('new_comment_email').value;
	title = document.getElementById('new_comment_title').value;
	body = document.getElementById('new_comment_body').value;
	if($('#captchaform').length > 0){
		captcha = document.getElementById('txtCaptcha_').value;
		rgb = couleur = $('#lecteur_titre').css('color');
	}else{
		captcha = "auth_user";
	}
	count = $('#comments_count').text() *1;
	if($('.first_validation').length > 0){
		charte_validate = true;
		data_string = 'articleID='+article+'&sender='+sender+'&email='+email+'&title='+title+'&body='+body+"&captcha="+captcha+"&charte_validate="+charte_validate;
	}else{
		data_string = 'articleID='+article+'&sender='+sender+'&email='+email+'&title='+title+'&body='+body+"&captcha="+captcha;
	}
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'add_comment.php',
	   data: data_string,
	   success: function(msg){
	   	if(msg=='show'){
		   	count++;
		   	$('#comments_count').text(count);
		   	load_zone_show_comments(article);
		}else if(msg=='dont_show'){
			alert('Votre message a été envoyé avec succès [Attente de validation]');
			if(count > 0){
				load_zone_show_comments(article);
			}else{
		   		$("#right_global_articles_detail").children('#bloc_add_comment').remove();
		   		$("#right_global_articles_detail").children('div').fadeIn('slow');			
			}
		}else{
			$("#new_comment_catcha_error").show();
		   	img = document.getElementById('imgCaptcha'); 
		   	if(img != null){
	   		img.src = ajax_serv+'create_image.php?' + Math.random()+'&rgb='+rgb;  
	   		}
	   		$('#send_comment').bind('click', function(){
	   			send_comment_click(article);
	   		});
		} 	
	   }
	 });  
}
function handle_comment(action, comment_id){
	data_string = 'cid='+comment_id+"&action="+action;
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'delete_comment.php',
	   data: data_string,
	   success: function(msg){
	   	if(action=='delete'){
		   	count = $('#comments_count').text() *1;
		   	count--;
		   	$('#comments_count').text(count);
	   	}else if(action=='block'){	
	   		parent_element = $('#block_'+comment_id).parent();
	   		parent_element.append('<div id="show_'+comment_id+'" onclick="handle_comment(\'show\', \''+comment_id+'\');" class="show_comment" style="cursor: pointer;display:none">Afficher</div>');
	   		$('#block_'+comment_id).fadeOut('fast', function(){
	   			$('#show_'+comment_id).fadeIn('fast');
	   		});
	   	}else if(action=='show'){
	   		parent_element = $('#show_'+comment_id).parent();
	   		parent_element.append('<div id="block_'+comment_id+'" onclick="handle_comment(\'block\', \''+comment_id+'\');" class="block_comment" style="cursor: pointer;display:none">Bloquer</div>');
	   		$('#show_'+comment_id).fadeOut('fast', function(){
	   			$('#block_'+comment_id).fadeIn('fast');
	   		});
	   	}		
	   }
	 });	
}
function set_gal_scrollable(){
	$('.nextselection').show(); 	
	$("#rang_top_gallery").scrollable({size:4,prev:'.prev_p', next:'.next_n', clickable: false});
	$("#rang_top").show();
	$("#rang_down").show();
	$("#rang_top_gallery").pngFix(); 
	$('.next_n').click(function(){
		$('.previewselection').show();	
		$("#rang_top_gallery").scrollable().next();
		if(($("#rang_top_gallery").scrollable().getStatus().size+$("#rang_top_gallery").scrollable().getStatus().index)==$("#rang_top_gallery").scrollable().getStatus().total){
			$('.nextselection').hide();
		}
	});
	$('#fleche_p').click(function(){
		$('.nextselection').show();
		$("#rang_top_gallery").scrollable().prev();
		if($("#rang_top_gallery").scrollable().getStatus().index==0){
			$('.previewselection').hide();
		}
	});
}
function load_search_zone(){
	$("#search").unbind("click", load_search_zone);
	thema_id = $('#current_thema_id').text();
	topic_id = $('#current_topic_id').text();
	data_string = 'thema_id='+thema_id+"&topic_id="+topic_id;
	$.ajax({
	   type: 'POST',
	   url: ajax_serv+'load_search_zone.php',
	   data: data_string,
	   success: function(msg){
	   	$('#searching_forms').children('form').remove();
	   	//$('#searching_forms').css('z-index', 100);
	  	$('#searching_forms').prepend(msg);
	  	show_search_zone();
	   }
	 });
}
function show_search_zone(){
	$('#search_form_container').height(0);
	$('#super_admin_zone_anchor').fadeOut('fast');
	$('#onglet_mode_emplois').fadeOut('fast');
	$('#accueil_zone_anchor').fadeOut('fast');
	$('#banner_rsr_button').fadeOut('fast');
   	$('#search_form_container').animate({"height": "+=130px"}, 'fast', function(){
   		$('#search_form').fadeIn('medium');
		$("#search").bind("click", hide_search_zone);
   	}); 	
}
function hide_search_zone(){
	$("#search").unbind("click", hide_search_zone);
	$('#search_form').fadeOut('medium', function(){
   		$('#search_form_container').animate({"height": "-=130px"}, 'fast', function(){
   			//$('#searching_forms').css('z-index', 89);
   			$('#super_admin_zone_anchor').fadeIn('fast');
   			$('#onglet_mode_emplois').fadeIn('fast');
   			$('#accueil_zone_anchor').fadeIn('fast');
   			$('#banner_rsr_button').fadeIn('fast');
   		});
		$("#search").bind("click", load_search_zone);
   	}); 	
}
function check_radio_list(radio){
	if(radio == 'thema'){
		if($('#topics_to_search_in').css('display')=='none'){
			$('#topics_to_search_in').fadeIn('fast');
		}
	}else{
		if($('#topics_to_search_in').css('display')=='block'){
			$('#topics_to_search_in').fadeOut('fast');
		}
	}
}
function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if (str.indexOf(" ")!=-1){
		return false;
	}
	return true;					
}
function show_rsr_banner(){
		$('#super_admin_zone_anchor').fadeOut('fast');
		$('#onglet_mode_emplois').fadeOut('fast');
		$('#accueil_zone_anchor').fadeOut('fast');
		$('#search').fadeOut('fast');	
	$('#iframed_banner').slideDown('slow', function(){
		$('#iframed_banner').removeClass('closed');
		button_src = $('#banner_rsr_button').children('img').attr('src');
		new_button_src = button_src.replace("close", "open");
		$('#banner_rsr_button').children('img').attr('src', new_button_src);
	});
}
function hide_rsr_banner(){
	$('#iframed_banner').slideUp('slow', function(){
		$('#iframed_banner').addClass('closed');
		button_src = $('#banner_rsr_button').children('img').attr('src');
		new_button_src = button_src.replace("open", "close");
		$('#banner_rsr_button').children('img').attr('src', new_button_src);
		$('#super_admin_zone_anchor').fadeIn('fast');
		$('#onglet_mode_emplois').fadeIn('fast');
		$('#accueil_zone_anchor').fadeIn('fast');
		$('#search').fadeIn('fast');			
	});
}
function getCookie(nom) {
	deb = document.cookie.indexOf(nom + "=");
	if (deb >= 0) {
		deb += nom.length + 1;
		fin = document.cookie.indexOf(";",deb);
		if (fin < 0) fin = document.cookie.length;
		return unescape(document.cookie.substring(deb,fin));
	}
	return "";
}
function FixCookie(nom,valeur,expire,path,domaine,securise) {
      document.cookie = nom + "=" + escape (valeur) + ((expire) ? "; expires=" + expire.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domaine) ? "; domain=" + domaine : "") + ((securise) ? "; secure" : "");
}
function DateExpiration (DateExp) {

      var aujourdhui = new Date(0);
      var aujourdhuidate = aujourdhui.getTime();
      if (aujourdhuidate > 0)
            DateExp.setTime (DateExp.getTime() - aujourdhuidate);

}
