// JavaScript Document
var current_lg;
var rpc_url;
var offset = 0;

function get_actus_with_filters(){
	var f1 = document.getElementById('date_select').options[document.getElementById('date_select').selectedIndex].value;
	
	var datas = 'action=get_actus'
	+ '&lg='+current_lg;
	
	if(f1 != 0){
		datas += '&y='+encodeURIComponent(f1);
	}
	
	//JQUERY AJAX
	$.ajaxSetup ({  
		cache: false  
	 });

	var response = $.ajax({
	   async: false,
	   url: rpc_url,
	   data: datas,
	   error: function(msg){
			
			alert('error');
			
	   }
	}).responseText;
	
	var json = eval('(' + response + ')');
	
	if (json.response == 'ok'){
		
		//Success !
		$('.page_actus_list').html(json.html);
		
		$(".level").hover(function() {
			  $(this).removeClass("off").addClass("on");
			  var width_elt = $(this).children(".sb_content").width()+25;
			  $(this).stop(true,true).animate({width:width_elt},500,function() {
				 $(this).children(".sb_content").fadeIn("fast");
				 $(this).children(".addthis_toolbox").fadeIn("fast");
			  });
		   },
		   function() {
			  $(this).removeClass("on").addClass("off");
			  $(this).stop(true,true).animate({width:0},1500);
			  $(this).children(".sb_content").stop(true,true).fadeOut("fast");
			  $(this).children(".addthis_toolbox").stop(true,true).fadeOut("fast");
		   }
	   );
	   var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		if (window.addthis){
		   window.addthis = null;
		}
		$.getScript( script );	 
		
	}else{
		
		//Error
		
	}
	
}

function get_editions_with_filters(){
	var f1 = document.getElementById('date_select').options[document.getElementById('date_select').selectedIndex].value;
	
	var datas = 'action=get_editions'
	+ '&lg='+current_lg;
	
	if(f1 != 0){
		datas += '&y='+encodeURIComponent(f1);
	}
	
	//JQUERY AJAX
	$.ajaxSetup ({  
		cache: false  
	 });

	var response = $.ajax({
	   async: false,
	   url: rpc_url,
	   data: datas,
	   error: function(msg){
			
			alert('error');
			
	   }
	}).responseText;
	
	var json = eval('(' + response + ')');
	
	if (json.response == 'ok'){
		
		//Success !
		$('.page_actus_list').html(json.html);
		$(".level").hover(function() {
			  $(this).removeClass("off").addClass("on");
			  var width_elt = $(this).children(".sb_content").width()+25;
			  $(this).stop(true,true).animate({width:width_elt},500,function() {
				 $(this).children(".sb_content").fadeIn("fast");
				 $(this).children(".addthis_toolbox").fadeIn("fast");
			  });
		   },
		   function() {
			  $(this).removeClass("on").addClass("off");
			  $(this).stop(true,true).animate({width:0},1500);
			  $(this).children(".sb_content").stop(true,true).fadeOut("fast");
			  $(this).children(".addthis_toolbox").stop(true,true).fadeOut("fast");
		   }
	   );
	   var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		if (window.addthis){
		   window.addthis = null;
		}
		$.getScript( script );	 
		
	}else{
		
		//Error
		
	}
	
}

function get_images_with_filters(){
	var f1 = document.getElementById('date_select').options[document.getElementById('date_select').selectedIndex].value;
	var f2 = document.getElementById('activite_select').options[document.getElementById('activite_select').selectedIndex].value;
	var f3 = document.getElementById('pays_select').options[document.getElementById('pays_select').selectedIndex].value;
	var f4 = document.getElementById('type_select').options[document.getElementById('type_select').selectedIndex].value;
	
	var datas = 'action=get_images'
	+ '&lg='+current_lg;
	
	if(f1 != 0){
		datas += '&y='+encodeURIComponent(f1);
	}
	
	var cat = "";
	
	if(f2 != 0){
		if(cat != ''){
			cat += "_"
		}
		cat += encodeURIComponent(f2);
	}
	if(f3 != 0){
		if(cat != ''){
			cat += "_"
		}
		cat += encodeURIComponent(f3);
		
	}
	if(f4 != 0){
		if(cat != ''){
			cat += "_"
		}
		cat += encodeURIComponent(f4);
	}
	
	if(cat != ''){
		datas += '&cat='+encodeURIComponent(cat);
	}
	
	//JQUERY AJAX
	$.ajaxSetup ({  
		cache: false  
	 });

	var response = $.ajax({
	   async: false,
	   url: rpc_url,
	   data: datas,
	   error: function(msg){
			
			alert('error');
			
	   }
	}).responseText;
	
	var json = eval('(' + response + ')');
	
	if (json.response == 'ok'){
		
		//Success !
		$('.page_content').html(json.html); 
		
	}else{
		
		//Error
		
	}
}

