$(function(){

	var id_article = "";
	
	if(document.location.toString().indexOf("#") != -1)
	{
		id_article = document.location.toString().substr(document.location.toString().indexOf("#")+5,10);
		var id_to_open ="";
	}
	
	if(id_article == "")
	{
		$("#accordion_article").accordion({ header: "h3",clearStyle: true,collapsible: true,active: true }).bind("accordionchange", function(event, ui) { 
	
			if(ui.newHeader.next().html()=="")
			{
				ui.newHeader.next().html(loading_html);
	
				ui.newHeader.next().load($('#'+ui.newHeader.attr("id") +' > a').attr("href"),
					{limit: 25},
					function (responseText, textStatus, req) {
						if( textStatus=="success")
							ui.newHeader.next().html(responseText);
					}
				);
			}
		});
	}
	else
	{		
		//looking for the item to open
		var i = 0;
		var trouve = false;
		
		 $("h3 a").each(function(){
		 	
			var id_article_temp = $(this).attr('href').substr($(this).attr('href').indexOf("id_article=")+11,10);

		 	if (id_article_temp == id_article) //it is the good one
		 	{		 				 		
		 		trouve = true;
		 		$(this).parent().next("div").load($(this).attr('href'),
					{limit: 25},
					function (responseText, textStatus, req) {
						if( textStatus=="success")
						{
							$("#accordion_article").accordion({ header: "h3",clearStyle: true,collapsible: true,active: i }).bind("accordionchange", function(event, ui) { 
						
								if(ui.newHeader.next().html()=="")
								{
									ui.newHeader.next().html(loading_html);
						
									ui.newHeader.next().load($('#'+ui.newHeader.attr("id") +' > a').attr("href"),
										{limit: 25},
										function (responseText, textStatus, req) {
											if( textStatus=="success")
												ui.newHeader.next().html(responseText);
										}
									);
								}
							});
						}
					});
		 	}
		 	if(trouve == false)
		 	i++;
		 });
	}
});