var curentjson = "";
		var typeTri = "treemap";
		var currentfromdate = "07/01/2007";
		var currenttodate = "12/01/2012";			
		var currentcategories = [];		


	function launchpage(json)
	{
		curentjson = json;
		if (typeTri == "treemap")
		{
			var k =1;
			content = "<div class=\"actus\">";
			for (i = 0; i < json.clusters.length && i<4; i++)
			{
				content += "<a id=\""+json.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster/"+json.query.query_id+"/"+json.clusters[i].id+"/0/10\"><div  class=\"actu\"><img src=\"/static/img/home-visuel-"+k+".jpg\" alt=\"\" /><div class=\"inner-actu\">";
				content += "<h2> ";
				content += json.clusters[i].title;
				content += "</h2></div></div></a>";
				k++;
			}
			content +="</div>";
		}
		else
		{
			content = "<div class=\"articles\">";
			for (i = 0; i < json.clusters.length && i<4; i++)
			{
				content += "<div name=\"cluster_id\" class=\"article\" id=\""+json.clusters[i].id+"\"><div class=\"inner-article clearfix\"><h2><a title=\"Lire l\'article\" id=\""+json.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster/"+json.query.query_id+"/"+json.clusters[i].id+"/0/10\">";
				content += json.clusters[i].title;
				content += "</a></h2><p class=\"number-article\"><a href=\"#\">";
				content += json.clusters[i].documents_number;
				content +=" articles | ";
				content += json.clusters[i].annotations.length;
				content += " annotations </a><a title=\"ajouter une annotation\" class=\"add-annotation\" href=\"#\"></a></p> <div class=\"article-annotations\"><a title=\"title\" class=\"blue\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"green\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"red\" href=\"#\" style=\"width:40%;\"></a><a title=\"title\" class=\"empty\" href=\"#\" style=\"width:20%;\"></a></div><div class=\"article-content\">";
				content +="<div class=\"article-visuel-wrap\"><img class=\"article-visuel\" src=\"/static/img/visuel-article.jpg\" alt=\"\" /></div>";	 
				content +="<p class=\"resume\">";
				content += json.clusters[i].abstract;
				content += "</p><ul class=\"articlelinks\"><ul>";
				
				for (j = 0; j < json.clusters[i].documents.length; j++)
				{
					content += "<li><a href=\"\" id=\""+json.clusters[i].documents[j].id+"\">";
					content += json.clusters[i].documents[j].title;
					content += "</a></li>";
				}
				content +="</ul></ul>";
				content +="</div></div></div>";
			}
			content +="</div>";
		}
		$("#right").empty();
		$(content).appendTo("#right");		
	}

	
	function refreshview(type)
	{
		typeTri = type; 
		if(type == 'treemap')
		{
			typeTri = "treemap";
			var k =1;
		content = "<div class=\"actus\">";
		for (i = 0; i < curentjson.clusters.length && i<4; i++)
		{
			content += "<a id=\""+curentjson.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster/"+curentjson.query.query_id+"/"+curentjson.clusters[i].id+"/0/10\"><div  class=\"actu\"><img src=\"/static/img/home-visuel-"+k+".jpg\" alt=\"\" /><div class=\"inner-actu\">";
			content += "<h2> ";
			content += curentjson.clusters[i].title;
			content += "</h2></div></div></a>";
			k++;
		}
		content +="</div>";
		$("#right").empty();
		$(content).appendTo("#right");		
		}
		else
		{
			typeTri = "liste";
			content = "<div class=\"articles\">";
		for (i = 0; i < curentjson.clusters.length && i<4; i++)
		{
			content += "<div name=\"cluster_id\" class=\"article\" id=\""+curentjson.clusters[i].id+"\"><div class=\"inner-article clearfix\"><h2><a title=\"Lire l\'article\" id=\""+curentjson.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster?query_id="+curentjson.query.query_id+"&cluster_id="+curentjson.clusters[i].id+"&offset=0&count=10\">";
			content += curentjson.clusters[i].title;
			content += "</a></h2><p class=\"number-article\"><a href=\"#\">";
			content += curentjson.clusters[i].documents_number;
			content +=" articles | ";
			content += curentjson.clusters[i].annotations.length;
			content += " annotations </a><a title=\"ajouter une annotation\" class=\"add-annotation\" href=\"#\"></a></p> <div class=\"article-annotations\"><a title=\"title\" class=\"blue\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"green\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"red\" href=\"#\" style=\"width:40%;\"></a><a title=\"title\" class=\"empty\" href=\"#\" style=\"width:20%;\"></a></div><div class=\"article-content\">";
			content +="<div class=\"article-visuel-wrap\"><img class=\"article-visuel\" src=\"/static/img/visuel-article.jpg\" alt=\"\" /></div>";	 
			content +="<p class=\"resume\">";
			content += curentjson.clusters[i].abstract;
			content += "</p><ul class=\"articlelinks\"><ul>";
			
			for (j = 0; j < curentjson.clusters[i].documents.length; j++)
			{
				content += "<li><a href=\"\" id=\""+curentjson.clusters[i].documents[j].id+"\">";
				content += curentjson.clusters[i].documents[j].title;
				content += "</a></li>";
			}
			content +="</ul></ul>";
			content +="</div></div></div>";
		}
		content +="</div>";
		$("#right").empty();
		$(content).appendTo("#right");
		}
	}
	
	$(function(){
		

		$('#recherche_button').click(function() {

		$('#from_date').val(currentfromdate);
		$('#to_date').val(currenttodate);
		
		//$['categories'] = array('inter', 'france', 'eco');
		

		$.each(currentcategories, function() {
			if(this != undefined)
			{
				$('<input />').attr('type', 'hidden')
				.attr('name', 'categories')
				.attr('value', this)
				.appendTo('#ajax1');
			}
				
		 });
		/*var i=0;
		$("input[name='categories']").each( function() {
			if(currentcategories[i] != undefined)
			{
				alert(currentcategories[i]);
				
				$(this).attr('value', currentcategories[i]);
			}
			/*else
			{
				return false;
			}*/
			/*i++;
			
	});
*/

		$('#ajax1').submit();
	});
			
		// Formulaire POST AJAX
		$("#ajax1").submit( function() 
		{
			var urlSubmit = $(this).attr('action');
			
			/*var params = [
               {
                 name: "adress",
                 value: window.location.pathname
               },
               {
                  name: "time",
                  value: new Date().getTime()
               }
             ];
			 
			$.each(currentcategories, function(i,param)
			{
				
				
				$('<input />').attr('type', 'hidden')
					.attr('name', param.name)
					.attr('value', param.value)
					.appendTo('#ajax1');
			});*/
			
			
			$.ajax(
			{  
				type: "POST",
				url: urlSubmit,
				data      : $(this).serializeArray(),
				success: function(data) {
					var json = jQuery.parseJSON(data);
					var k =1;
					alert(currentfromdate);
					if (typeTri == "treemap")
					{
						content = "<div class=\"actus\">";
						for (i = 0; i < json.clusters.length & i<4; i++)
						{
							content += "<a id=\""+json.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster/"+json.query.query_id+"/"+json.clusters[i].id+"/0/10\"><div  class=\"actu\"><img src=\"/static/img/home-visuel-"+k+".jpg\" alt=\"\" /><div class=\"inner-actu\">";
							content += "<h2> ";
							content += json.clusters[i].title;
							content += "</h2></div></div></a>";
							k++;
						}
						content +="</div>";
					}
					else
					{
						content = "<div class=\"articles\">";
						for (i = 0; i < json.clusters.length && i<4; i++)
						{
							content += "<div name=\"cluster_id\" class=\"article\" id=\""+json.clusters[i].id+"\"><div class=\"inner-article clearfix\"><h2><a title=\"Lire l\'article\" id=\""+json.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster/"+json.query.query_id+"/"+json.clusters[i].id+"/0/10\">";
							content += json.clusters[i].title;
							content += "</a></h2><p class=\"number-article\"><a href=\"#\">";
							content += json.clusters[i].documents_number;
							content +=" articles | ";
							content += json.clusters[i].annotations.length;
							content += " annotations </a><a title=\"ajouter une annotation\" class=\"add-annotation\" href=\"#\"></a></p> <div class=\"article-annotations\"><a title=\"title\" class=\"blue\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"green\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"red\" href=\"#\" style=\"width:40%;\"></a><a title=\"title\" class=\"empty\" href=\"#\" style=\"width:20%;\"></a></div><div class=\"article-content\">";
							content +="<div class=\"article-visuel-wrap\"><img class=\"article-visuel\" src=\"/static/img/visuel-article.jpg\" alt=\"\" /></div>";	 
							content +="<p class=\"resume\">";
							content += json.clusters[i].abstract;
							content += "</p><ul class=\"articlelinks\"><ul>";
							
							for (j = 0; j < json.clusters[i].documents.length; j++)
							{
								content += "<li><a href=\"\" id=\""+json.clusters[i].documents[j].id+"\">";
								content += json.clusters[i].documents[j].title;
								content += "</a></li>";
							}
							content +="</ul></ul>";
							content +="</div></div></div>";
						}
						content +="</div>";
					}
					$("#right").empty();
					$(content).appendTo("#right");		
					curentjson = json;
				}
			});
			return false;
		});
		
		// Formulaire POST AJAX
		$("#ajax2").submit( function() 
		{
			alert('ajax2');
			var urlSubmit = $(this).attr('action');
			currentcategories = [];
			/*var data = { 'categories' : []};*/
			$("input:checked").each(function() {
					/*data['categories'].push($(this).val());*/
					currentcategories.push($(this).val());
			});
			currentfromdate = $("#pickeddatebegin").val();
			currenttodate = $("#pickeddateend").val();
						
			$.ajax(
			{  
				type: "POST",
				url: urlSubmit,
				data      : $(this).serializeArray(),
				success: function(data) {
					var json = jQuery.parseJSON(data);
					var k =1;
					if (typeTri == "treemap")
					{
						content = "<div class=\"actus\">";
						for (i = 0; i < json.clusters.length & i<4; i++)
						{
							content += "<a id=\""+json.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster/"+json.query.query_id+"/"+json.clusters[i].id+"/0/10\"><div  class=\"actu\"><img src=\"/static/img/home-visuel-"+k+".jpg\" alt=\"\" /><div class=\"inner-actu\">";
							content += "<h2> ";
							content += json.clusters[i].title;
							content += "</h2></div></div></a>";
							k++;
						}
						content +="</div>";
					}
					else
					{
						content = "<div class=\"articles\">";
						for (i = 0; i < json.clusters.length && i<4; i++)
						{
							content += "<div name=\"cluster_id\" class=\"article\" id=\""+json.clusters[i].id+"\"><div class=\"inner-article clearfix\"><h2><a title=\"Lire l\'article\" id=\""+json.clusters[i].id+"\" href=\"http://localhost:8000/documents_cluster/"+json.query.query_id+"/"+json.clusters[i].id+"/0/10\">";
							content += json.clusters[i].title;
							content += "</a></h2><p class=\"number-article\"><a href=\"#\">";
							content += json.clusters[i].documents_number;
							content +=" articles | ";
							content += json.clusters[i].annotations.length;
							content += " annotations </a><a title=\"ajouter une annotation\" class=\"add-annotation\" href=\"#\"></a></p> <div class=\"article-annotations\"><a title=\"title\" class=\"blue\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"green\" href=\"#\" style=\"width:20%;\"></a><a title=\"title\" class=\"red\" href=\"#\" style=\"width:40%;\"></a><a title=\"title\" class=\"empty\" href=\"#\" style=\"width:20%;\"></a></div><div class=\"article-content\">";
							content +="<div class=\"article-visuel-wrap\"><img class=\"article-visuel\" src=\"/static/img/visuel-article.jpg\" alt=\"\" /></div>";	 
							content +="<p class=\"resume\">";
							content += json.clusters[i].abstract;
							content += "</p><ul class=\"articlelinks\"><ul>";
							
							for (j = 0; j < json.clusters[i].documents.length; j++)
							{
								content += "<li><a href=\"\" id=\""+json.clusters[i].documents[j].id+"\">";
								content += json.clusters[i].documents[j].title;
								content += "</a></li>";
							}
							content +="</ul></ul>";
							content +="</div></div></div>";
						}
						content +="</div>";
					}
					$("#right").empty();
					$(content).appendTo("#right");		
					curentjson = json;
				}
			});
			return false;
		});
		
		 $('.checkbox_category').click(function(){
			  /*var theValue = $(this).val();*/
			 $('#ajax2').submit();
  		});
	
});//jQuery