function get_image_page(offset_page){
	offset = offset_page;
	var f1 = document.getElementById('date_select').options[document.getElementById('date_select').selectedIndex].value;
	var f2 = document.getElementById('activite_select').options[document.getElementById('activite_select').selectedIndex].value;
	var f3 = document.getElementById('pays_select').options[document.getElementById('pays_select').selectedIndex].value;
	var f4 = document.getElementById('type_select').options[document.getElementById('type_select').selectedIndex].value;
	
	var datas = 'action=get_images'
	+ '&lg='+current_lg;
	
	if(f1 != 0){
		datas += '&y='+encodeURIComponent(f1);
	}
	
	var cat = "";
	
	if(f2 != 0){
		if(cat != ''){
			cat += "_"
		}
		cat += encodeURIComponent(f2);
	}
	if(f3 != 0){
		if(cat != ''){
			cat += "_"
		}
		cat += encodeURIComponent(f3);
		
	}
	if(f4 != 0){
		if(cat != ''){
			cat += "_"
		}
		cat += encodeURIComponent(f4);
	}
	
	if(cat != ''){
		datas += '&cat='+encodeURIComponent(cat);
	}
	
	if(offset != 0){
		datas += '&offset='+encodeURIComponent(offset);
	}
	
	//JQUERY AJAX
	$.ajaxSetup ({  
		cache: false  
	 });

	var response = $.ajax({
	   async: false,
	   url: rpc_url,
	   data: datas,
	   error: function(msg){
			
			alert('error');
			
	   }
	}).responseText;
	
	var json = eval('(' + response + ')');
	
	if (json.response == 'ok'){
		
		//Success !
		$('.page_content').html(json.html); 
		
		$.scrollTo('#header', 300);
		
	}else{
		
		//Error
		
	}
}

function get_actu_page(offset){
	var f1 = document.getElementById('date_select').options[document.getElementById('date_select').selectedIndex].value;
	
	var datas = 'action=get_actus'
	+ '&lg='+current_lg;
	
	if(f1 != 0){
		datas += '&y='+encodeURIComponent(f1);
	}
	
	if(offset != 0){
		datas += '&offset='+encodeURIComponent(offset);
	}
	
	//JQUERY AJAX
	$.ajaxSetup ({  
		cache: false  
	 });

	var response = $.ajax({
	   async: false,
	   url: rpc_url,
	   data: datas,
	   error: function(msg){
			
			alert('error');
			
	   }
	}).responseText;
	
	var json = eval('(' + response + ')');
	
	if (json.response == 'ok'){
		
		//Success !
		$('.page_actus_list').html(json.html);
		
		$.scrollTo('#header', 300);
		
		$(".level").hover(function() {
			  $(this).removeClass("off").addClass("on");
			  var width_elt = $(this).children(".sb_content").width()+25;
			  $(this).stop(true,true).animate({width:width_elt},500,function() {
				 $(this).children(".sb_content").fadeIn("fast");
				 $(this).children(".addthis_toolbox").fadeIn("fast");
			  });
		   },
		   function() {
			  $(this).removeClass("on").addClass("off");
			  $(this).stop(true,true).animate({width:0},1500);
			  $(this).children(".sb_content").stop(true,true).fadeOut("fast");
			  $(this).children(".addthis_toolbox").stop(true,true).fadeOut("fast");
		   }
	   );
	   var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		if (window.addthis){
		   window.addthis = null;
		}
		$.getScript( script );	 
		
	}else{
		
		//Error
		
	}
	
}

function get_edition_page(offset){
	var f1 = document.getElementById('date_select').options[document.getElementById('date_select').selectedIndex].value;
	
	var datas = 'action=get_editions'
	+ '&lg='+current_lg;
	
	if(f1 != 0){
		datas += '&y='+encodeURIComponent(f1);
	}
	
	if(offset != 0){
		datas += '&offset='+encodeURIComponent(offset);
	}
	
	//JQUERY AJAX
	$.ajaxSetup ({  
		cache: false  
	 });

	var response = $.ajax({
	   async: false,
	   url: rpc_url,
	   data: datas,
	   error: function(msg){
			
			alert('error');
			
	   }
	}).responseText;
	
	var json = eval('(' + response + ')');
	
	if (json.response == 'ok'){
		
		//Success !
		$('.page_actus_list').html(json.html);
		
		$.scrollTo('#header', 300);
		
		$(".level").hover(function() {
			  $(this).removeClass("off").addClass("on");
			  var width_elt = $(this).children(".sb_content").width()+25;
			  $(this).stop(true,true).animate({width:width_elt},500,function() {
				 $(this).children(".sb_content").fadeIn("fast");
				 $(this).children(".addthis_toolbox").fadeIn("fast");
			  });
		   },
		   function() {
			  $(this).removeClass("on").addClass("off");
			  $(this).stop(true,true).animate({width:0},1500);
			  $(this).children(".sb_content").stop(true,true).fadeOut("fast");
			  $(this).children(".addthis_toolbox").stop(true,true).fadeOut("fast");
		   }
	   );
	   var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
		if (window.addthis){
		   window.addthis = null;
		}
		$.getScript( script );	 
		
	}else{
		
		//Error
		
	}
	
}
